Skip to content

Commit eca3241

Browse files
committed
[RFC 3127 - Trim Paths]: Add unstable option and parsing
1 parent 5ede940 commit eca3241

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,32 @@ impl OutputFilenames {
10141014
}
10151015
}
10161016

1017+
bitflags::bitflags! {
1018+
/// Scopes used to determined if it need to apply to --remap-path-prefix
1019+
pub struct RemapPathScopeComponents: u8 {
1020+
/// Apply remappings to the expansion of std::file!() macro
1021+
const MACRO = 1 << 0;
1022+
/// Apply remappings to printed compiler diagnostics
1023+
const DIAGNOSTICS = 1 << 1;
1024+
/// Apply remappings to debug information only when they are written to
1025+
/// compiled executables or libraries, but not when they are in split
1026+
/// debuginfo files
1027+
const UNSPLIT_DEBUGINFO = 1 << 2;
1028+
/// Apply remappings to debug information only when they are written to
1029+
/// split debug information files, but not in compiled executables or
1030+
/// libraries
1031+
const SPLIT_DEBUGINFO = 1 << 3;
1032+
/// Apply remappings to the paths pointing to split debug information
1033+
/// files. Does nothing when these files are not generated.
1034+
const SPLIT_DEBUGINFO_PATH = 1 << 4;
1035+
1036+
/// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This
1037+
/// ensures all paths in compiled executables or libraries are remapped
1038+
/// but not elsewhere.
1039+
const OBJECT = Self::MACRO.bits | Self::UNSPLIT_DEBUGINFO.bits | Self::SPLIT_DEBUGINFO_PATH.bits;
1040+
}
1041+
}
1042+
10171043
pub fn host_triple() -> &'static str {
10181044
// Get the host triple out of the build environment. This ensures that our
10191045
// idea of the host triple is the same as for the set of libraries we've
@@ -3145,8 +3171,8 @@ pub(crate) mod dep_tracking {
31453171
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, DebugInfoCompression,
31463172
ErrorOutputType, InstrumentCoverage, InstrumentXRay, LdImpl, LinkerPluginLto,
31473173
LocationDetail, LtoCli, OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes,
3148-
Passes, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
3149-
SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
3174+
Passes, RemapPathScopeComponents, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind,
3175+
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
31503176
};
31513177
use crate::lint;
31523178
use crate::options::WasiExecModel;
@@ -3240,6 +3266,7 @@ pub(crate) mod dep_tracking {
32403266
StackProtector,
32413267
SwitchWithOptPath,
32423268
SymbolManglingVersion,
3269+
RemapPathScopeComponents,
32433270
SourceFileHashAlgorithm,
32443271
TrimmedDefPaths,
32453272
Option<LdImpl>,

compiler/rustc_session/src/options.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ mod desc {
422422
pub const parse_proc_macro_execution_strategy: &str =
423423
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
424424
pub const parse_dump_solver_proof_tree: &str = "one of: `always`, `on-request`, `on-error`";
425+
pub const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `unsplit-debuginfo`, `split-debuginfo`, `split-debuginfo-path`, `object`, `all`";
425426
}
426427

427428
mod parse {
@@ -1069,6 +1070,30 @@ mod parse {
10691070
true
10701071
}
10711072

1073+
pub(crate) fn parse_remap_path_scope(
1074+
slot: &mut RemapPathScopeComponents,
1075+
v: Option<&str>,
1076+
) -> bool {
1077+
if let Some(v) = v {
1078+
*slot = RemapPathScopeComponents::empty();
1079+
for s in v.split(',') {
1080+
*slot |= match s {
1081+
"macro" => RemapPathScopeComponents::MACRO,
1082+
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1083+
"unsplit-debuginfo" => RemapPathScopeComponents::UNSPLIT_DEBUGINFO,
1084+
"split-debuginfo" => RemapPathScopeComponents::SPLIT_DEBUGINFO,
1085+
"split-debuginfo-path" => RemapPathScopeComponents::SPLIT_DEBUGINFO_PATH,
1086+
"object" => RemapPathScopeComponents::OBJECT,
1087+
"all" => RemapPathScopeComponents::all(),
1088+
_ => return false,
1089+
}
1090+
}
1091+
true
1092+
} else {
1093+
false
1094+
}
1095+
}
1096+
10721097
pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
10731098
match v.and_then(|s| RelocModel::from_str(s).ok()) {
10741099
Some(relocation_model) => *slot = Some(relocation_model),
@@ -1723,6 +1748,8 @@ options! {
17231748
"choose which RELRO level to use"),
17241749
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
17251750
"remap paths under the current working directory to this path prefix"),
1751+
remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
1752+
"remap path scope (default: all)"),
17261753
remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
17271754
"directory into which to write optimization remarks (if not specified, they will be \
17281755
written to standard error output)"),

0 commit comments

Comments
 (0)