@@ -821,6 +821,54 @@ def rebuild_generated_staticlib(optimizer_name):
821821
822822 @staticmethod
823823 def c_bindings_helper (optimizer_name ):
824+ if sys .platform == "win32" :
825+ result = RustBuildTestCase .c_bindings_cmake_helper (
826+ optimizer_name = optimizer_name ,
827+ build_dir_name = "cmake-build-run" )
828+ compile_stdout = result ["configure_stdout" ] + result ["build_stdout" ]
829+ compile_stderr = result ["configure_stderr" ] + result ["build_stderr" ]
830+ compile_returncode = (
831+ result ["configure_returncode" ]
832+ if result ["configure_returncode" ] != 0
833+ else result ["build_returncode" ]
834+ )
835+
836+ run_stdout = ""
837+ run_stderr = ""
838+ run_returncode = None
839+ if compile_returncode == 0 :
840+ executable_candidates = [
841+ os .path .join (result ["build_dir" ], "Debug" , "optimizer.exe" ),
842+ os .path .join (result ["build_dir" ], "optimizer.exe" ),
843+ os .path .join (result ["build_dir" ], "Debug" , "optimizer" ),
844+ os .path .join (result ["build_dir" ], "optimizer" ),
845+ ]
846+ executable_path = next (
847+ (candidate for candidate in executable_candidates if os .path .exists (candidate )),
848+ None ,
849+ )
850+ if executable_path is None :
851+ raise RuntimeError ("Could not locate built optimizer executable" )
852+
853+ run_process = subprocess .Popen (
854+ [executable_path ],
855+ stdout = subprocess .PIPE ,
856+ stderr = subprocess .PIPE ,
857+ )
858+ run_stdout_bytes , run_stderr_bytes = run_process .communicate ()
859+ run_stdout = run_stdout_bytes .decode ()
860+ run_stderr = run_stderr_bytes .decode ()
861+ run_returncode = run_process .returncode
862+
863+ return {
864+ "compile_returncode" : compile_returncode ,
865+ "compile_stdout" : compile_stdout ,
866+ "compile_stderr" : compile_stderr ,
867+ "run_returncode" : run_returncode ,
868+ "run_stdout" : run_stdout ,
869+ "run_stderr" : run_stderr ,
870+ }
871+
824872 compile_process = subprocess .Popen (
825873 ["/usr/bin/gcc" ,
826874 RustBuildTestCase .TEST_DIR + "/" + optimizer_name + "/example_optimizer.c" ,
@@ -880,13 +928,13 @@ def patch_c_bindings_example_parameter_initializer(optimizer_name, replacement_l
880928 return original_line
881929
882930 @staticmethod
883- def c_bindings_cmake_helper (optimizer_name ):
931+ def c_bindings_cmake_helper (optimizer_name , build_dir_name = "cmake-build-test" ):
884932 cmake_executable = shutil .which ("cmake" )
885933 if cmake_executable is None :
886934 raise unittest .SkipTest ("cmake is not available in PATH" )
887935
888936 optimizer_dir = os .path .join (RustBuildTestCase .TEST_DIR , optimizer_name )
889- build_dir = os .path .join (optimizer_dir , "cmake-build-test" )
937+ build_dir = os .path .join (optimizer_dir , build_dir_name )
890938 if os .path .isdir (build_dir ):
891939 shutil .rmtree (build_dir )
892940 os .makedirs (build_dir )
@@ -903,8 +951,11 @@ def c_bindings_cmake_helper(optimizer_name):
903951 build_stderr = b""
904952 build_returncode = None
905953 if configure_process .returncode == 0 :
954+ build_command = [cmake_executable , "--build" , "." ]
955+ if sys .platform == "win32" :
956+ build_command .extend (["--config" , "Debug" ])
906957 build_process = subprocess .Popen (
907- [ cmake_executable , "--build" , "." ] ,
958+ build_command ,
908959 cwd = build_dir ,
909960 stdout = subprocess .PIPE ,
910961 stderr = subprocess .PIPE ,
@@ -919,6 +970,7 @@ def c_bindings_cmake_helper(optimizer_name):
919970 "build_returncode" : build_returncode ,
920971 "build_stdout" : build_stdout .decode (),
921972 "build_stderr" : build_stderr .decode (),
973+ "build_dir" : build_dir ,
922974 }
923975
924976 def test_c_bindings (self ):
0 commit comments