path.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package discover
  2. import (
  3. "os"
  4. "path/filepath"
  5. "runtime"
  6. )
  7. // LibPath is a path to lookup dynamic libraries
  8. // in development it's usually 'build/lib/ollama'
  9. // in distribution builds it's 'lib/ollama' on Windows
  10. // '../lib/ollama' on Linux and the executable's directory on macOS
  11. // note: distribution builds, additional GPU-specific libraries are
  12. // found in subdirectories of the returned path, such as
  13. // 'cuda_v11', 'cuda_v12', 'rocm', etc.
  14. var LibOllamaPath string = func() string {
  15. exe, err := os.Executable()
  16. if err != nil {
  17. return ""
  18. }
  19. exe, err = filepath.EvalSymlinks(exe)
  20. if err != nil {
  21. return ""
  22. }
  23. libPath := filepath.Dir(exe)
  24. switch runtime.GOOS {
  25. case "windows":
  26. libPath = filepath.Join(filepath.Dir(exe), "lib", "ollama")
  27. case "linux":
  28. libPath = filepath.Join(filepath.Dir(exe), "..", "lib", "ollama")
  29. }
  30. cwd, err := os.Getwd()
  31. if err != nil {
  32. return ""
  33. }
  34. // build paths for development
  35. buildPaths := []string{
  36. filepath.Join(filepath.Dir(exe), "build", "lib", "ollama"),
  37. filepath.Join(cwd, "build", "lib", "ollama"),
  38. }
  39. for _, p := range buildPaths {
  40. if _, err := os.Stat(p); err == nil {
  41. return p
  42. }
  43. }
  44. return libPath
  45. }()