Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 58 additions & 34 deletions src/cargo/core/compiler/build_runner/compilation_files.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I saw this kind of commit I badly wanted semantic diff built into GitHub.

(Sorry for the noise)

https://app.semanticdiff.com/gh/rust-lang/cargo/pull/16351/changes#src/cargo/core/compiler/build_runner/compilation_files.rs?ignore_comments=true

Original file line number Diff line number Diff line change
Expand Up @@ -887,40 +887,64 @@ fn use_extra_filename(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
// Doc tests do not have metadata.
return false;
}
if unit.mode.is_any_test() || unit.mode.is_check() {
// These always use metadata.
return true;
}
// No metadata in these cases:
//
// - dylibs:
// - if any dylib names are encoded in executables, so they can't be renamed.
// - TODO: Maybe use `-install-name` on macOS or `-soname` on other UNIX systems
// to specify the dylib name to be used by the linker instead of the filename.
// - Windows MSVC executables: The path to the PDB is embedded in the
// executable, and we don't want the PDB path to include the hash in it.
// - wasm32-unknown-emscripten executables: When using emscripten, the path to the
// .wasm file is embedded in the .js file, so we don't want the hash in there.
//
// This is only done for local packages, as we don't expect to export
// dependencies.
//
// The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
// force metadata in the hash. This is only used for building libstd. For
// example, if libstd is placed in a common location, we don't want a file
// named /usr/lib/libstd.so which could conflict with other rustc
// installs. In addition it prevents accidentally loading a libstd of a
// different compiler at runtime.
// See https://github.com/rust-lang/cargo/issues/3005
let short_name = bcx.target_data.short_name(&unit.kind);
if (unit.target.is_dylib()
|| unit.target.is_cdylib()
|| (unit.target.is_executable() && short_name == "wasm32-unknown-emscripten")
|| (unit.target.is_executable() && short_name.contains("msvc")))
&& unit.pkg.package_id().source_id().is_path()
&& bcx.gctx.get_env("__CARGO_DEFAULT_LIB_METADATA").is_err()
{
return false;
if bcx.gctx.cli_unstable().build_dir_new_layout {
if unit.mode.is_any_test() || unit.mode.is_check() {
// These always use metadata.
return true;
}
// No metadata in these cases:
//
// - dylib, cdylib, executable: `pkg_dir` avoids collisions for us and rustc isn't looking these
// up by `-Cextra-filename`
//
// The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
// force metadata in the hash. This is only used for building libstd. For
// example, if libstd is placed in a common location, we don't want a file
// named /usr/lib/libstd.so which could conflict with other rustc
// installs. In addition it prevents accidentally loading a libstd of a
// different compiler at runtime.
// See https://github.com/rust-lang/cargo/issues/3005
if (unit.target.is_dylib() || unit.target.is_cdylib() || unit.target.is_executable())
&& bcx.gctx.get_env("__CARGO_DEFAULT_LIB_METADATA").is_err()
{
return false;
}
} else {
if unit.mode.is_any_test() || unit.mode.is_check() {
// These always use metadata.
return true;
}
// No metadata in these cases:
//
// - dylibs:
// - if any dylib names are encoded in executables, so they can't be renamed.
// - TODO: Maybe use `-install-name` on macOS or `-soname` on other UNIX systems
// to specify the dylib name to be used by the linker instead of the filename.
// - Windows MSVC executables: The path to the PDB is embedded in the
// executable, and we don't want the PDB path to include the hash in it.
// - wasm32-unknown-emscripten executables: When using emscripten, the path to the
// .wasm file is embedded in the .js file, so we don't want the hash in there.
//
// This is only done for local packages, as we don't expect to export
// dependencies.
//
// The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
// force metadata in the hash. This is only used for building libstd. For
// example, if libstd is placed in a common location, we don't want a file
// named /usr/lib/libstd.so which could conflict with other rustc
// installs. In addition it prevents accidentally loading a libstd of a
// different compiler at runtime.
// See https://github.com/rust-lang/cargo/issues/3005
let short_name = bcx.target_data.short_name(&unit.kind);
if (unit.target.is_dylib()
|| unit.target.is_cdylib()
|| (unit.target.is_executable() && short_name == "wasm32-unknown-emscripten")
|| (unit.target.is_executable() && short_name.contains("msvc")))
&& unit.pkg.package_id().source_id().is_path()
&& bcx.gctx.get_env("__CARGO_DEFAULT_LIB_METADATA").is_err()
{
return false;
}
}
true
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ fn cargo_tmpdir_should_output_to_build_dir() {
[ROOT]/foo/build-dir/CACHEDIR.TAG
[ROOT]/foo/build-dir/debug/.cargo-lock
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH].d
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH].d
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo.d
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..].d
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH][EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo-[HASH][EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..][EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/invoked.timestamp
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/dep-test-bin-foo
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/clean_new_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn clean_multiple_packages_in_glob_char_path() {
let foo_path = &p.build_dir().join("debug").join("build");

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

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