[RFC 3127 - Trim Paths]: Add unstable option and parsing

This commit is contained in:
Urgau 2023-08-23 11:18:20 +02:00
parent 631a116cd3
commit 30f94717ca
4 changed files with 58 additions and 2 deletions

View File

@ -4456,6 +4456,7 @@ dependencies = [
name = "rustc_session"
version = "0.0.0"
dependencies = [
"bitflags 1.3.2",
"getopts",
"libc",
"rustc_ast",

View File

@ -4,6 +4,7 @@ version = "0.0.0"
edition = "2021"
[dependencies]
bitflags = "1.2.1"
getopts = "0.2"
rustc_macros = { path = "../rustc_macros" }
tracing = "0.1"

View File

@ -1018,6 +1018,32 @@ impl OutputFilenames {
}
}
bitflags::bitflags! {
/// Scopes used to determined if it need to apply to --remap-path-prefix
pub struct RemapPathScopeComponents: u8 {
/// Apply remappings to the expansion of std::file!() macro
const MACRO = 1 << 0;
/// Apply remappings to printed compiler diagnostics
const DIAGNOSTICS = 1 << 1;
/// Apply remappings to debug information only when they are written to
/// compiled executables or libraries, but not when they are in split
/// debuginfo files
const UNSPLIT_DEBUGINFO = 1 << 2;
/// Apply remappings to debug information only when they are written to
/// split debug information files, but not in compiled executables or
/// libraries
const SPLIT_DEBUGINFO = 1 << 3;
/// Apply remappings to the paths pointing to split debug information
/// files. Does nothing when these files are not generated.
const SPLIT_DEBUGINFO_PATH = 1 << 4;
/// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This
/// ensures all paths in compiled executables or libraries are remapped
/// but not elsewhere.
const OBJECT = Self::MACRO.bits | Self::UNSPLIT_DEBUGINFO.bits | Self::SPLIT_DEBUGINFO_PATH.bits;
}
}
pub fn host_triple() -> &'static str {
// Get the host triple out of the build environment. This ensures that our
// idea of the host triple is the same as for the set of libraries we've
@ -3173,8 +3199,8 @@ pub(crate) mod dep_tracking {
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, DebugInfoCompression,
ErrorOutputType, InstrumentCoverage, InstrumentXRay, LinkerPluginLto, LocationDetail,
LtoCli, OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Polonius,
ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
RemapPathScopeComponents, ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind,
SwitchWithOptPath, SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
};
use crate::lint;
use crate::options::WasiExecModel;
@ -3268,6 +3294,7 @@ pub(crate) mod dep_tracking {
StackProtector,
SwitchWithOptPath,
SymbolManglingVersion,
RemapPathScopeComponents,
SourceFileHashAlgorithm,
TrimmedDefPaths,
OutFileName,

View File

@ -427,6 +427,7 @@ mod desc {
pub const parse_proc_macro_execution_strategy: &str =
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
pub const parse_dump_solver_proof_tree: &str = "one of: `always`, `on-request`, `on-error`";
pub const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `unsplit-debuginfo`, `split-debuginfo`, `split-debuginfo-path`, `object`, `all`";
}
mod parse {
@ -1095,6 +1096,30 @@ mod parse {
true
}
pub(crate) fn parse_remap_path_scope(
slot: &mut RemapPathScopeComponents,
v: Option<&str>,
) -> bool {
if let Some(v) = v {
*slot = RemapPathScopeComponents::empty();
for s in v.split(',') {
*slot |= match s {
"macro" => RemapPathScopeComponents::MACRO,
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
"unsplit-debuginfo" => RemapPathScopeComponents::UNSPLIT_DEBUGINFO,
"split-debuginfo" => RemapPathScopeComponents::SPLIT_DEBUGINFO,
"split-debuginfo-path" => RemapPathScopeComponents::SPLIT_DEBUGINFO_PATH,
"object" => RemapPathScopeComponents::OBJECT,
"all" => RemapPathScopeComponents::all(),
_ => return false,
}
}
true
} else {
false
}
}
pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
match v.and_then(|s| RelocModel::from_str(s).ok()) {
Some(relocation_model) => *slot = Some(relocation_model),
@ -1731,6 +1756,8 @@ options! {
"choose which RELRO level to use"),
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
"remap paths under the current working directory to this path prefix"),
remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
"remap path scope (default: all)"),
remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
"directory into which to write optimization remarks (if not specified, they will be \
written to standard error output)"),