Skip to content

Commit f288d21

Browse files
committed
[RFC 3127 - Trim Paths]: Add unstable option and parsing
1 parent 9be4eac commit f288d21

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,32 @@ impl OutputFilenames {
996996
}
997997
}
998998

999+
bitflags::bitflags! {
1000+
/// Scopes used to determined if it need to apply to --remap-path-prefix
1001+
pub struct RemapPathScopeComponents: u8 {
1002+
/// Apply remappings to the expansion of std::file!() macro
1003+
const MACRO = 1 << 0;
1004+
/// Apply remappings to printed compiler diagnostics
1005+
const DIAGNOSTICS = 1 << 1;
1006+
/// Apply remappings to debug information only when they are written to
1007+
/// compiled executables or libraries, but not when they are in split
1008+
/// debuginfo files
1009+
const UNSPLIT_DEBUGINFO = 1 << 2;
1010+
/// Apply remappings to debug information only when they are written to
1011+
/// split debug information files, but not in compiled executables or
1012+
/// libraries
1013+
const SPLIT_DEBUGINFO = 1 << 3;
1014+
/// Apply remappings to the paths pointing to split debug information
1015+
/// files. Does nothing when these files are not generated.
1016+
const SPLIT_DEBUGINFO_PATH = 1 << 4;
1017+
1018+
/// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This
1019+
/// ensures all paths in compiled executables or libraries are remapped
1020+
/// but not elsewhere.
1021+
const OBJECT = Self::MACRO.bits | Self::UNSPLIT_DEBUGINFO.bits | Self::SPLIT_DEBUGINFO_PATH.bits;
1022+
}
1023+
}
1024+
9991025
pub fn host_triple() -> &'static str {
10001026
// Get the host triple out of the build environment. This ensures that our
10011027
// idea of the host triple is the same as for the set of libraries we've
@@ -3115,9 +3141,9 @@ pub(crate) mod dep_tracking {
31153141
use super::{
31163142
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType,
31173143
InstrumentCoverage, InstrumentXRay, LdImpl, LinkerPluginLto, LocationDetail, LtoCli,
3118-
OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Passes, ResolveDocLinks,
3119-
SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath, SymbolManglingVersion,
3120-
TraitSolver, TrimmedDefPaths,
3144+
OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Passes,
3145+
RemapPathScopeComponents, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind,
3146+
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
31213147
};
31223148
use crate::lint;
31233149
use crate::options::WasiExecModel;
@@ -3210,6 +3236,7 @@ pub(crate) mod dep_tracking {
32103236
StackProtector,
32113237
SwitchWithOptPath,
32123238
SymbolManglingVersion,
3239+
RemapPathScopeComponents,
32133240
SourceFileHashAlgorithm,
32143241
TrimmedDefPaths,
32153242
Option<LdImpl>,

compiler/rustc_session/src/options.rs

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

425426
mod parse {
@@ -1054,6 +1055,30 @@ mod parse {
10541055
true
10551056
}
10561057

1058+
pub(crate) fn parse_remap_path_scope(
1059+
slot: &mut RemapPathScopeComponents,
1060+
v: Option<&str>,
1061+
) -> bool {
1062+
if let Some(v) = v {
1063+
*slot = RemapPathScopeComponents::empty();
1064+
for s in v.split(',') {
1065+
*slot |= match s {
1066+
"macro" => RemapPathScopeComponents::MACRO,
1067+
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1068+
"unsplit-debuginfo" => RemapPathScopeComponents::UNSPLIT_DEBUGINFO,
1069+
"split-debuginfo" => RemapPathScopeComponents::SPLIT_DEBUGINFO,
1070+
"split-debuginfo-path" => RemapPathScopeComponents::SPLIT_DEBUGINFO_PATH,
1071+
"object" => RemapPathScopeComponents::OBJECT,
1072+
"all" => RemapPathScopeComponents::all(),
1073+
_ => return false,
1074+
}
1075+
}
1076+
true
1077+
} else {
1078+
false
1079+
}
1080+
}
1081+
10571082
pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
10581083
match v.and_then(|s| RelocModel::from_str(s).ok()) {
10591084
Some(relocation_model) => *slot = Some(relocation_model),
@@ -1706,6 +1731,8 @@ options! {
17061731
"choose which RELRO level to use"),
17071732
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
17081733
"remap paths under the current working directory to this path prefix"),
1734+
remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
1735+
"remap path scope (default: all)"),
17091736
remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
17101737
"directory into which to write optimization remarks (if not specified, they will be \
17111738
written to standard error output)"),

0 commit comments

Comments
 (0)