@@ -1845,16 +1845,25 @@ impl<'test> TestCx<'test> {
1845
1845
// Musl toolchain is build on linux-gnu host
1846
1846
// but with proper setup it can behave almost* like native linux-musl.
1847
1847
// One difference is "cc" which will link to glibc; force musl cc.
1848
- if self . props . force_host && ! self . config . target . contains ( "musl" ) {
1848
+ if self . props . force_host {
1849
1849
self . maybe_add_external_args ( & mut rustc,
1850
1850
self . split_maybe_args ( & self . config . host_rustcflags ) ) ;
1851
+ if self . config . target . contains ( "musl" ) {
1852
+ if let Some ( ref linker) = self . config . linker {
1853
+ rustc. arg ( format ! ( "-Clinker={}" , linker) ) ;
1854
+ }
1855
+ }
1851
1856
} else {
1852
1857
self . maybe_add_external_args ( & mut rustc,
1853
1858
self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
1854
1859
if !is_rustdoc {
1855
1860
if let Some ( ref linker) = self . config . linker {
1856
1861
rustc. arg ( format ! ( "-Clinker={}" , linker) ) ;
1857
1862
}
1863
+ } else if self . config . target . contains ( "musl" ) {
1864
+ if let Some ( ref linker) = self . config . linker {
1865
+ rustc. arg ( format ! ( "--linker={}" , linker) ) ;
1866
+ }
1858
1867
}
1859
1868
}
1860
1869
@@ -2646,6 +2655,12 @@ impl<'test> TestCx<'test> {
2646
2655
// compiler flags set in the test cases:
2647
2656
cmd. env_remove ( "RUSTFLAGS" ) ;
2648
2657
2658
+ // Use dynamic musl for tests because static doesn't allow creating dylibs
2659
+ if self . config . target . contains ( "musl" ) {
2660
+ cmd. env ( "RUSTFLAGS" , "-Ctarget-feature=-crt-static" )
2661
+ . env ( "IS_MUSL_HOST" , "1" ) ;
2662
+ }
2663
+
2649
2664
if self . config . target . contains ( "msvc" ) && self . config . cc != "" {
2650
2665
// We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
2651
2666
// and that `lib.exe` lives next to it.
@@ -2668,8 +2683,13 @@ impl<'test> TestCx<'test> {
2668
2683
. env ( "CC" , format ! ( "'{}' {}" , self . config. cc, cflags) )
2669
2684
. env ( "CXX" , format ! ( "'{}'" , & self . config. cxx) ) ;
2670
2685
} else {
2671
- cmd. env ( "CC" , format ! ( "{} {}" , self . config. cc, self . config. cflags) )
2672
- . env ( "CXX" , format ! ( "{} {}" , self . config. cxx, self . config. cflags) )
2686
+ let cflags = if self . config . target . contains ( "musl" ) {
2687
+ self . config . cflags . replace ( "-static" , "" )
2688
+ } else {
2689
+ self . config . cflags . to_string ( )
2690
+ } ;
2691
+ cmd. env ( "CC" , format ! ( "{} {}" , self . config. cc, cflags) )
2692
+ . env ( "CXX" , format ! ( "{} {}" , self . config. cxx, cflags) )
2673
2693
. env ( "AR" , & self . config . ar ) ;
2674
2694
2675
2695
if self . config . target . contains ( "windows" ) {
0 commit comments