@@ -171,7 +171,6 @@ fn cross_compiling() -> Result<Option<CrossCompileConfig>> {
171
171
///
172
172
/// (hrm, this is sort of re-implementing what distutils does, except
173
173
/// by passing command line args instead of referring to a python.h)
174
- #[ cfg( not( target_os = "windows" ) ) ]
175
174
static SYSCONFIG_FLAGS : [ & str ; 7 ] = [
176
175
"Py_USING_UNICODE" ,
177
176
"Py_UNICODE_WIDE" ,
@@ -443,8 +442,11 @@ fn load_cross_compile_info(
443
442
/// Examine python's compile flags to pass to cfg by launching
444
443
/// the interpreter and printing variables of interest from
445
444
/// sysconfig.get_config_vars.
446
- #[ cfg( not( target_os = "windows" ) ) ]
447
445
fn get_config_vars ( python_path : & Path ) -> Result < HashMap < String , String > > {
446
+ if env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) == "windows" {
447
+ return get_config_vars_windows ( python_path) ;
448
+ }
449
+
448
450
let mut script = "import sysconfig; \
449
451
config = sysconfig.get_config_vars();"
450
452
. to_owned ( ) ;
@@ -478,8 +480,7 @@ fn get_config_vars(python_path: &Path) -> Result<HashMap<String, String>> {
478
480
Ok ( fix_config_map ( all_vars) )
479
481
}
480
482
481
- #[ cfg( target_os = "windows" ) ]
482
- fn get_config_vars ( _: & Path ) -> Result < HashMap < String , String > > {
483
+ fn get_config_vars_windows ( _: & Path ) -> Result < HashMap < String , String > > {
483
484
// sysconfig is missing all the flags on windows, so we can't actually
484
485
// query the interpreter directly for its build flags.
485
486
//
@@ -567,9 +568,15 @@ fn get_library_link_name(version: &PythonVersion, ld_version: &str) -> String {
567
568
}
568
569
}
569
570
570
- #[ cfg( not( target_os = "macos" ) ) ]
571
- #[ cfg( not( target_os = "windows" ) ) ]
572
571
fn get_rustc_link_lib ( config : & InterpreterConfig ) -> Result < String > {
572
+ match env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) . as_str ( ) {
573
+ "windows" => get_rustc_link_lib_windows ( config) ,
574
+ "macos" => get_rustc_link_lib_macos ( config) ,
575
+ _ => get_rustc_link_lib_unix ( config) ,
576
+ }
577
+ }
578
+
579
+ fn get_rustc_link_lib_unix ( config : & InterpreterConfig ) -> Result < String > {
573
580
if config. shared {
574
581
Ok ( format ! (
575
582
"cargo:rustc-link-lib={}" ,
@@ -583,7 +590,6 @@ fn get_rustc_link_lib(config: &InterpreterConfig) -> Result<String> {
583
590
}
584
591
}
585
592
586
- #[ cfg( target_os = "macos" ) ]
587
593
fn get_macos_linkmodel ( config : & InterpreterConfig ) -> Result < String > {
588
594
// PyPy 3.6 ships with a shared library, but doesn't have Py_ENABLE_SHARED.
589
595
if config. version . implementation == PythonInterpreterKind :: PyPy {
@@ -604,8 +610,7 @@ else:
604
610
Ok ( out. trim_end ( ) . to_owned ( ) )
605
611
}
606
612
607
- #[ cfg( target_os = "macos" ) ]
608
- fn get_rustc_link_lib ( config : & InterpreterConfig ) -> Result < String > {
613
+ fn get_rustc_link_lib_macos ( config : & InterpreterConfig ) -> Result < String > {
609
614
// os x can be linked to a framework or static or dynamic, and
610
615
// Py_ENABLE_SHARED is wrong; framework means shared library
611
616
let link_name = get_library_link_name ( & config. version , & config. ld_version ) ;
@@ -617,8 +622,7 @@ fn get_rustc_link_lib(config: &InterpreterConfig) -> Result<String> {
617
622
}
618
623
}
619
624
620
- #[ cfg( target_os = "windows" ) ]
621
- fn get_rustc_link_lib ( config : & InterpreterConfig ) -> Result < String > {
625
+ fn get_rustc_link_lib_windows ( config : & InterpreterConfig ) -> Result < String > {
622
626
// Py_ENABLE_SHARED doesn't seem to be present on windows.
623
627
Ok ( format ! (
624
628
"cargo:rustc-link-lib=pythonXY:{}" ,
@@ -733,7 +737,7 @@ fn configure(interpreter_config: &InterpreterConfig) -> Result<String> {
733
737
println ! ( "{}" , get_rustc_link_lib( & interpreter_config) ?) ;
734
738
if let Some ( libdir) = & interpreter_config. libdir {
735
739
println ! ( "cargo:rustc-link-search=native={}" , libdir) ;
736
- } else if cfg ! ( target_os = "windows" ) {
740
+ } else if target_os == "windows" {
737
741
println ! (
738
742
"cargo:rustc-link-search=native={}\\ libs" ,
739
743
interpreter_config. base_prefix
@@ -818,9 +822,6 @@ fn main() -> Result<()> {
818
822
// Detecting if cross-compiling by checking if the target triple is different from the host
819
823
// rustc's triple.
820
824
let ( interpreter_config, mut config_map) = if let Some ( paths) = cross_compiling ( ) ? {
821
- // If cross compiling we need the path to the cross-compiled include dir and lib dir, else
822
- // fail quickly and loudly
823
-
824
825
load_cross_compile_info ( paths) ?
825
826
} else {
826
827
find_interpreter_and_get_config ( ) ?
0 commit comments