@@ -353,6 +353,23 @@ impl Config {
353353 self . compile_objects ( & src_dst) ;
354354 self . assemble ( lib_name, & dst. join ( output) , & objects) ;
355355
356+ if self . get_target ( ) . contains ( "msvc" ) {
357+ let compiler = self . get_base_compiler ( ) ;
358+ let atlmfc_lib = compiler. env ( ) . iter ( ) . find ( |& & ( ref var, _) | {
359+ var == OsStr :: new ( "LIB" )
360+ } ) . and_then ( |& ( _, ref lib_paths) | {
361+ env:: split_paths ( lib_paths) . find ( |path| {
362+ let sub = Path :: new ( "atlmfc/lib" ) ;
363+ path. ends_with ( sub) || path. parent ( ) . map_or ( false , |p| p. ends_with ( sub) )
364+ } )
365+ } ) ;
366+
367+ if let Some ( atlmfc_lib) = atlmfc_lib {
368+ self . print ( & format ! ( "cargo:rustc-link-search=native={}" ,
369+ atlmfc_lib. display( ) ) ) ;
370+ }
371+ }
372+
356373 self . print ( & format ! ( "cargo:rustc-link-lib=static={}" ,
357374 & output[ 3 ..output. len( ) - 2 ] ) ) ;
358375 self . print ( & format ! ( "cargo:rustc-link-search=native={}" , dst. display( ) ) ) ;
@@ -446,17 +463,20 @@ impl Config {
446463
447464 if msvc {
448465 cmd. args . push ( "/nologo" . into ( ) ) ;
449- cmd. args . push ( "/MD" . into ( ) ) ; // link against msvcrt.dll for now
466+ let features = env:: var ( "CARGO_CFG_TARGET_FEATURE" )
467+ . unwrap_or ( String :: new ( ) ) ;
468+ if features. contains ( "crt-static" ) {
469+ cmd. args . push ( "/MT" . into ( ) ) ;
470+ } else {
471+ cmd. args . push ( "/MD" . into ( ) ) ;
472+ }
450473 match & opt_level[ ..] {
451474 "z" | "s" => cmd. args . push ( "/Os" . into ( ) ) ,
452475 "2" => cmd. args . push ( "/O2" . into ( ) ) ,
453476 "1" => cmd. args . push ( "/O1" . into ( ) ) ,
454477 _ => { }
455478 }
456- if target. contains ( "i686" ) {
457- cmd. args . push ( "/SAFESEH" . into ( ) ) ;
458- } else if target. contains ( "i586" ) {
459- cmd. args . push ( "/SAFESEH" . into ( ) ) ;
479+ if target. contains ( "i586" ) {
460480 cmd. args . push ( "/ARCH:IA32" . into ( ) ) ;
461481 }
462482 } else if nvcc {
@@ -489,27 +509,48 @@ impl Config {
489509 cmd. args . push ( "-Xcompiler" . into ( ) ) ;
490510 cmd. args . push ( "\' -fPIC\' " . into ( ) ) ;
491511 }
512+
492513 if target. contains ( "musl" ) {
493514 cmd. args . push ( "-static" . into ( ) ) ;
494515 }
495516
517+ // armv7 targets get to use armv7 instructions
496518 if target. starts_with ( "armv7-unknown-linux-" ) {
497519 cmd. args . push ( "-march=armv7-a" . into ( ) ) ;
498520 }
521+
522+ // On android we can guarantee some extra float instructions
523+ // (specified in the android spec online)
499524 if target. starts_with ( "armv7-linux-androideabi" ) {
500525 cmd. args . push ( "-march=armv7-a" . into ( ) ) ;
501526 cmd. args . push ( "-mfpu=vfpv3-d16" . into ( ) ) ;
502527 }
528+
529+ // For us arm == armv6 by default
503530 if target. starts_with ( "arm-unknown-linux-" ) {
504531 cmd. args . push ( "-march=armv6" . into ( ) ) ;
505532 cmd. args . push ( "-marm" . into ( ) ) ;
506533 }
534+
535+ // Turn codegen down on i586 to avoid some instructions.
507536 if target. starts_with ( "i586-unknown-linux-" ) {
508537 cmd. args . push ( "-march=pentium" . into ( ) ) ;
509538 }
539+
540+ // Set codegen level for i686 correctly
510541 if target. starts_with ( "i686-unknown-linux-" ) {
511542 cmd. args . push ( "-march=i686" . into ( ) ) ;
512543 }
544+
545+ // Looks like `musl-gcc` makes is hard for `-m32` to make its way
546+ // all the way to the linker, so we need to actually instruct the
547+ // linker that we're generating 32-bit executables as well. This'll
548+ // typically only be used for build scripts which transitively use
549+ // these flags that try to compile executables.
550+ if target == "i686-unknown-linux-musl" {
551+ cmd. args . push ( "-Wl,-melf_i386" . into ( ) ) ;
552+ }
553+
513554 if target. starts_with ( "thumb" ) {
514555 cmd. args . push ( "-mthumb" . into ( ) ) ;
515556
@@ -518,10 +559,14 @@ impl Config {
518559 }
519560 }
520561 if target. starts_with ( "thumbv6m" ) {
521- cmd. args . push ( "-march=armv6 -m" . into ( ) ) ;
562+ cmd. args . push ( "-march=armv6s -m" . into ( ) ) ;
522563 }
523564 if target. starts_with ( "thumbv7em" ) {
524565 cmd. args . push ( "-march=armv7e-m" . into ( ) ) ;
566+
567+ if target. ends_with ( "eabihf" ) {
568+ cmd. args . push ( "-mfpu=fpv4-sp-d16" . into ( ) )
569+ }
525570 }
526571 if target. starts_with ( "thumbv7m" ) {
527572 cmd. args . push ( "-march=armv7-m" . into ( ) ) ;
@@ -739,6 +784,7 @@ impl Config {
739784 "powerpc64-unknown-linux-gnu" => Some ( "powerpc-linux-gnu" ) ,
740785 "powerpc64le-unknown-linux-gnu" => Some ( "powerpc64le-linux-gnu" ) ,
741786 "s390x-unknown-linux-gnu" => Some ( "s390x-linux-gnu" ) ,
787+ "sparc64-unknown-netbsd" => Some ( "sparc64--netbsd" ) ,
742788 "thumbv6m-none-eabi" => Some ( "arm-none-eabi" ) ,
743789 "thumbv7em-none-eabi" => Some ( "arm-none-eabi" ) ,
744790 "thumbv7em-none-eabihf" => Some ( "arm-none-eabi" ) ,
@@ -805,6 +851,8 @@ impl Config {
805851 None
806852 } else if target. contains ( "darwin" ) {
807853 Some ( "c++" . to_string ( ) )
854+ } else if target. contains ( "freebsd" ) {
855+ Some ( "c++" . to_string ( ) )
808856 } else {
809857 Some ( "stdc++" . to_string ( ) )
810858 }
0 commit comments