Skip to content

Commit 0e154db

Browse files
authored
patchpkg: fix system CUDA lib search (#2507)
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.
1 parent 55fd9a1 commit 0e154db

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

go.sum

-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/patchpkg/builder.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,15 @@ func (d *DerivationBuilder) findCUDA(ctx context.Context, out *packageFS) error
327327
return fmt.Errorf("patch flake didn't set $src to the path to its source tree")
328328
}
329329

330-
glob, err := fs.Glob(d.src, "lib/libcuda.so*")
330+
pattern := "lib/libcuda.so*"
331+
slog.DebugContext(ctx, "looking for system CUDA libraries in flake", "glob", filepath.Join(d.src.storePath, "lib/libcuda.so*"))
332+
glob, err := fs.Glob(d.src, pattern)
331333
if err != nil {
332334
return fmt.Errorf("glob system libraries: %v", err)
333335
}
334-
if len(glob) != 0 {
336+
if len(glob) == 0 {
337+
slog.DebugContext(ctx, "no system CUDA libraries found in flake")
338+
} else {
335339
err := d.copyDir(out, "lib")
336340
if err != nil {
337341
return fmt.Errorf("copy system library: %v", err)

internal/patchpkg/elf.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ func (lib SharedLibrary) CopyAndLink(dir string) error {
182182
return err
183183
}
184184

185-
sonameLink := filepath.Join(dir, lib.Soname)
185+
sonameLink := filepath.Join(dir, filepath.Base(lib.Soname))
186186
var sonameErr error
187187
if lib.Soname != "" {
188188
// Symlink must be relative.
189189
sonameErr = os.Symlink(filepath.Base(lib.RealName), sonameLink)
190190
}
191191

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

210210
func (lib SharedLibrary) LogValue() slog.Value {
211211
return slog.GroupValue(
212-
slog.String("lib.path", lib.Name()),
213-
slog.String("lib.linkername", lib.LinkerName),
214-
slog.String("lib.soname", lib.Soname),
215-
slog.String("lib.realname", lib.RealName),
212+
slog.String("path", lib.Name()),
213+
slog.String("linkername", lib.LinkerName),
214+
slog.String("soname", lib.Soname),
215+
slog.String("realname", lib.RealName),
216216
)
217217
}

internal/shellgen/tmpl/glibc-patch.nix.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
gcc = if isLinux then nixpkgs-glibc.legacyPackages."${system}".stdenv.cc.cc.lib else null;
9595

9696
DEVBOX_DEBUG = 1;
97-
97+
src = self;
9898
builder = "${devbox.packages.${system}.default}/bin/devbox";
9999
args = [ "patch" "--restore-refs" ] ++
100100
(if glibc != null then [ "--glibc" "${glibc}" ] else [ ]) ++

0 commit comments

Comments
 (0)