From d5f2b8e5c65b0406254b990296793f664c1926a0 Mon Sep 17 00:00:00 2001 From: jyn Date: Mon, 8 May 2023 04:12:38 -0500 Subject: Only depend on CFG_VERSION in rustc_interface this avoids having to rebuild the whole compiler on each commit when `omit-git-hash = false`. --- compiler/rustc_metadata/src/locator.rs | 6 ++++-- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'compiler/rustc_metadata/src') diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index c6af8d63289..deafd8df44d 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -246,6 +246,7 @@ pub(crate) struct CrateLocator<'a> { only_needs_metadata: bool, sysroot: &'a Path, metadata_loader: &'a dyn MetadataLoader, + cfg_version: &'static str, // Immutable per-search configuration. crate_name: Symbol, @@ -323,6 +324,7 @@ impl<'a> CrateLocator<'a> { only_needs_metadata, sysroot: &sess.sysroot, metadata_loader, + cfg_version: sess.cfg_version, crate_name, exact_paths: if hash.is_none() { sess.opts @@ -655,7 +657,7 @@ impl<'a> CrateLocator<'a> { } fn crate_matches(&mut self, metadata: &MetadataBlob, libpath: &Path) -> Option { - let rustc_version = rustc_version(); + let rustc_version = rustc_version(self.cfg_version); let found_version = metadata.get_rustc_version(); if found_version != rustc_version { info!("Rejecting via version: expected {} got {}", rustc_version, found_version); @@ -1097,7 +1099,7 @@ impl CrateError { crate_name, add_info, found_crates, - rustc_version: rustc_version(), + rustc_version: rustc_version(sess.cfg_version), }); } else if !locator.crate_rejections.via_invalid.is_empty() { let mut crate_rejections = Vec::new(); diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 82c66b9dfb9..d6c26c082fa 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2267,7 +2267,7 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) { }; // Encode the rustc version string in a predictable location. - rustc_version().encode(&mut ecx); + rustc_version(tcx.sess.cfg_version).encode(&mut ecx); // Encode all the entries and extra information in the crate, // culminating in the `CrateRoot` which points to all of it. diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 84f6b7f934d..eef23b93e86 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -48,8 +48,8 @@ mod def_path_hash_map; mod encoder; mod table; -pub(crate) fn rustc_version() -> String { - format!("rustc {}", option_env!("CFG_VERSION").unwrap_or("unknown version")) +pub(crate) fn rustc_version(cfg_version: &'static str) -> String { + format!("rustc {}", cfg_version) } /// Metadata encoding version. -- cgit 1.4.1-3-g733a5