Skip to content

Commit 98a0684

Browse files
committed
fix(layout): Remove hashes from bins in new layout
There is a desire in #8332 to make our use of `-Cextra-file-name` in `deps/` more consistent across platforms. Having it present gets in the way of finding PDBs. With #15010, we no longer need `-Cextra-file-name` to avoid collisions. It might still be used by rustc for faster lookups though. So we can at least adjust all other platforms to be like Windows, making things consistent Addresses #8332 if #15010 is stabilized Part of #15010
1 parent d1061b4 commit 98a0684

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/cargo/core/compiler/build_runner/compilation_files.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,29 @@ fn use_extra_filename(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
887887
// Doc tests do not have metadata.
888888
return false;
889889
}
890-
{
890+
if bcx.gctx.cli_unstable().build_dir_new_layout {
891+
if unit.mode.is_any_test() || unit.mode.is_check() {
892+
// These always use metadata.
893+
return true;
894+
}
895+
// No metadata in these cases:
896+
//
897+
// - dylib, cdylib, executable: `pkg_dir` avoids collisions for us and rustc isn't looking these
898+
// up by `-Cextra-filename`
899+
//
900+
// The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
901+
// force metadata in the hash. This is only used for building libstd. For
902+
// example, if libstd is placed in a common location, we don't want a file
903+
// named /usr/lib/libstd.so which could conflict with other rustc
904+
// installs. In addition it prevents accidentally loading a libstd of a
905+
// different compiler at runtime.
906+
// See https://github.com/rust-lang/cargo/issues/3005
907+
if (unit.target.is_dylib() || unit.target.is_cdylib() || unit.target.is_executable())
908+
&& bcx.gctx.get_env("__CARGO_DEFAULT_LIB_METADATA").is_err()
909+
{
910+
return false;
911+
}
912+
} else {
891913
if unit.mode.is_any_test() || unit.mode.is_check() {
892914
// These always use metadata.
893915
return true;

tests/testsuite/build_dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ fn cargo_tmpdir_should_output_to_build_dir() {
336336
[ROOT]/foo/build-dir/CACHEDIR.TAG
337337
[ROOT]/foo/build-dir/debug/.cargo-lock
338338
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH].d
339-
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH].d
339+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo.d
340340
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..].d
341341
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH][EXE]
342-
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH][EXE]
342+
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[EXE]
343343
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..][EXE]
344344
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/invoked.timestamp
345345
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/dep-test-bin-foo

tests/testsuite/clean_new_layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn clean_multiple_packages_in_glob_char_path() {
126126
let foo_path = &p.build_dir().join("debug").join("build");
127127

128128
#[cfg(not(target_env = "msvc"))]
129-
let file_glob = "foo/*/deps/foo-*";
129+
let file_glob = "foo/*/deps/foo*";
130130

131131
#[cfg(target_env = "msvc")]
132132
let file_glob = "foo/*/deps/foo.pdb";

0 commit comments

Comments
 (0)