Skip to content

Commit 121f4b3

Browse files
committed
Auto merge of #9653 - bjorn3:update_should_use_metadata, r=alexcrichton
Update should_use_metadata function * Correct the reason for not renaming dylibs * Add todo for -install-name/-soname usage * Limit wasm32 executable metadata omission to emscripten. Wasm file don't contain any filename themself. * Don't omit metadata for executables on macOS. backtrace-rs is now able to load debuginfo for renamed .dSYM files: https://github.com/rust-lang/backtrace-rs/blob/ed3689c2f2b9a31546d75fae389a32a572957dbd/src/symbolize/gimli/macho.rs#L51-L65 * Mention another reason to include the metadata hash for libstd.
2 parents cebef29 + 8c24820 commit 121f4b3

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -626,19 +626,13 @@ fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
626626
// No metadata in these cases:
627627
//
628628
// - dylibs:
629-
// - macOS encodes the dylib name in the executable, so it can't be renamed.
630-
// - TODO: Are there other good reasons? If not, maybe this should be macos specific?
629+
// - if any dylib names are encoded in executables, so they can't be renamed.
630+
// - TODO: Maybe use `-install-name` on macOS or `-soname` on other UNIX systems
631+
// to specify the dylib name to be used by the linker instead of the filename.
631632
// - Windows MSVC executables: The path to the PDB is embedded in the
632633
// executable, and we don't want the PDB path to include the hash in it.
633-
// - wasm32 executables: When using emscripten, the path to the .wasm file
634-
// is embedded in the .js file, so we don't want the hash in there.
635-
// TODO: Is this necessary for wasm32-unknown-unknown?
636-
// - apple executables: The executable name is used in the dSYM directory
637-
// (such as `target/debug/foo.dSYM/Contents/Resources/DWARF/foo-64db4e4bf99c12dd`).
638-
// Unfortunately this causes problems with our current backtrace
639-
// implementation which looks for a file matching the exe name exactly.
640-
// See https://github.com/rust-lang/rust/issues/72550#issuecomment-638501691
641-
// for more details.
634+
// - wasm32-unknown-emscripten executables: When using emscripten, the path to the
635+
// .wasm file is embedded in the .js file, so we don't want the hash in there.
642636
//
643637
// This is only done for local packages, as we don't expect to export
644638
// dependencies.
@@ -647,14 +641,14 @@ fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
647641
// force metadata in the hash. This is only used for building libstd. For
648642
// example, if libstd is placed in a common location, we don't want a file
649643
// named /usr/lib/libstd.so which could conflict with other rustc
650-
// installs. TODO: Is this still a realistic concern?
644+
// installs. In addition it prevents accidentally loading a libstd of a
645+
// different compiler at runtime.
651646
// See https://github.com/rust-lang/cargo/issues/3005
652647
let short_name = bcx.target_data.short_name(&unit.kind);
653648
if (unit.target.is_dylib()
654649
|| unit.target.is_cdylib()
655-
|| (unit.target.is_executable() && short_name.starts_with("wasm32-"))
656-
|| (unit.target.is_executable() && short_name.contains("msvc"))
657-
|| (unit.target.is_executable() && short_name.contains("-apple-")))
650+
|| (unit.target.is_executable() && short_name == "wasm32-unknown-emscripten")
651+
|| (unit.target.is_executable() && short_name.contains("msvc")))
658652
&& unit.pkg.package_id().source_id().is_path()
659653
&& env::var("__CARGO_DEFAULT_LIB_METADATA").is_err()
660654
{

tests/testsuite/freshness.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ fn changing_bin_features_caches_targets() {
493493
/* Targets should be cached from the first build */
494494

495495
let mut e = p.cargo("build");
496-
// MSVC/apple does not include hash in binary filename, so it gets recompiled.
497-
if cfg!(any(target_env = "msvc", target_vendor = "apple")) {
496+
// MSVC does not include hash in binary filename, so it gets recompiled.
497+
if cfg!(target_env = "msvc") {
498498
e.with_stderr("[COMPILING] foo[..]\n[FINISHED] dev[..]");
499499
} else {
500500
e.with_stderr("[FINISHED] dev[..]");
@@ -503,7 +503,7 @@ fn changing_bin_features_caches_targets() {
503503
p.rename_run("foo", "off2").with_stdout("feature off").run();
504504

505505
let mut e = p.cargo("build --features foo");
506-
if cfg!(any(target_env = "msvc", target_vendor = "apple")) {
506+
if cfg!(target_env = "msvc") {
507507
e.with_stderr("[COMPILING] foo[..]\n[FINISHED] dev[..]");
508508
} else {
509509
e.with_stderr("[FINISHED] dev[..]");

0 commit comments

Comments
 (0)