Skip to content

Commit

Permalink
patchpkg: fix system CUDA lib search
Browse files Browse the repository at this point in the history
As part of the auto-patching for CUDA, devbox searches for the system's
libcuda (installed by the driver) and adds it to the Nix store. This
fixes a couple of bugs with that search process:

- When creating the soname links, the base name of the path to libcuda
  wasn't being used. This would lead to creating symlinks like
  "lib/libcuda.so.1", which would fail because a lib subdirectory didn't
  exist.
- Ensure the `src` attribute is set in the patch flake so that devbox
  knows the path the flake source (which contains the copied libcuda) at
  build time.
  • Loading branch information
gcurtis committed Feb 7, 2025
1 parent 55fd9a1 commit aab66e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
10 changes: 0 additions & 10 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions internal/patchpkg/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,15 @@ func (d *DerivationBuilder) findCUDA(ctx context.Context, out *packageFS) error
return fmt.Errorf("patch flake didn't set $src to the path to its source tree")
}

glob, err := fs.Glob(d.src, "lib/libcuda.so*")
pattern := "lib/libcuda.so*"
slog.DebugContext(ctx, "looking for system CUDA libraries in flake", "glob", filepath.Join(d.src.storePath, "lib/libcuda.so*"))
glob, err := fs.Glob(d.src, pattern)
if err != nil {
return fmt.Errorf("glob system libraries: %v", err)
}
if len(glob) != 0 {
if len(glob) == 0 {
slog.DebugContext(ctx, "no system CUDA libraries found in flake")
} else {
err := d.copyDir(out, "lib")
if err != nil {
return fmt.Errorf("copy system library: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions internal/patchpkg/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ func (lib SharedLibrary) CopyAndLink(dir string) error {
return err
}

sonameLink := filepath.Join(dir, lib.Soname)
sonameLink := filepath.Join(dir, filepath.Base(lib.Soname))
var sonameErr error
if lib.Soname != "" {
// Symlink must be relative.
sonameErr = os.Symlink(filepath.Base(lib.RealName), sonameLink)
}

linkerNameLink := filepath.Join(dir, lib.LinkerName)
linkerNameLink := filepath.Join(dir, filepath.Base(lib.LinkerName))
var linkerNameErr error
if lib.LinkerName != "" {
// Symlink must be relative.
Expand All @@ -209,9 +209,9 @@ func (lib SharedLibrary) CopyAndLink(dir string) error {

func (lib SharedLibrary) LogValue() slog.Value {
return slog.GroupValue(
slog.String("lib.path", lib.Name()),
slog.String("lib.linkername", lib.LinkerName),
slog.String("lib.soname", lib.Soname),
slog.String("lib.realname", lib.RealName),
slog.String("path", lib.Name()),
slog.String("linkername", lib.LinkerName),
slog.String("soname", lib.Soname),
slog.String("realname", lib.RealName),
)
}
2 changes: 1 addition & 1 deletion internal/shellgen/tmpl/glibc-patch.nix.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
gcc = if isLinux then nixpkgs-glibc.legacyPackages."${system}".stdenv.cc.cc.lib else null;

DEVBOX_DEBUG = 1;

src = self;
builder = "${devbox.packages.${system}.default}/bin/devbox";
args = [ "patch" "--restore-refs" ] ++
(if glibc != null then [ "--glibc" "${glibc}" ] else [ ]) ++
Expand Down

0 comments on commit aab66e6

Please sign in to comment.