2929def build_go_library ():
3030 """Build the Go shared library"""
3131 print ("Building Go shared library..." )
32-
32+
3333 # Change to the project root directory
3434 project_root = Path (__file__ ).parent .parent
3535 os .chdir (project_root )
36-
36+
3737 # Build the shared library
3838 output_path = f"python/spl_toolkit/libspl_toolkit{ SHARED_EXT } "
3939 cmd = [
@@ -42,10 +42,18 @@ def build_go_library():
4242 "-o" , output_path ,
4343 "./pkg/bindings" ,
4444 ]
45-
45+
46+ env = os .environ .copy ()
47+ # Ensure CGO is enabled for c-shared builds
48+ env .setdefault ("CGO_ENABLED" , "1" )
49+
4650 try :
47- result = subprocess .run (cmd , check = True , capture_output = True , text = True )
48- print ("Go library built successfully" )
51+ result = subprocess .run (cmd , check = True , capture_output = True , text = True , env = env )
52+ # Verify output file exists
53+ if not Path (output_path ).exists ():
54+ print (f"Go build reported success but output not found: { output_path } " )
55+ return False
56+ print ("Go library built successfully:" , output_path )
4957 return True
5058 except subprocess .CalledProcessError as e :
5159 print (f"Failed to build Go library: { e } " )
@@ -70,6 +78,16 @@ def run(self):
7078 print ("You may need to build it manually with: go build -buildmode=c-shared -o python/spl_toolkit/libspl_toolkit.so ./pkg/bindings" )
7179
7280from wheel .bdist_wheel import bdist_wheel
81+ from setuptools .command .build_py import build_py as _build_py
82+
83+ class build_py_go (_build_py ):
84+ def run (self ):
85+ # Build the Go shared library before packaging Python modules
86+ require_build = os .environ .get ("CIBUILDWHEEL" ) == "1" or os .environ .get ("FORCE_BUILD_GO" ) == "1"
87+ success = build_go_library ()
88+ if not success and require_build :
89+ raise RuntimeError ("Failed to build Go shared library during wheel build. See logs above." )
90+ super ().run ()
7391
7492class bdist_wheel_plat (bdist_wheel ):
7593 def finalize_options (self ):
@@ -128,7 +146,8 @@ def finalize_options(self):
128146 include_package_data = True ,
129147 zip_safe = False , # Due to shared library
130148 cmdclass = {
131- # Mark wheel as non-pure so it gets a platform tag
149+ # Ensure Go library is built and mark wheel as non-pure
150+ "build_py" : build_py_go ,
132151 "bdist_wheel" : bdist_wheel_plat ,
133152 },
134153 keywords = "splunk spl query parser field mapping analysis" ,
0 commit comments