MCPcopy Index your code
hub / github.com/jetify-com/devbox / findCUDA

Method findCUDA

internal/patchpkg/builder.go:325–390  ·  view source on GitHub ↗
(ctx context.Context, out *packageFS)

Source from the content-addressed store, hash-verified

323}
324
325func (d *DerivationBuilder) findCUDA(ctx context.Context, out *packageFS) error {
326 if d.src == nil {
327 return fmt.Errorf("patch flake didn't set $src to the path to its source tree")
328 }
329
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)
333 if err != nil {
334 return fmt.Errorf("glob system libraries: %v", err)
335 }
336 if len(glob) == 0 {
337 slog.DebugContext(ctx, "no system CUDA libraries found in flake")
338 } else {
339 err := d.copyDir(out, "lib")
340 if err != nil {
341 return fmt.Errorf("copy system library: %v", err)
342 }
343 }
344 for _, lib := range glob {
345 slog.DebugContext(ctx, "found system CUDA library in flake", "path", lib)
346
347 err := d.copyFile(ctx, d.src, out, lib)
348 if err != nil {
349 return fmt.Errorf("copy system library: %v", err)
350 }
351 need, err := out.OSPath(lib)
352 if err != nil {
353 return fmt.Errorf("get absolute path to library: %v", err)
354 }
355 d.glibcPatcher.needed = append(d.glibcPatcher.needed, need)
356
357 slog.DebugContext(ctx, "added DT_NEEDED entry for system CUDA library", "path", need)
358 }
359
360 slog.DebugContext(ctx, "looking for nix libraries in $patchDependencies")
361 deps := os.Getenv("patchDependencies")
362 if strings.TrimSpace(deps) == "" {
363 slog.DebugContext(ctx, "$patchDependencies is empty")
364 return nil
365 }
366 for _, pkg := range strings.Split(deps, " ") {
367 slog.DebugContext(ctx, "checking for nix libraries in package", "pkg", pkg)
368
369 pkgFS := newPackageFS(pkg)
370 libs, err := fs.Glob(pkgFS, "lib*/*.so*")
371 if err != nil {
372 return fmt.Errorf("glob nix package libraries: %v", err)
373 }
374
375 sonameRegexp := regexp.MustCompile(`(^|/).+\.so\.\d+`)
376 for _, lib := range libs {
377 if !sonameRegexp.MatchString(lib) {
378 continue
379 }
380 need, err := pkgFS.OSPath(lib)
381 if err != nil {
382 return fmt.Errorf("get absolute path to nix package library: %v", err)

Callers 1

buildMethod · 0.95

Calls 4

copyDirMethod · 0.95
copyFileMethod · 0.95
newPackageFSFunction · 0.85
OSPathMethod · 0.80

Tested by

no test coverage detected