Skip to content

Commit 109cb7c

Browse files
authored
Auto merge of #3022 - alexcrichton:add-more-metadata, r=brson
Add a temporary env var to enable hashes in filenames For rustbuild we need the hashes to exist for all deps, even if they're path deps, because we care about the actual file names. For example we don't want to install /usr/lib/libstd.so! This adds a "secret" environment variable, `__CARGO_DEFAULT_LIB_METADATA` which re-enables the old behavior of just putting hashes in filenames. Closes #3005
2 parents b05bacd + 7e40439 commit 109cb7c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/cargo/ops/cargo_rustc/context.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,30 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
335335
Some(metadata)
336336
} else if unit.pkg.package_id().source_id().is_path() &&
337337
!unit.profile.test {
338-
// If we're not building a unit test then the root package never
339-
// needs any metadata as it's guaranteed to not conflict with any
340-
// other output filenames. This means that we'll have predictable
338+
// If we're not building a unit test but we're building a path
339+
// dependency, then we're likely compiling the "current package" or
340+
// some package in a workspace. In this situation we pass no
341+
// metadata by default so we'll have predictable
341342
// file names like `target/debug/libfoo.{a,so,rlib}` and such.
342-
None
343+
//
344+
// Note, though, that the compiler's build system at least wants
345+
// path dependencies to have hashes in filenames. To account for
346+
// that we have an extra hack here which reads the
347+
// `__CARGO_DEFAULT_METADATA` environment variable and creates a
348+
// hash in the filename if that's present.
349+
//
350+
// This environment variable should not be relied on! It's basically
351+
// just here for rustbuild. We need a more principled method of
352+
// doing this eventually.
353+
if unit.target.is_lib() {
354+
env::var("__CARGO_DEFAULT_LIB_METADATA").ok().map(|meta| {
355+
let mut metadata = unit.pkg.generate_metadata();
356+
metadata.mix(&meta);
357+
metadata
358+
})
359+
} else {
360+
None
361+
}
343362
} else {
344363
metadata.cloned()
345364
}

0 commit comments

Comments
 (0)