@@ -57,6 +57,41 @@ def _load_binary():
5757 if others :
5858 error_msg += f" Found binaries for: { ', ' .join (others )} . You may need to rebuild for the current platform."
5959 raise ImportError (error_msg )
60+ # Map platform to our specific Go shared library names
61+ lib_map = {
62+ "linux" : (".linux.so" , "pycymbal_go.so" ),
63+ "windows" : (".windows.dll" , "pycymbal_go.dll" ),
64+ "darwin" : (".darwin.dylib" , "pycymbal_go.dylib" )
65+ }
66+
67+ # On Windows, we must ensure the Go DLL is findable by the .pyd extension.
68+ # The .pyd is compiled to look for 'pycymbal_go.dll', but we distribute it
69+ # as 'pycymbal_go.windows.dll'. We'll create a link/copy if needed.
70+ if system in lib_map :
71+ suff , target_name = lib_map [system ]
72+ src_lib = os .path .join (pkg_dir , f"pycymbal_go{ suff } " )
73+ dst_lib = os .path .join (pkg_dir , target_name )
74+
75+ if os .path .exists (src_lib ) and not os .path .exists (dst_lib ):
76+ try :
77+ # Try symlink first, fallback to copy if on Windows without permissions
78+ if hasattr (os , "symlink" ) and system != "windows" :
79+ os .symlink (src_lib , dst_lib )
80+ else :
81+ import shutil
82+ shutil .copy2 (src_lib , dst_lib )
83+ except Exception as e :
84+ print (f"Warning: Could not create link from { src_lib } to { dst_lib } : { e } " , file = sys .stderr )
85+
86+ # DLL search path for Windows Python 3.8+
87+ if system == "windows" :
88+ if hasattr (os , "add_dll_directory" ):
89+ try :
90+ os .add_dll_directory (pkg_dir )
91+ except Exception :
92+ pass
93+ # Add to PATH as well for older Python versions or specific loader behaviors
94+ os .environ ['PATH' ] = pkg_dir + os .path .pathsep + os .environ .get ('PATH' , '' )
6095
6196 # Load the module
6297 spec = importlib .util .spec_from_file_location ("cymbal._pycymbal" , binary_path )
0 commit comments