@@ -46,8 +46,8 @@ def _check_safe_mode() -> bool:
4646 return False
4747
4848
49- def _get_platform_dir () -> str :
50- """Get the platform directory name for the current system ."""
49+ def _get_platform_candidates () -> List [ str ] :
50+ """Get list of potential platform directory names ."""
5151 import platform as plat
5252 system = plat .system ().lower ()
5353 machine = plat .machine ().lower ()
@@ -57,8 +57,28 @@ def _get_platform_dir() -> str:
5757 machine = "x86_64"
5858 elif machine in ("arm64" , "aarch64" ):
5959 machine = "aarch64"
60+
61+ candidates = []
62+
63+ # 1. Existing format: system-machine (e.g., darwin-aarch64)
64+ candidates .append (f"{ system } -{ machine } " )
6065
61- return f"{ system } -{ machine } "
66+ # 2. Rust target triples (Standard naming)
67+ if system == "darwin" :
68+ if machine == "aarch64" :
69+ candidates .append ("aarch64-apple-darwin" )
70+ elif machine == "x86_64" :
71+ candidates .append ("x86_64-apple-darwin" )
72+ elif system == "linux" :
73+ if machine == "x86_64" :
74+ candidates .append ("x86_64-unknown-linux-gnu" )
75+ elif machine == "aarch64" :
76+ candidates .append ("aarch64-unknown-linux-gnu" )
77+ elif system == "windows" :
78+ if machine == "x86_64" :
79+ candidates .append ("x86_64-pc-windows-msvc" )
80+
81+ return candidates
6282
6383
6484def _find_library ():
@@ -80,7 +100,7 @@ def _find_library():
80100 lib_name = "libsochdb_index.so"
81101
82102 pkg_dir = os .path .dirname (__file__ )
83- platform_dir = _get_platform_dir ()
103+ platform_candidates = _get_platform_candidates ()
84104
85105 # 1. Environment variable override
86106 env_path = os .environ .get ("SOCHDB_LIB_PATH" )
@@ -93,23 +113,32 @@ def _find_library():
93113 return full_path
94114
95115 # Search paths in priority order
96- search_paths = [
97- # 2. Bundled library in wheel (platform-specific)
98- os .path .join (pkg_dir , "lib" , platform_dir ),
99- # 3. Bundled library in wheel (generic)
100- os .path .join (pkg_dir , "lib" ),
101- # 4. Package directory
102- pkg_dir ,
103- # 5. Development builds
104- os .path .join (pkg_dir , ".." , ".." , ".." , "target" , "release" ),
105- os .path .join (pkg_dir , ".." , ".." , ".." , "target" , "debug" ),
106- # 6. System paths (no manual setup required)
116+ search_paths = []
117+
118+ # 2. Bundled library in wheel (platform-specific candidates)
119+ for platform_dir in platform_candidates :
120+ search_paths .append (os .path .join (pkg_dir , "lib" , platform_dir ))
121+ # Also check local _bin for dev/other builds if structured that way
122+ search_paths .append (os .path .join (pkg_dir , "_bin" , platform_dir ))
123+
124+ # 3. Bundled library in wheel (generic)
125+ search_paths .append (os .path .join (pkg_dir , "lib" ))
126+
127+ # 4. Package directory
128+ search_paths .append (pkg_dir )
129+
130+ # 5. Development builds
131+ search_paths .append (os .path .join (pkg_dir , ".." , ".." , ".." , "target" , "release" ))
132+ search_paths .append (os .path .join (pkg_dir , ".." , ".." , ".." , "target" , "debug" ))
133+
134+ # 6. System paths (no manual setup required)
135+ search_paths .extend ([
107136 "/usr/local/lib" ,
108137 "/usr/lib" ,
109138 "/opt/homebrew/lib" , # macOS Apple Silicon Homebrew
110139 "/opt/local/lib" , # MacPorts
111140 os .path .expanduser ("~/.sochdb/lib" ), # User installation
112- ]
141+ ])
113142
114143 for path in search_paths :
115144 full_path = os .path .join (path , lib_name )
0 commit comments