-
Notifications
You must be signed in to change notification settings - Fork 26
Update libkrun build to use nerdbox variant #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,39 +73,76 @@ func (*vmManager) NewInstance(ctx context.Context, state string) (vm.Instance, e | |
| p2 = []string{"/usr/local/lib", "/usr/local/lib64", "/usr/lib", "/lib"} | ||
| } | ||
| arch := kernelArch() | ||
| sharedNames := []string{fmt.Sprintf("libkrun-%s.so", arch), "libkrun.so"} | ||
|
|
||
| // variants lists distinct library families in priority order. Each family | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code path has been a pain point up the stack historically. I wonder if it'd make sense to write a small lookup plugin that we can easily swap out. WDYT?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to think a bit more about how we would want to do that. We could certainly put the resolution logic in a library, I'm not sure how it would be pluggable though. Since this is specific to the libkrun plugin itself, its reasonable that other backends may have slightly different resolution logic or not have a "nerdbox" specific build at all. |
||
| // represents a different patchset / ABI, so we exhaust all search paths | ||
| // for one variant before falling back to the next. Within a variant, the | ||
| // arch-tagged name is preferred over the generic name. | ||
| // | ||
| // Priority: libkrun-nerdbox (custom patches) > libkrun (stock upstream) | ||
| variants := [][]string{ | ||
| {fmt.Sprintf("libkrun-nerdbox-%s.so", arch), "libkrun-nerdbox.so"}, | ||
| {fmt.Sprintf("libkrun-%s.so", arch), "libkrun.so"}, | ||
| } | ||
| switch runtime.GOOS { | ||
| case "darwin": | ||
| sharedNames = []string{fmt.Sprintf("libkrun-%s.dylib", arch), "libkrun.dylib", fmt.Sprintf("libkrun-efi-%s.dylib", arch), "libkrun-efi.dylib"} | ||
| variants = [][]string{ | ||
| {fmt.Sprintf("libkrun-nerdbox-%s.dylib", arch), "libkrun-nerdbox.dylib"}, | ||
| {fmt.Sprintf("libkrun-%s.dylib", arch), "libkrun.dylib"}, | ||
| {fmt.Sprintf("libkrun-efi-%s.dylib", arch), "libkrun-efi.dylib"}, | ||
| } | ||
| p2 = append(p2, "/opt/homebrew/lib") | ||
| case "windows": | ||
| sharedNames = []string{"krun.dll"} | ||
| variants = [][]string{{"krun.dll"}} | ||
| } | ||
|
|
||
| for _, dir := range append(p1, p2...) { | ||
| if dir == "" { | ||
| // Unix shell semantics: path element "" means "." | ||
| dir = "." | ||
| dirs := append(p1, p2...) | ||
|
|
||
| // Search: variant → name → directory. All paths are checked for a given | ||
| // name before moving to the next name, and all names in a variant are | ||
| // exhausted before trying the next variant. | ||
| var sharedNames []string // flattened, for use in the error message | ||
| for _, variant := range variants { | ||
| sharedNames = append(sharedNames, variant...) | ||
| } | ||
| for _, variant := range variants { | ||
| if krunPath != "" { | ||
| break | ||
| } | ||
| var path string | ||
| if krunPath == "" { | ||
| for _, sharedName := range sharedNames { | ||
| path = filepath.Join(dir, sharedName) | ||
| for _, name := range variant { | ||
| if krunPath != "" { | ||
| break | ||
| } | ||
| for _, dir := range dirs { | ||
| if dir == "" { | ||
| // Unix shell semantics: path element "" means "." | ||
| dir = "." | ||
| } | ||
| path := filepath.Join(dir, name) | ||
| if _, err := os.Stat(path); err == nil { | ||
| krunPath = path | ||
| break | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Kernel and initrd use a single name variant each; still search all dirs. | ||
| kernelName := fmt.Sprintf("nerdbox-kernel-%s", arch) | ||
| initrdNames := []string{fmt.Sprintf("nerdbox-initrd-%s", arch), "nerdbox-initrd"} | ||
| for _, dir := range dirs { | ||
| if dir == "" { | ||
| dir = "." | ||
| } | ||
| if kernelPath == "" { | ||
| path = filepath.Join(dir, fmt.Sprintf("nerdbox-kernel-%s", kernelArch())) | ||
| path := filepath.Join(dir, kernelName) | ||
| if _, err := os.Stat(path); err == nil { | ||
| kernelPath = path | ||
| } | ||
| } | ||
| if initrdPath == "" { | ||
| for _, name := range []string{fmt.Sprintf("nerdbox-initrd-%s", arch), "nerdbox-initrd"} { | ||
| path = filepath.Join(dir, name) | ||
| for _, name := range initrdNames { | ||
| path := filepath.Join(dir, name) | ||
| if _, err := os.Stat(path); err == nil { | ||
| initrdPath = path | ||
| break | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.