From 44120364c3aa17d5d5627b12e41e2d0c7468a3ff Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 8 Jun 2024 23:46:22 +0200 Subject: [PATCH] feat(startup): allow to load libs from extracted assets Signed-off-by: Ettore Di Giacinto --- pkg/assets/extract.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/assets/extract.go b/pkg/assets/extract.go index 8f668a1aaed..7727edfa621 100644 --- a/pkg/assets/extract.go +++ b/pkg/assets/extract.go @@ -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) + } + } return err }