@@ -93,6 +93,7 @@ use crate::core::{Feature, PackageId, Target, Verbosity};
93
93
use crate :: util:: errors:: { CargoResult , VerboseError } ;
94
94
use crate :: util:: interning:: InternedString ;
95
95
use crate :: util:: machine_message:: { self , Message } ;
96
+ use crate :: util:: toml:: ProfileTrimPaths ;
96
97
use crate :: util:: toml:: TomlDebugInfo ;
97
98
use crate :: util:: { add_path_args, internal, iter_join_onto, profile} ;
98
99
use cargo_util:: { paths, ProcessBuilder , ProcessError } ;
@@ -954,6 +955,7 @@ fn build_base_args(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, unit: &Unit)
954
955
incremental,
955
956
strip,
956
957
rustflags : profile_rustflags,
958
+ trim_paths,
957
959
..
958
960
} = unit. profile . clone ( ) ;
959
961
let test = unit. mode . is_any_test ( ) ;
@@ -1032,6 +1034,10 @@ fn build_base_args(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, unit: &Unit)
1032
1034
}
1033
1035
}
1034
1036
1037
+ if !trim_paths. is_empty ( ) {
1038
+ trim_paths_args ( cmd, cx, unit, & trim_paths) ?;
1039
+ }
1040
+
1035
1041
cmd. args ( unit. pkg . manifest ( ) . lint_rustflags ( ) ) ;
1036
1042
cmd. args ( & profile_rustflags) ;
1037
1043
if let Some ( args) = cx. bcx . extra_args_for ( unit) {
@@ -1166,6 +1172,63 @@ fn features_args(unit: &Unit) -> Vec<OsString> {
1166
1172
args
1167
1173
}
1168
1174
1175
+ /// Generates the `--remap-path-scope` and `--remap-path-prefix` for [RFC 3127].
1176
+ /// See also unstable feature [`-Ztrim-paths`].
1177
+ ///
1178
+ /// [RFC 3127]: https://rust-lang.github.io/rfcs/3127-trim-paths.html
1179
+ /// [`-Ztrim-paths`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#profile-trim-paths-option
1180
+ fn trim_paths_args (
1181
+ cmd : & mut ProcessBuilder ,
1182
+ cx : & Context < ' _ , ' _ > ,
1183
+ unit : & Unit ,
1184
+ scopes : & [ ProfileTrimPaths ] ,
1185
+ ) -> CargoResult < ( ) > {
1186
+ if scopes. iter ( ) . any ( |s| matches ! ( s, ProfileTrimPaths :: None ) ) {
1187
+ return Ok ( ( ) ) ;
1188
+ }
1189
+
1190
+ // feature gate was checked during mainfest/config parsing.
1191
+ cmd. arg ( "-Zunstable-options" ) ;
1192
+
1193
+ let mut remap_path_scope = String :: from ( "-Zremap-path-scope=" ) ;
1194
+ for scope in scopes. iter ( ) {
1195
+ remap_path_scope. push_str ( scope. as_str ( ) ) ;
1196
+ remap_path_scope. push ( ',' ) ;
1197
+ }
1198
+ cmd. arg ( remap_path_scope. trim_end_matches ( ',' ) ) ;
1199
+
1200
+ let sysroot_remap = {
1201
+ let sysroot = & cx. bcx . target_data . info ( unit. kind ) . sysroot_target_libdir ;
1202
+ let commit_hash = & cx. bcx . rustc ( ) . commit_hash ;
1203
+ let mut remap = OsString :: from ( "--remap-path-prefix=" ) ;
1204
+ remap. push ( sysroot) ;
1205
+ remap. push ( "=" ) ;
1206
+ remap. push ( "/rustc/" ) ;
1207
+ remap. push ( commit_hash) ;
1208
+ remap
1209
+ } ;
1210
+ cmd. arg ( sysroot_remap) ;
1211
+
1212
+ let package_remap = {
1213
+ let pkg_root = unit. pkg . root ( ) ;
1214
+ let ws_root = cx. bcx . ws . root ( ) ;
1215
+ let mut remap = OsString :: from ( "--remap-path-prefix=" ) ;
1216
+ remap. push ( pkg_root) ;
1217
+ remap. push ( "=" ) ;
1218
+ if pkg_root. starts_with ( ws_root) {
1219
+ // empty to remap to relative paths.
1220
+ } else {
1221
+ remap. push ( unit. pkg . name ( ) ) ;
1222
+ remap. push ( "-" ) ;
1223
+ remap. push ( unit. pkg . version ( ) . to_string ( ) ) ;
1224
+ }
1225
+ remap
1226
+ } ;
1227
+ cmd. arg ( package_remap) ;
1228
+
1229
+ Ok ( ( ) )
1230
+ }
1231
+
1169
1232
/// Generates the `--check-cfg` arguments for the `unit`.
1170
1233
/// See unstable feature [`check-cfg`].
1171
1234
///
0 commit comments