Skip to content

Commit e9d7af4

Browse files
committed
Auto merge of #8329 - ehuss:apple-no-hash, r=alexcrichton
Don't hash executable filenames on apple platforms. Due to some recent changes to the backtrace crate, backtraces on apple platforms haven't been working (they are missing line/filename information). The reason is that previously libbacktrace would hunt through the directory for any matching file in the `.dSYM` directory. The new implementation expects a file matching the executable name exactly (which no longer includes the hash because Cargo renames it). The solution here is to not include a hash in the executable filename. This matches the behavior on Windows which does it for a similar reason (paths are embedded in pdb files). The downside is that switching between different settings (like different features) causes Cargo to rebuild the binary each time. I don't think this is a particularly common use case, at least I've not heard any complaints about this behavior on Windows. Fixes rust-lang/rust#72550
2 parents 02205f5 + f975c2e commit e9d7af4

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,12 @@ fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
608608
// - wasm32 executables: When using emscripten, the path to the .wasm file
609609
// is embedded in the .js file, so we don't want the hash in there.
610610
// TODO: Is this necessary for wasm32-unknown-unknown?
611+
// - apple executables: The executable name is used in the dSYM directory
612+
// (such as `target/debug/foo.dSYM/Contents/Resources/DWARF/foo-64db4e4bf99c12dd`).
613+
// Unfortunately this causes problems with our current backtrace
614+
// implementation which looks for a file matching the exe name exactly.
615+
// See https://github.com/rust-lang/rust/issues/72550#issuecomment-638501691
616+
// for more details.
611617
//
612618
// This is only done for local packages, as we don't expect to export
613619
// dependencies.
@@ -622,7 +628,8 @@ fn should_use_metadata(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
622628
if (unit.target.is_dylib()
623629
|| unit.target.is_cdylib()
624630
|| (unit.target.is_executable() && short_name.starts_with("wasm32-"))
625-
|| (unit.target.is_executable() && short_name.contains("msvc")))
631+
|| (unit.target.is_executable() && short_name.contains("msvc"))
632+
|| (unit.target.is_executable() && short_name.contains("-apple-")))
626633
&& unit.pkg.package_id().source_id().is_path()
627634
&& env::var("__CARGO_DEFAULT_LIB_METADATA").is_err()
628635
{

tests/testsuite/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4149,7 +4149,7 @@ fn uplift_dsym_of_bin_on_mac() {
41494149
assert!(p.target_debug_dir().join("foo.dSYM").is_dir());
41504150
assert!(p.target_debug_dir().join("b.dSYM").is_dir());
41514151
assert!(p.target_debug_dir().join("b.dSYM").is_symlink());
4152-
assert!(p.target_debug_dir().join("examples/c.dSYM").is_symlink());
4152+
assert!(p.target_debug_dir().join("examples/c.dSYM").is_dir());
41534153
assert!(!p.target_debug_dir().join("c.dSYM").exists());
41544154
assert!(!p.target_debug_dir().join("d.dSYM").exists());
41554155
}

tests/testsuite/collisions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ This may become a hard error in the future; see <https://github.com/rust-lang/ca
9191
}
9292

9393
#[cargo_test]
94-
// --out-dir and examples are currently broken on MSVC.
94+
// --out-dir and examples are currently broken on MSVC and apple.
9595
// See https://github.com/rust-lang/cargo/issues/7493
96-
#[cfg(not(target_env = "msvc"))]
96+
#[cfg_attr(any(target_env = "msvc", target_vendor = "apple"), ignore)]
9797
fn collision_export() {
9898
// `--out-dir` combines some things which can cause conflicts.
9999
let p = project()

tests/testsuite/freshness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ fn changing_bin_features_caches_targets() {
491491
/* Targets should be cached from the first build */
492492

493493
let mut e = p.cargo("build");
494-
// MSVC does not include hash in binary filename, so it gets recompiled.
495-
if cfg!(target_env = "msvc") {
494+
// MSVC/apple does not include hash in binary filename, so it gets recompiled.
495+
if cfg!(any(target_env = "msvc", target_vendor = "apple")) {
496496
e.with_stderr("[COMPILING] foo[..]\n[FINISHED] dev[..]");
497497
} else {
498498
e.with_stderr("[FINISHED] dev[..]");
@@ -501,7 +501,7 @@ fn changing_bin_features_caches_targets() {
501501
p.rename_run("foo", "off2").with_stdout("feature off").run();
502502

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

0 commit comments

Comments
 (0)