Skip to content

Commit 800e63a

Browse files
committed
[RFC 3127 - Trim Paths]: Add unstable option and parsing
1 parent 1f2bacf commit 800e63a

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
@@ -1024,6 +1024,32 @@ impl OutputFilenames {
10241024
}
10251025
}
10261026

1027+
bitflags::bitflags! {
1028+
/// Scopes used to determined if it need to apply to --remap-path-prefix
1029+
pub struct RemapPathScopeComponents: u8 {
1030+
/// Apply remappings to the expansion of std::file!() macro
1031+
const MACRO = 1 << 0;
1032+
/// Apply remappings to printed compiler diagnostics
1033+
const DIAGNOSTICS = 1 << 1;
1034+
/// Apply remappings to debug information only when they are written to
1035+
/// compiled executables or libraries, but not when they are in split
1036+
/// debuginfo files
1037+
const UNSPLIT_DEBUGINFO = 1 << 2;
1038+
/// Apply remappings to debug information only when they are written to
1039+
/// split debug information files, but not in compiled executables or
1040+
/// libraries
1041+
const SPLIT_DEBUGINFO = 1 << 3;
1042+
/// Apply remappings to the paths pointing to split debug information
1043+
/// files. Does nothing when these files are not generated.
1044+
const SPLIT_DEBUGINFO_PATH = 1 << 4;
1045+
1046+
/// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This
1047+
/// ensures all paths in compiled executables or libraries are remapped
1048+
/// but not elsewhere.
1049+
const OBJECT = Self::MACRO.bits | Self::UNSPLIT_DEBUGINFO.bits | Self::SPLIT_DEBUGINFO_PATH.bits;
1050+
}
1051+
}
1052+
10271053
pub fn host_triple() -> &'static str {
10281054
// Get the host triple out of the build environment. This ensures that our
10291055
// idea of the host triple is the same as for the set of libraries we've
@@ -3170,8 +3196,8 @@ pub(crate) mod dep_tracking {
31703196
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, DebugInfoCompression,
31713197
ErrorOutputType, InstrumentCoverage, InstrumentXRay, LdImpl, LinkerPluginLto,
31723198
LocationDetail, LtoCli, OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes,
3173-
Passes, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
3174-
SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
3199+
Passes, RemapPathScopeComponents, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind,
3200+
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
31753201
};
31763202
use crate::lint;
31773203
use crate::options::WasiExecModel;
@@ -3265,6 +3291,7 @@ pub(crate) mod dep_tracking {
32653291
StackProtector,
32663292
SwitchWithOptPath,
32673293
SymbolManglingVersion,
3294+
RemapPathScopeComponents,
32683295
SourceFileHashAlgorithm,
32693296
TrimmedDefPaths,
32703297
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 {
@@ -1075,6 +1076,30 @@ mod parse {
10751076
true
10761077
}
10771078

1079+
pub(crate) fn parse_remap_path_scope(
1080+
slot: &mut RemapPathScopeComponents,
1081+
v: Option<&str>,
1082+
) -> bool {
1083+
if let Some(v) = v {
1084+
*slot = RemapPathScopeComponents::empty();
1085+
for s in v.split(',') {
1086+
*slot |= match s {
1087+
"macro" => RemapPathScopeComponents::MACRO,
1088+
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1089+
"unsplit-debuginfo" => RemapPathScopeComponents::UNSPLIT_DEBUGINFO,
1090+
"split-debuginfo" => RemapPathScopeComponents::SPLIT_DEBUGINFO,
1091+
"split-debuginfo-path" => RemapPathScopeComponents::SPLIT_DEBUGINFO_PATH,
1092+
"object" => RemapPathScopeComponents::OBJECT,
1093+
"all" => RemapPathScopeComponents::all(),
1094+
_ => return false,
1095+
}
1096+
}
1097+
true
1098+
} else {
1099+
false
1100+
}
1101+
}
1102+
10781103
pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
10791104
match v.and_then(|s| RelocModel::from_str(s).ok()) {
10801105
Some(relocation_model) => *slot = Some(relocation_model),
@@ -1720,6 +1745,8 @@ options! {
17201745
"choose which RELRO level to use"),
17211746
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
17221747
"remap paths under the current working directory to this path prefix"),
1748+
remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
1749+
"remap path scope (default: all)"),
17231750
remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
17241751
"directory into which to write optimization remarks (if not specified, they will be \
17251752
written to standard error output)"),

0 commit comments

Comments
 (0)