Rollup merge of #142377 - Urgau:unremap-rustc-dev, r=jieyouxu
Try unremapping compiler sources See [#t-compiler/help > Span pointing to wrong file location (`rustc-dev` component)](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Span.20pointing.20to.20wrong.20file.20location.20.28.60rustc-dev.60.20component.29/with/521087083). This PR is a follow-up to rust-lang/rust#141751 regarding the compiler side. Specifically we now take into account the `CFG_VIRTUAL_RUSTC_DEV_SOURCE_BASE_DIR` env from rust-lang/rust#141751 when trying to unremap sources from `$sysroot/lib/rustlib/rustc-src/rust` (the `rustc-dev` component install directory). Best reviewed commit by commit. cc ``@samueltardieu`` r? ``@jieyouxu``
This commit is contained in:
@@ -1364,6 +1364,7 @@ impl Default for Options {
|
||||
cli_forced_local_thinlto_off: false,
|
||||
remap_path_prefix: Vec::new(),
|
||||
real_rust_source_base_dir: None,
|
||||
real_rustc_dev_source_base_dir: None,
|
||||
edition: DEFAULT_EDITION,
|
||||
json_artifact_notifications: false,
|
||||
json_timings: false,
|
||||
@@ -2713,9 +2714,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
||||
|
||||
let sysroot = filesearch::materialize_sysroot(sysroot_opt);
|
||||
|
||||
let real_rust_source_base_dir = {
|
||||
// This is the location used by the `rust-src` `rustup` component.
|
||||
let mut candidate = sysroot.join("lib/rustlib/src/rust");
|
||||
let real_source_base_dir = |suffix: &str, confirm: &str| {
|
||||
let mut candidate = sysroot.join(suffix);
|
||||
if let Ok(metadata) = candidate.symlink_metadata() {
|
||||
// Replace the symlink bootstrap creates, with its destination.
|
||||
// We could try to use `fs::canonicalize` instead, but that might
|
||||
@@ -2728,9 +2728,17 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
||||
}
|
||||
|
||||
// Only use this directory if it has a file we can expect to always find.
|
||||
candidate.join("library/std/src/lib.rs").is_file().then_some(candidate)
|
||||
candidate.join(confirm).is_file().then_some(candidate)
|
||||
};
|
||||
|
||||
let real_rust_source_base_dir =
|
||||
// This is the location used by the `rust-src` `rustup` component.
|
||||
real_source_base_dir("lib/rustlib/src/rust", "library/std/src/lib.rs");
|
||||
|
||||
let real_rustc_dev_source_base_dir =
|
||||
// This is the location used by the `rustc-dev` `rustup` component.
|
||||
real_source_base_dir("lib/rustlib/rustc-src/rust", "compiler/rustc/src/main.rs");
|
||||
|
||||
let mut search_paths = vec![];
|
||||
for s in &matches.opt_strs("L") {
|
||||
search_paths.push(SearchPath::from_cli_opt(
|
||||
@@ -2784,6 +2792,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
||||
cli_forced_local_thinlto_off: disable_local_thinlto,
|
||||
remap_path_prefix,
|
||||
real_rust_source_base_dir,
|
||||
real_rustc_dev_source_base_dir,
|
||||
edition,
|
||||
json_artifact_notifications,
|
||||
json_timings,
|
||||
|
||||
@@ -395,15 +395,25 @@ top_level_options!(
|
||||
|
||||
/// Remap source path prefixes in all output (messages, object files, debug, etc.).
|
||||
remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
|
||||
/// Base directory containing the `src/` for the Rust standard library, and
|
||||
/// potentially `rustc` as well, if we can find it. Right now it's always
|
||||
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
|
||||
|
||||
/// Base directory containing the `library/` directory for the Rust standard library.
|
||||
/// Right now it's always `$sysroot/lib/rustlib/src/rust`
|
||||
/// (i.e. the `rustup` `rust-src` component).
|
||||
///
|
||||
/// This directory is what the virtual `/rustc/$hash` is translated back to,
|
||||
/// if Rust was built with path remapping to `/rustc/$hash` enabled
|
||||
/// (the `rust.remap-debuginfo` option in `bootstrap.toml`).
|
||||
real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
|
||||
|
||||
/// Base directory containing the `compiler/` directory for the rustc sources.
|
||||
/// Right now it's always `$sysroot/lib/rustlib/rustc-src/rust`
|
||||
/// (i.e. the `rustup` `rustc-dev` component).
|
||||
///
|
||||
/// This directory is what the virtual `/rustc-dev/$hash` is translated back to,
|
||||
/// if Rust was built with path remapping to `/rustc/$hash` enabled
|
||||
/// (the `rust.remap-debuginfo` option in `bootstrap.toml`).
|
||||
real_rustc_dev_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
|
||||
|
||||
edition: Edition [TRACKED],
|
||||
|
||||
/// `true` if we're emitting JSON blobs about each artifact produced
|
||||
|
||||
Reference in New Issue
Block a user