Skip to content

Commit 39648ea

Browse files
committed
Make real_rust_path_dir a TRACKED_NO_CRATE_HASH option
This also adds support for doc-comments to Options.
1 parent 2720151 commit 39648ea

File tree

5 files changed

+52
-36
lines changed

5 files changed

+52
-36
lines changed

compiler/rustc_interface/src/tests.rs

+4
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ fn test_top_level_options_tracked_no_crate() {
459459
// Make sure that changing a [TRACKED_NO_CRATE_HASH] option leaves the crate hash unchanged but changes the incremental hash.
460460
// This list is in alphabetical order.
461461
tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]);
462+
tracked!(
463+
real_rust_source_base_dir,
464+
Some("/home/bors/rust/.rustup/toolchains/nightly/lib/rustlib/src/rust".into())
465+
);
462466
}
463467

464468
#[test]

compiler/rustc_metadata/src/rmeta/decoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16171617
.map(Path::new)
16181618
.filter(|_| {
16191619
// Only spend time on further checks if we have what to translate *to*.
1620-
sess.real_rust_source_base_dir.is_some()
1620+
sess.opts.real_rust_source_base_dir.is_some()
16211621
})
16221622
.filter(|virtual_dir| {
16231623
// Don't translate away `/rustc/$hash` if we're still remapping to it,
@@ -1629,11 +1629,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
16291629
debug!(
16301630
"try_to_translate_virtual_to_real(name={:?}): \
16311631
virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}",
1632-
name, virtual_rust_source_base_dir, sess.real_rust_source_base_dir,
1632+
name, virtual_rust_source_base_dir, sess.opts.real_rust_source_base_dir,
16331633
);
16341634

16351635
if let Some(virtual_dir) = virtual_rust_source_base_dir {
1636-
if let Some(real_dir) = &sess.real_rust_source_base_dir {
1636+
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
16371637
if let rustc_span::FileName::Real(old_name) = name {
16381638
if let rustc_span::RealFileName::Named(one_path) = old_name {
16391639
if let Ok(rest) = one_path.strip_prefix(virtual_dir) {

compiler/rustc_session/src/config.rs

+30
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ impl Default for Options {
702702
cli_forced_codegen_units: None,
703703
cli_forced_thinlto_off: false,
704704
remap_path_prefix: Vec::new(),
705+
real_rust_source_base_dir: None,
705706
edition: DEFAULT_EDITION,
706707
json_artifact_notifications: false,
707708
json_unused_externs: false,
@@ -1980,6 +1981,34 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
19801981
}
19811982
}
19821983

1984+
// Try to find a directory containing the Rust `src`, for more details see
1985+
// the doc comment on the `real_rust_source_base_dir` field.
1986+
let tmp_buf;
1987+
let sysroot = match &sysroot_opt {
1988+
Some(s) => s,
1989+
None => {
1990+
tmp_buf = crate::filesearch::get_or_default_sysroot();
1991+
&tmp_buf
1992+
}
1993+
};
1994+
let real_rust_source_base_dir = {
1995+
// This is the location used by the `rust-src` `rustup` component.
1996+
let mut candidate = sysroot.join("lib/rustlib/src/rust");
1997+
if let Ok(metadata) = candidate.symlink_metadata() {
1998+
// Replace the symlink rustbuild creates, with its destination.
1999+
// We could try to use `fs::canonicalize` instead, but that might
2000+
// produce unnecessarily verbose path.
2001+
if metadata.file_type().is_symlink() {
2002+
if let Ok(symlink_dest) = std::fs::read_link(&candidate) {
2003+
candidate = symlink_dest;
2004+
}
2005+
}
2006+
}
2007+
2008+
// Only use this directory if it has a file we can expect to always find.
2009+
if candidate.join("library/std/src/lib.rs").is_file() { Some(candidate) } else { None }
2010+
};
2011+
19832012
Options {
19842013
crate_types,
19852014
optimize: opt_level,
@@ -2010,6 +2039,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
20102039
cli_forced_codegen_units: codegen_units,
20112040
cli_forced_thinlto_off: disable_thinlto,
20122041
remap_path_prefix,
2042+
real_rust_source_base_dir,
20132043
edition,
20142044
json_artifact_notifications,
20152045
json_unused_externs,

compiler/rustc_session/src/options.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ macro_rules! hash_substruct {
5454

5555
macro_rules! top_level_options {
5656
(pub struct Options { $(
57+
$( #[$attr:meta] )*
5758
$opt:ident : $t:ty [$dep_tracking_marker:ident],
5859
)* } ) => (
5960
#[derive(Clone)]
6061
pub struct Options {
61-
$(pub $opt: $t),*
62+
$(
63+
$( #[$attr] )*
64+
pub $opt: $t
65+
),*
6266
}
6367

6468
impl Options {
@@ -174,6 +178,14 @@ top_level_options!(
174178

175179
// Remap source path prefixes in all output (messages, object files, debug, etc.).
176180
remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
181+
/// Base directory containing the `src/` for the Rust standard library, and
182+
/// potentially `rustc` as well, if we can can find it. Right now it's always
183+
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
184+
///
185+
/// This directory is what the virtual `/rustc/$hash` is translated back to,
186+
/// if Rust was built with path remapping to `/rustc/$hash` enabled
187+
/// (the `rust.remap-debuginfo` option in `config.toml`).
188+
real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
177189

178190
edition: Edition [TRACKED],
179191

@@ -254,13 +266,13 @@ macro_rules! options {
254266
}
255267

256268
impl $struct_name {
257-
fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
269+
fn dep_tracking_hash(&self, _for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
258270
let mut sub_hashes = BTreeMap::new();
259271
$({
260272
hash_opt!($opt,
261273
&self.$opt,
262274
&mut sub_hashes,
263-
for_crate_hash,
275+
_for_crate_hash,
264276
[$dep_tracking_marker]);
265277
})*
266278
let mut hasher = DefaultHasher::new();

compiler/rustc_session/src/session.rs

-30
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,6 @@ pub struct Session {
214214
/// drown everything else in noise.
215215
miri_unleashed_features: Lock<Vec<(Span, Option<Symbol>)>>,
216216

217-
/// Base directory containing the `src/` for the Rust standard library, and
218-
/// potentially `rustc` as well, if we can can find it. Right now it's always
219-
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
220-
///
221-
/// This directory is what the virtual `/rustc/$hash` is translated back to,
222-
/// if Rust was built with path remapping to `/rustc/$hash` enabled
223-
/// (the `rust.remap-debuginfo` option in `config.toml`).
224-
pub real_rust_source_base_dir: Option<PathBuf>,
225-
226217
/// Architecture to use for interpreting asm!.
227218
pub asm_arch: Option<InlineAsmArch>,
228219

@@ -1390,26 +1381,6 @@ pub fn build_session(
13901381
_ => CtfeBacktrace::Disabled,
13911382
});
13921383

1393-
// Try to find a directory containing the Rust `src`, for more details see
1394-
// the doc comment on the `real_rust_source_base_dir` field.
1395-
let real_rust_source_base_dir = {
1396-
// This is the location used by the `rust-src` `rustup` component.
1397-
let mut candidate = sysroot.join("lib/rustlib/src/rust");
1398-
if let Ok(metadata) = candidate.symlink_metadata() {
1399-
// Replace the symlink rustbuild creates, with its destination.
1400-
// We could try to use `fs::canonicalize` instead, but that might
1401-
// produce unnecessarily verbose path.
1402-
if metadata.file_type().is_symlink() {
1403-
if let Ok(symlink_dest) = std::fs::read_link(&candidate) {
1404-
candidate = symlink_dest;
1405-
}
1406-
}
1407-
}
1408-
1409-
// Only use this directory if it has a file we can expect to always find.
1410-
if candidate.join("library/std/src/lib.rs").is_file() { Some(candidate) } else { None }
1411-
};
1412-
14131384
let asm_arch =
14141385
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };
14151386

@@ -1453,7 +1424,6 @@ pub fn build_session(
14531424
system_library_path: OneThread::new(RefCell::new(Default::default())),
14541425
ctfe_backtrace,
14551426
miri_unleashed_features: Lock::new(Default::default()),
1456-
real_rust_source_base_dir,
14571427
asm_arch,
14581428
target_features: FxHashSet::default(),
14591429
known_attrs: Lock::new(MarkedAttrs::new()),

0 commit comments

Comments
 (0)