Skip to content

Commit ed7c051

Browse files
committed
[RFC 3127 - Trim Paths]: Add unstable option and parsing
1 parent 19149d1 commit ed7c051

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,6 +4479,7 @@ dependencies = [
44794479
name = "rustc_session"
44804480
version = "0.0.0"
44814481
dependencies = [
4482+
"bitflags 1.3.2",
44824483
"getopts",
44834484
"libc",
44844485
"rustc_ast",

compiler/rustc_session/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7+
bitflags = "1.2.1"
78
getopts = "0.2"
89
rustc_macros = { path = "../rustc_macros" }
910
tracing = "0.1"

compiler/rustc_session/src/config.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,32 @@ impl OutputFilenames {
10181018
}
10191019
}
10201020

1021+
bitflags::bitflags! {
1022+
/// Scopes used to determined if it need to apply to --remap-path-prefix
1023+
pub struct RemapPathScopeComponents: u8 {
1024+
/// Apply remappings to the expansion of std::file!() macro
1025+
const MACRO = 1 << 0;
1026+
/// Apply remappings to printed compiler diagnostics
1027+
const DIAGNOSTICS = 1 << 1;
1028+
/// Apply remappings to debug information only when they are written to
1029+
/// compiled executables or libraries, but not when they are in split
1030+
/// debuginfo files
1031+
const UNSPLIT_DEBUGINFO = 1 << 2;
1032+
/// Apply remappings to debug information only when they are written to
1033+
/// split debug information files, but not in compiled executables or
1034+
/// libraries
1035+
const SPLIT_DEBUGINFO = 1 << 3;
1036+
/// Apply remappings to the paths pointing to split debug information
1037+
/// files. Does nothing when these files are not generated.
1038+
const SPLIT_DEBUGINFO_PATH = 1 << 4;
1039+
1040+
/// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This
1041+
/// ensures all paths in compiled executables or libraries are remapped
1042+
/// but not elsewhere.
1043+
const OBJECT = Self::MACRO.bits | Self::UNSPLIT_DEBUGINFO.bits | Self::SPLIT_DEBUGINFO_PATH.bits;
1044+
}
1045+
}
1046+
10211047
pub fn host_triple() -> &'static str {
10221048
// Get the host triple out of the build environment. This ensures that our
10231049
// idea of the host triple is the same as for the set of libraries we've
@@ -3177,8 +3203,8 @@ pub(crate) mod dep_tracking {
31773203
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, DebugInfoCompression,
31783204
ErrorOutputType, InstrumentCoverage, InstrumentXRay, LinkerPluginLto, LocationDetail,
31793205
LtoCli, OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Passes,
3180-
ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
3181-
SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
3206+
RemapPathScopeComponents, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind,
3207+
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
31823208
};
31833209
use crate::lint;
31843210
use crate::options::WasiExecModel;
@@ -3272,6 +3298,7 @@ pub(crate) mod dep_tracking {
32723298
StackProtector,
32733299
SwitchWithOptPath,
32743300
SymbolManglingVersion,
3301+
RemapPathScopeComponents,
32753302
SourceFileHashAlgorithm,
32763303
TrimmedDefPaths,
32773304
OutFileName,

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 {
@@ -1090,6 +1091,30 @@ mod parse {
10901091
true
10911092
}
10921093

1094+
pub(crate) fn parse_remap_path_scope(
1095+
slot: &mut RemapPathScopeComponents,
1096+
v: Option<&str>,
1097+
) -> bool {
1098+
if let Some(v) = v {
1099+
*slot = RemapPathScopeComponents::empty();
1100+
for s in v.split(',') {
1101+
*slot |= match s {
1102+
"macro" => RemapPathScopeComponents::MACRO,
1103+
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1104+
"unsplit-debuginfo" => RemapPathScopeComponents::UNSPLIT_DEBUGINFO,
1105+
"split-debuginfo" => RemapPathScopeComponents::SPLIT_DEBUGINFO,
1106+
"split-debuginfo-path" => RemapPathScopeComponents::SPLIT_DEBUGINFO_PATH,
1107+
"object" => RemapPathScopeComponents::OBJECT,
1108+
"all" => RemapPathScopeComponents::all(),
1109+
_ => return false,
1110+
}
1111+
}
1112+
true
1113+
} else {
1114+
false
1115+
}
1116+
}
1117+
10931118
pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
10941119
match v.and_then(|s| RelocModel::from_str(s).ok()) {
10951120
Some(relocation_model) => *slot = Some(relocation_model),
@@ -1726,6 +1751,8 @@ options! {
17261751
"choose which RELRO level to use"),
17271752
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
17281753
"remap paths under the current working directory to this path prefix"),
1754+
remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
1755+
"remap path scope (default: all)"),
17291756
remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
17301757
"directory into which to write optimization remarks (if not specified, they will be \
17311758
written to standard error output)"),

0 commit comments

Comments
 (0)