@@ -1845,16 +1845,25 @@ impl<'test> TestCx<'test> {
18451845 // Musl toolchain is build on linux-gnu host
18461846 // but with proper setup it can behave almost* like native linux-musl.
18471847 // 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 {
18491849 self . maybe_add_external_args ( & mut rustc,
18501850 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+ }
18511856 } else {
18521857 self . maybe_add_external_args ( & mut rustc,
18531858 self . split_maybe_args ( & self . config . target_rustcflags ) ) ;
18541859 if !is_rustdoc {
18551860 if let Some ( ref linker) = self . config . linker {
18561861 rustc. arg ( format ! ( "-Clinker={}" , linker) ) ;
18571862 }
1863+ } else if self . config . target . contains ( "musl" ) {
1864+ if let Some ( ref linker) = self . config . linker {
1865+ rustc. arg ( format ! ( "--linker={}" , linker) ) ;
1866+ }
18581867 }
18591868 }
18601869
@@ -2646,6 +2655,12 @@ impl<'test> TestCx<'test> {
26462655 // compiler flags set in the test cases:
26472656 cmd. env_remove ( "RUSTFLAGS" ) ;
26482657
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+
26492664 if self . config . target . contains ( "msvc" ) && self . config . cc != "" {
26502665 // We need to pass a path to `lib.exe`, so assume that `cc` is `cl.exe`
26512666 // and that `lib.exe` lives next to it.
@@ -2668,8 +2683,13 @@ impl<'test> TestCx<'test> {
26682683 . env ( "CC" , format ! ( "'{}' {}" , self . config. cc, cflags) )
26692684 . env ( "CXX" , format ! ( "'{}'" , & self . config. cxx) ) ;
26702685 } 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) )
26732693 . env ( "AR" , & self . config . ar ) ;
26742694
26752695 if self . config . target . contains ( "windows" ) {
0 commit comments