@@ -1521,7 +1521,7 @@ fn remap_path_prefix_works() {
1521
1521
}
1522
1522
1523
1523
#[ cargo_test]
1524
- fn remap_path_prefix_ignored ( ) {
1524
+ fn rustflags_remap_path_prefix_ignored_for_c_metadata ( ) {
1525
1525
let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
1526
1526
1527
1527
let build_output = p
@@ -1531,16 +1531,89 @@ fn remap_path_prefix_ignored() {
1531
1531
"--remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo" ,
1532
1532
)
1533
1533
. run ( ) ;
1534
- let build_c_metadata = dbg ! ( get_c_metadata( build_output) ) ;
1534
+ let first_c_metadata = dbg ! ( get_c_metadata( build_output) ) ;
1535
1535
1536
1536
p. cargo ( "clean" ) . run ( ) ;
1537
1537
1538
- let rustc_output = p
1538
+ let build_output = p
1539
+ . cargo ( "build -v" )
1540
+ . env (
1541
+ "RUSTFLAGS" ,
1542
+ "--remap-path-prefix=/def=/zoo --remap-path-prefix /earth=/zoo" ,
1543
+ )
1544
+ . run ( ) ;
1545
+ let second_c_metadata = dbg ! ( get_c_metadata( build_output) ) ;
1546
+
1547
+ assert_data_eq ! ( first_c_metadata, second_c_metadata) ;
1548
+ }
1549
+
1550
+ #[ cargo_test]
1551
+ fn rustc_remap_path_prefix_ignored_for_c_metadata ( ) {
1552
+ let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
1553
+
1554
+ let build_output = p
1555
+ . cargo ( "rustc -v -- --remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo" )
1556
+ . run ( ) ;
1557
+ let first_c_metadata = dbg ! ( get_c_metadata( build_output) ) ;
1558
+
1559
+ p. cargo ( "clean" ) . run ( ) ;
1560
+
1561
+ let build_output = p
1562
+ . cargo ( "rustc -v -- --remap-path-prefix=/def=/zoo --remap-path-prefix /earth=/zoo" )
1563
+ . run ( ) ;
1564
+ let second_c_metadata = dbg ! ( get_c_metadata( build_output) ) ;
1565
+
1566
+ assert_data_eq ! ( first_c_metadata, second_c_metadata) ;
1567
+ }
1568
+
1569
+ // `--remap-path-prefix` is meant to take two different binaries and make them the same but the
1570
+ // rlib name, including `-Cextra-filename`, can still end up in the binary so it can't change
1571
+ #[ cargo_test]
1572
+ fn rustflags_remap_path_prefix_ignored_for_c_extra_filename ( ) {
1573
+ let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
1574
+
1575
+ let build_output = p
1576
+ . cargo ( "build -v" )
1577
+ . env (
1578
+ "RUSTFLAGS" ,
1579
+ "--remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo" ,
1580
+ )
1581
+ . run ( ) ;
1582
+ let first_c_extra_filename = dbg ! ( get_c_extra_filename( build_output) ) ;
1583
+
1584
+ p. cargo ( "clean" ) . run ( ) ;
1585
+
1586
+ let build_output = p
1587
+ . cargo ( "build -v" )
1588
+ . env (
1589
+ "RUSTFLAGS" ,
1590
+ "--remap-path-prefix=/def=/zoo --remap-path-prefix /earth=/zoo" ,
1591
+ )
1592
+ . run ( ) ;
1593
+ let second_c_extra_filename = dbg ! ( get_c_extra_filename( build_output) ) ;
1594
+
1595
+ assert_data_eq ! ( first_c_extra_filename, second_c_extra_filename) ;
1596
+ }
1597
+
1598
+ // `--remap-path-prefix` is meant to take two different binaries and make them the same but the
1599
+ // rlib name, including `-Cextra-filename`, can still end up in the binary so it can't change
1600
+ #[ cargo_test]
1601
+ fn rustc_remap_path_prefix_ignored_for_c_extra_filename ( ) {
1602
+ let p = project ( ) . file ( "src/lib.rs" , "" ) . build ( ) ;
1603
+
1604
+ let build_output = p
1539
1605
. cargo ( "rustc -v -- --remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo" )
1540
1606
. run ( ) ;
1541
- let rustc_c_metadata = dbg ! ( get_c_metadata( rustc_output) ) ;
1607
+ let first_c_extra_filename = dbg ! ( get_c_extra_filename( build_output) ) ;
1608
+
1609
+ p. cargo ( "clean" ) . run ( ) ;
1610
+
1611
+ let build_output = p
1612
+ . cargo ( "rustc -v -- --remap-path-prefix=/def=/zoo --remap-path-prefix /earth=/zoo" )
1613
+ . run ( ) ;
1614
+ let second_c_extra_filename = dbg ! ( get_c_extra_filename( build_output) ) ;
1542
1615
1543
- assert_data_eq ! ( rustc_c_metadata , build_c_metadata ) ;
1616
+ assert_data_eq ! ( first_c_extra_filename , second_c_extra_filename ) ;
1544
1617
}
1545
1618
1546
1619
fn get_c_metadata ( output : RawOutput ) -> String {
@@ -1563,6 +1636,26 @@ fn get_c_metadata(output: RawOutput) -> String {
1563
1636
c_metadata. join ( "\n " )
1564
1637
}
1565
1638
1639
+ fn get_c_extra_filename ( output : RawOutput ) -> String {
1640
+ let get_c_extra_filename_re =
1641
+ regex:: Regex :: new ( r".* (--crate-name [^ ]+).* (-C ?extra-filename=[^ ]+).*" ) . unwrap ( ) ;
1642
+
1643
+ let stderr = String :: from_utf8 ( output. stderr ) . unwrap ( ) ;
1644
+ let mut c_extra_filename = get_c_extra_filename_re
1645
+ . captures_iter ( & stderr)
1646
+ . map ( |c| {
1647
+ let ( _, [ name, c_extra_filename] ) = c. extract ( ) ;
1648
+ format ! ( "{name} {c_extra_filename}" )
1649
+ } )
1650
+ . collect :: < Vec < _ > > ( ) ;
1651
+ assert ! (
1652
+ !c_extra_filename. is_empty( ) ,
1653
+ "`{get_c_extra_filename_re:?}` did not match:\n ```\n {stderr}\n ```"
1654
+ ) ;
1655
+ c_extra_filename. sort ( ) ;
1656
+ c_extra_filename. join ( "\n " )
1657
+ }
1658
+
1566
1659
#[ cargo_test]
1567
1660
fn host_config_rustflags_with_target ( ) {
1568
1661
// regression test for https://github.com/rust-lang/cargo/issues/10206
0 commit comments