@@ -159,6 +159,8 @@ pub struct ParsedArguments {
159159 crate_name : String ,
160160 /// The crate types that will be generated
161161 crate_types : CrateTypes ,
162+ /// The hash pased to -Cextra-filename
163+ extra_filename : Option < String > ,
162164 /// If dependency info is being emitted, the name of the dep info file.
163165 dep_info : Option < PathBuf > ,
164166 /// If profile info is being emitted, the path of the profile.
@@ -1252,7 +1254,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
12521254 // Figure out the dep-info filename, if emitting dep-info.
12531255 let dep_info = if emit. contains ( "dep-info" ) {
12541256 let mut dep_info = crate_name. clone ( ) ;
1255- if let Some ( extra_filename) = extra_filename. clone ( ) {
1257+ if let Some ( extra_filename) = extra_filename. as_ref ( ) {
12561258 dep_info. push_str ( & extra_filename[ ..] ) ;
12571259 }
12581260 dep_info. push_str ( ".d" ) ;
@@ -1267,7 +1269,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
12671269 // Figure out the gcno filename, if producing gcno files with `-Zprofile`.
12681270 let gcno = if gcno && emit. contains ( "link" ) {
12691271 let mut gcno = crate_name. clone ( ) ;
1270- if let Some ( extra_filename) = extra_filename {
1272+ if let Some ( extra_filename) = extra_filename. as_ref ( ) {
12711273 gcno. push_str ( & extra_filename[ ..] ) ;
12721274 }
12731275 gcno. push_str ( ".gcno" ) ;
@@ -1310,6 +1312,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
13101312 crate_link_paths,
13111313 staticlibs,
13121314 crate_name,
1315+ extra_filename,
13131316 dep_info : dep_info. map ( |s| s. into ( ) ) ,
13141317 profile : profile. map ( |s| s. into ( ) ) ,
13151318 gcno : gcno. map ( |s| s. into ( ) ) ,
@@ -1456,15 +1459,22 @@ where
14561459 let ( mut sortables, rest) : ( Vec < _ > , Vec < _ > ) = os_string_arguments
14571460 . iter ( )
14581461 // We exclude a few arguments from the hash:
1459- // -L, --extern, --out-dir, --diagnostic-width
1462+ // -L, --extern, --out-dir, --diagnostic-width, -Cprefer-dynamic, -Cextra-filename
14601463 // These contain paths which aren't relevant to the output, and the compiler inputs
14611464 // in those paths (rlibs and static libs used in the compilation) are used as hash
1462- // inputs below.
1463- . filter ( |& ( arg, _) | {
1465+ // inputs below. -Cextra-filename is okay to exclude from the hash because we remove
1466+ // the extra component from the cache keys below (`remove_extra_filename`)
1467+ . filter ( |& ( arg, value) | {
14641468 !( arg == "--extern"
14651469 || arg == "-L"
14661470 || arg == "--out-dir"
1467- || arg == "--diagnostic-width" )
1471+ || arg == "--diagnostic-width"
1472+ || ( arg == "-C" && value == & Some ( OsString :: from ( "prefer-dynamic" ) ) )
1473+ || ( arg == "-C" && value. as_ref ( ) . is_some_and ( |v| v. starts_with ( "extra-filename" ) ) ) )
1474+ // prefer-dynamic never affects staticlibs or rlib
1475+ // see https://github.com/rust-lang/rust/blob/master/compiler/rustc_metadata/src/dependency_format.rs
1476+ // note that the unstable `staticlib-prefer-dynamic` affects staticlibs but it
1477+ // is an independent flag
14681478 } )
14691479 // We also exclude `--target` if it specifies a path to a .json file. The file content
14701480 // is used as hash input below.
@@ -1598,6 +1608,19 @@ where
15981608 }
15991609 }
16001610
1611+ let remove_extra_filename = |p : String | {
1612+ if let Some ( extra) = self . parsed_args . extra_filename . as_ref ( ) {
1613+ if let Some ( ( pre_ext, ext) ) = p. rsplit_once ( "." ) {
1614+ if pre_ext. ends_with ( extra) {
1615+ let pre_extra_filename = & pre_ext[ 0 ..( pre_ext. len ( ) - extra. len ( ) ) ] ;
1616+ return format ! ( "{}.{}" , pre_extra_filename, ext) ;
1617+ }
1618+ }
1619+ }
1620+
1621+ p
1622+ } ;
1623+
16011624 // Convert output files into a map of basename -> full
16021625 // path, and remove some unneeded / non-existing ones,
16031626 // see https://github.com/rust-lang/rust/pull/68799.
@@ -1606,7 +1629,7 @@ where
16061629 . map ( |o| {
16071630 let p = self . parsed_args . output_dir . join ( & o) ;
16081631 (
1609- o ,
1632+ remove_extra_filename ( o ) ,
16101633 ArtifactDescriptor {
16111634 path : p,
16121635 optional : false ,
@@ -1617,7 +1640,7 @@ where
16171640 let dep_info = if let Some ( dep_info) = & self . parsed_args . dep_info {
16181641 let p = self . parsed_args . output_dir . join ( dep_info) ;
16191642 outputs. insert (
1620- dep_info. to_string_lossy ( ) . into_owned ( ) ,
1643+ remove_extra_filename ( dep_info. to_string_lossy ( ) . into_owned ( ) ) ,
16211644 ArtifactDescriptor {
16221645 path : p. clone ( ) ,
16231646 optional : false ,
@@ -1640,7 +1663,7 @@ where
16401663 if let Some ( gcno) = & self . parsed_args . gcno {
16411664 let p = self . parsed_args . output_dir . join ( gcno) ;
16421665 outputs. insert (
1643- gcno. to_string_lossy ( ) . into_owned ( ) ,
1666+ remove_extra_filename ( gcno. to_string_lossy ( ) . into_owned ( ) ) ,
16441667 ArtifactDescriptor {
16451668 path : p,
16461669 optional : true ,
@@ -3472,6 +3495,7 @@ proc_macro false
34723495 rlib : true ,
34733496 staticlib : false ,
34743497 } ,
3498+ extra_filename : None ,
34753499 dep_info : None ,
34763500 emit,
34773501 color_mode : ColorMode :: Auto ,
@@ -3742,7 +3766,11 @@ proc_macro false
37423766 "--crate-type" ,
37433767 "lib" ,
37443768 "-L" ,
3745- "y=y"
3769+ "y=y" ,
3770+ "-C" ,
3771+ "prefer-dynamic" ,
3772+ "-C" ,
3773+ "extra-filename=abcdabcdabcd"
37463774 ] ,
37473775 & [ ] ,
37483776 nothing,
0 commit comments