Skip to content

Commit

Permalink
feat(startup): allow to load libs from extracted assets
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Jun 8, 2024
1 parent ee6e565 commit 4412036
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/assets/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,25 @@ func ExtractFiles(content embed.FS, extractDir string) error {
return nil
})

// If there is a lib directory, set LD_LIBRARY_PATH to include it
// we might use this mechanism to carry over e.g. Nvidia CUDA libraries
// from the embedded FS to the target directory

// Skip this if LOCALAI_SKIP_LD_LIBRARY_PATH is set
if os.Getenv("LOCALAI_SKIP_LD_LIBRARY_PATH") != "" {
return err
}

for _, libDir := range []string{filepath.Join(extractDir, "backend_assets", "lib"), filepath.Join(extractDir, "lib")} {
if _, err := os.Stat(libDir); err == nil {
ldLibraryPath := os.Getenv("LD_LIBRARY_PATH")
if ldLibraryPath == "" {
ldLibraryPath = libDir
} else {
ldLibraryPath = fmt.Sprintf("%s:%s", ldLibraryPath, libDir)
}
os.Setenv("LD_LIBRARY_PATH", ldLibraryPath)

Check warning

Code scanning / gosec

Errors unhandled. Warning

Errors unhandled.
}
}
return err
}

0 comments on commit 4412036

Please sign in to comment.