path.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. var libPath string
  20. switch runtime.GOOS {
  21. case "windows":
  22. libPath = filepath.Join(filepath.Dir(exe), "lib", "ollama")
  23. case "linux":
  24. libPath = filepath.Join(filepath.Dir(exe), "..", "lib", "ollama")
  25. case "darwin":
  26. libPath = filepath.Dir(exe)
  27. }
  28. cwd, err := os.Getwd()
  29. if err != nil {
  30. return ""
  31. }
  32. paths := []string{
  33. libPath,
  34. // build paths for development
  35. filepath.Join(filepath.Dir(exe), "build", "lib", "ollama"),
  36. filepath.Join(cwd, "build", "lib", "ollama"),
  37. }
  38. for _, p := range paths {
  39. if _, err := os.Stat(p); err == nil {
  40. return p
  41. }
  42. }
  43. return filepath.Dir(exe)
  44. }()