Skip to content

Commit 9e25570

Browse files
authored
Rollup merge of #36877 - solson:rustc-version-build-issue, r=eddyb
Fix RUSTC_VERSION for 'documenting' build stage. Previously the `env!("RUSTC_VERSION")` requirement would break the "Documenting rustc_metadata" stage of the rustc build, since that environment variable is only defined during the main build. r? @eddyb
2 parents e506bfa + 41832f2 commit 9e25570

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/librustc_metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12881288
let link_meta = self.link_meta;
12891289
let is_rustc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeRustcMacro);
12901290
let root = self.lazy(&CrateRoot {
1291-
rustc_version: RUSTC_VERSION.to_string(),
1291+
rustc_version: rustc_version(),
12921292
name: link_meta.crate_name.clone(),
12931293
triple: tcx.sess.opts.target_triple.clone(),
12941294
hash: link_meta.crate_hash,

src/librustc_metadata/loader.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
//! metadata::loader or metadata::creader for all the juicy details!
214214
215215
use cstore::MetadataBlob;
216-
use schema::{METADATA_HEADER, RUSTC_VERSION};
216+
use schema::{METADATA_HEADER, rustc_version};
217217

218218
use rustc::hir::svh::Svh;
219219
use rustc::session::Session;
@@ -382,7 +382,7 @@ impl<'a> Context<'a> {
382382
}
383383
if !self.rejected_via_version.is_empty() {
384384
err.help(&format!("please recompile that crate using this compiler ({})",
385-
RUSTC_VERSION));
385+
rustc_version()));
386386
let mismatches = self.rejected_via_version.iter();
387387
for (i, &CrateMismatch { ref path, ref got }) in mismatches.enumerate() {
388388
err.note(&format!("crate `{}` path #{}: {} compiled by {:?}",
@@ -597,9 +597,10 @@ impl<'a> Context<'a> {
597597

598598
fn crate_matches(&mut self, metadata: &MetadataBlob, libpath: &Path) -> Option<Svh> {
599599
let root = metadata.get_root();
600-
if root.rustc_version != RUSTC_VERSION {
600+
let rustc_version = rustc_version();
601+
if root.rustc_version != rustc_version {
601602
info!("Rejecting via version: expected {} got {}",
602-
RUSTC_VERSION, root.rustc_version);
603+
rustc_version, root.rustc_version);
603604
self.rejected_via_version.push(CrateMismatch {
604605
path: libpath.to_path_buf(),
605606
got: root.rustc_version

src/librustc_metadata/schema.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ use syntax_pos::{self, Span};
2626

2727
use std::marker::PhantomData;
2828

29-
#[cfg(not(test))]
30-
pub const RUSTC_VERSION: &'static str = concat!("rustc ", env!("CFG_VERSION"));
31-
32-
#[cfg(test)]
33-
pub const RUSTC_VERSION: &'static str = "rustc 0.0.0-unit-test";
29+
pub fn rustc_version() -> String {
30+
format!("rustc {}", option_env!("CFG_VERSION").unwrap_or("unknown version"))
31+
}
3432

3533
/// Metadata encoding version.
3634
/// NB: increment this if you change the format of metadata such that

0 commit comments

Comments
 (0)