@@ -75,7 +75,15 @@ pub fn dylib_env_var() -> &'static str {
75
75
}
76
76
77
77
/// The platform-specific library file extension
78
- pub fn lib_extension ( ) -> & ' static str {
78
+ pub fn lib_extension ( dylib : bool ) -> & ' static str {
79
+ // In some casess (e.g. MUSL), we build a static
80
+ // library, rather than a dynamic library.
81
+ // In this case, the only path we can pass
82
+ // with '--extern-meta' is the '.lib' file
83
+ if !dylib {
84
+ return ".rlib"
85
+ }
86
+
79
87
if cfg ! ( windows) {
80
88
".dll"
81
89
} else if cfg ! ( target_os = "macos" ) {
@@ -1596,12 +1604,15 @@ impl<'test> TestCx<'test> {
1596
1604
create_dir_all ( & aux_dir) . unwrap ( ) ;
1597
1605
}
1598
1606
1599
- for priv_dep in & self . props . extern_private {
1600
- let lib_name = format ! ( "lib{}{}" , priv_dep, lib_extension( ) ) ;
1607
+ // Use a Vec instead of a HashMap to preserve original order
1608
+ let mut extern_priv = self . props . extern_private . clone ( ) ;
1609
+
1610
+ let mut add_extern_priv = |priv_dep : & str , dylib : bool | {
1611
+ let lib_name = format ! ( "lib{}{}" , priv_dep, lib_extension( dylib) ) ;
1601
1612
rustc
1602
1613
. arg ( "--extern-private" )
1603
1614
. arg ( format ! ( "{}={}" , priv_dep, aux_dir. join( lib_name) . to_str( ) . unwrap( ) ) ) ;
1604
- }
1615
+ } ;
1605
1616
1606
1617
for rel_ab in & self . props . aux_builds {
1607
1618
let aux_testpaths = self . compute_aux_test_paths ( rel_ab) ;
@@ -1619,8 +1630,8 @@ impl<'test> TestCx<'test> {
1619
1630
create_dir_all ( aux_cx. output_base_dir ( ) ) . unwrap ( ) ;
1620
1631
let mut aux_rustc = aux_cx. make_compile_args ( & aux_testpaths. file , aux_output) ;
1621
1632
1622
- let crate_type = if aux_props. no_prefer_dynamic {
1623
- None
1633
+ let ( dylib , crate_type) = if aux_props. no_prefer_dynamic {
1634
+ ( true , None )
1624
1635
} else if self . config . target . contains ( "cloudabi" )
1625
1636
|| self . config . target . contains ( "emscripten" )
1626
1637
|| ( self . config . target . contains ( "musl" ) && !aux_props. force_host )
@@ -1636,11 +1647,20 @@ impl<'test> TestCx<'test> {
1636
1647
// dynamic libraries so we just go back to building a normal library. Note,
1637
1648
// however, that for MUSL if the library is built with `force_host` then
1638
1649
// it's ok to be a dylib as the host should always support dylibs.
1639
- Some ( "lib" )
1650
+ ( false , Some ( "lib" ) )
1640
1651
} else {
1641
- Some ( "dylib" )
1652
+ ( true , Some ( "dylib" ) )
1642
1653
} ;
1643
1654
1655
+ let trimmed = rel_ab. trim_end_matches ( ".rs" ) . to_string ( ) ;
1656
+
1657
+ // Normally, every 'extern-private' has a correspodning 'aux-build'
1658
+ // entry. If so, we remove it from our list of private crates,
1659
+ // and add an '--extern-private' flag to rustc
1660
+ if extern_priv. remove_item ( & trimmed) . is_some ( ) {
1661
+ add_extern_priv ( & trimmed, dylib) ;
1662
+ }
1663
+
1644
1664
if let Some ( crate_type) = crate_type {
1645
1665
aux_rustc. args ( & [ "--crate-type" , crate_type] ) ;
1646
1666
}
@@ -1664,6 +1684,12 @@ impl<'test> TestCx<'test> {
1664
1684
}
1665
1685
}
1666
1686
1687
+ // Add any '--extenr-private' entries without a matching
1688
+ // 'aux-build'
1689
+ for private_lib in extern_priv {
1690
+ add_extern_priv ( & private_lib, true ) ;
1691
+ }
1692
+
1667
1693
rustc. envs ( self . props . rustc_env . clone ( ) ) ;
1668
1694
self . compose_and_run (
1669
1695
rustc,
0 commit comments