Skip to content

Commit d2d6e67

Browse files
committed
Auto merge of #4239 - Keruspe:master, r=alexcrichton
hash '__CARGO_DEFAULT_LIB_METADATA' in metadata for rustc We already have __CARGO_DEFAULT_LIB_METADATA to force adding the hash of some metadata in the libraries file name when building rust. For now, we only check if it is set or not. This patch makes also use of its value to compute the hash. This way we'll be able to pass in the channel we're building to avoid hash collisions between channels.
2 parents 1ee4edb + dc8d5d3 commit d2d6e67

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,17 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
442442
// Note, though, that the compiler's build system at least wants
443443
// path dependencies (eg libstd) to have hashes in filenames. To account for
444444
// that we have an extra hack here which reads the
445-
// `__CARGO_DEFAULT_METADATA` environment variable and creates a
445+
// `__CARGO_DEFAULT_LIB_METADATA` environment variable and creates a
446446
// hash in the filename if that's present.
447447
//
448448
// This environment variable should not be relied on! It's
449449
// just here for rustbuild. We need a more principled method
450450
// doing this eventually.
451+
let __cargo_default_lib_metadata = env::var("__CARGO_DEFAULT_LIB_METADATA");
451452
if !unit.profile.test &&
452453
(unit.target.is_dylib() || unit.target.is_cdylib()) &&
453454
unit.pkg.package_id().source_id().is_path() &&
454-
!env::var("__CARGO_DEFAULT_LIB_METADATA").is_ok() {
455+
!__cargo_default_lib_metadata.is_ok() {
455456
return None;
456457
}
457458

@@ -491,6 +492,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
491492
rustc.verbose_version.hash(&mut hasher);
492493
}
493494

495+
// Seed the contents of __CARGO_DEFAULT_LIB_METADATA to the hasher if present.
496+
// This should be the release channel, to get a different hash for each channel.
497+
if let Ok(ref channel) = __cargo_default_lib_metadata {
498+
channel.hash(&mut hasher);
499+
}
500+
494501
Some(Metadata(hasher.finish()))
495502
}
496503

tests/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ suffix = env::consts::DLL_SUFFIX,
859859
assert_that(p.cargo("clean"), execs().with_status(0));
860860

861861
// If you set the env-var, then we expect metadata on libbar
862-
assert_that(p.cargo("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "1"),
862+
assert_that(p.cargo("build").arg("-v").env("__CARGO_DEFAULT_LIB_METADATA", "stable"),
863863
execs().with_status(0).with_stderr(&format!("\
864864
[COMPILING] bar v0.0.1 ({url}/bar)
865865
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type dylib \

0 commit comments

Comments
 (0)