mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 02:24:59 +00:00
feat(libpath): refactor and expose functions for external library paths (#2578)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
ac4a94dd44
commit
94cfaad7f4
5 changed files with 59 additions and 23 deletions
41
pkg/library/dynaload.go
Normal file
41
pkg/library/dynaload.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package library
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func LoadExtractedLibs(dir string) {
|
||||
// Skip this if LOCALAI_SKIP_LIBRARY_PATH is set
|
||||
if os.Getenv("LOCALAI_SKIP_LIBRARY_PATH") != "" {
|
||||
return
|
||||
}
|
||||
|
||||
for _, libDir := range []string{filepath.Join(dir, "backend-assets", "lib"), filepath.Join(dir, "lib")} {
|
||||
LoadExternal(libDir)
|
||||
}
|
||||
}
|
||||
|
||||
func LoadExternal(dir string) {
|
||||
// Skip this if LOCALAI_SKIP_LIBRARY_PATH is set
|
||||
if os.Getenv("LOCALAI_SKIP_LIBRARY_PATH") != "" {
|
||||
return
|
||||
}
|
||||
|
||||
lpathVar := "LD_LIBRARY_PATH"
|
||||
if runtime.GOOS == "darwin" {
|
||||
lpathVar = "DYLD_FALLBACK_LIBRARY_PATH" // should it be DYLD_LIBRARY_PATH ?
|
||||
}
|
||||
|
||||
if _, err := os.Stat(dir); err == nil {
|
||||
ldLibraryPath := os.Getenv(lpathVar)
|
||||
if ldLibraryPath == "" {
|
||||
ldLibraryPath = dir
|
||||
} else {
|
||||
ldLibraryPath = fmt.Sprintf("%s:%s", ldLibraryPath, dir)
|
||||
}
|
||||
os.Setenv(lpathVar, ldLibraryPath)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue