Skip to content

Commit af1fcb3

Browse files
committed
Auto merge of #6891 - ehuss:uplift-mac-dsym-example, r=alexcrichton
Symlink dSYM on macOS example binaries. Examples previously ended up with a layout such as: ``` target/debug/examples/ex1 target/debug/examples/ex1.d target/debug/examples/ex1-966e505ad4696130 target/debug/examples/ex1-966e505ad4696130.d target/debug/examples/ex1-966e505ad4696130.dSYM/… ``` If you attempt to run lldb on the executable without the hash (`target/debug/examples/ex1`), then symbols could not be found. This PR solves this by creating a symlink from `ex1.dSYM -> ex1-966e505ad4696130.dSYM`. Closes #6889
2 parents 6f39916 + f95f55a commit af1fcb3

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

src/cargo/core/compiler/build_context/target_info.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,16 @@ impl TargetInfo {
225225
}
226226

227227
// See rust-lang/cargo#4490, rust-lang/cargo#4960.
228-
// - Only uplift debuginfo for binaries.
229-
// Tests are run directly from `target/debug/deps/`
230-
// and examples are inside target/debug/examples/ which already have symbols next to them,
231-
// so no need to do anything.
232-
if *kind == TargetKind::Bin {
233-
if target_triple.contains("-apple-") {
228+
// Only uplift debuginfo for binaries.
229+
// - Tests are run directly from `target/debug/deps/` with the
230+
// metadata hash still in the filename.
231+
// - Examples are only uplifted for apple because the symbol file
232+
// needs to match the executable file name to be found (i.e., it
233+
// needs to remove the hash in the filename). On Windows, the path
234+
// to the .pdb with the hash is embedded in the executable.
235+
let is_apple = target_triple.contains("-apple-");
236+
if *kind == TargetKind::Bin || (*kind == TargetKind::ExampleBin && is_apple) {
237+
if is_apple {
234238
ret.push(FileType {
235239
suffix: ".dSYM".to_string(),
236240
prefix: prefix.clone(),

tests/testsuite/build.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -4132,10 +4132,8 @@ fn building_a_dependent_crate_witout_bin_should_fail() {
41324132
}
41334133

41344134
#[test]
4135+
#[cfg(any(target_os = "macos", target_os = "ios"))]
41354136
fn uplift_dsym_of_bin_on_mac() {
4136-
if !cfg!(any(target_os = "macos", target_os = "ios")) {
4137-
return;
4138-
}
41394137
let p = project()
41404138
.file("src/main.rs", "fn main() { panic!(); }")
41414139
.file("src/bin/b.rs", "fn main() { panic!(); }")
@@ -4144,23 +4142,17 @@ fn uplift_dsym_of_bin_on_mac() {
41444142
.build();
41454143

41464144
p.cargo("build --bins --examples --tests").run();
4147-
assert!(p.bin("foo.dSYM").is_dir());
4148-
assert!(p.bin("b.dSYM").is_dir());
4149-
assert!(p
4150-
.bin("b.dSYM")
4151-
.symlink_metadata()
4152-
.expect("read metadata from b.dSYM")
4153-
.file_type()
4154-
.is_symlink());
4155-
assert!(!p.bin("c.dSYM").is_dir());
4156-
assert!(!p.bin("d.dSYM").is_dir());
4145+
assert!(p.target_debug_dir().join("foo.dSYM").is_dir());
4146+
assert!(p.target_debug_dir().join("b.dSYM").is_dir());
4147+
assert!(p.target_debug_dir().join("b.dSYM").is_symlink());
4148+
assert!(p.target_debug_dir().join("examples/c.dSYM").is_symlink());
4149+
assert!(!p.target_debug_dir().join("c.dSYM").exists());
4150+
assert!(!p.target_debug_dir().join("d.dSYM").exists());
41574151
}
41584152

41594153
#[test]
4154+
#[cfg(all(target_os = "windows", target_env = "msvc"))]
41604155
fn uplift_pdb_of_bin_on_windows() {
4161-
if !cfg!(all(target_os = "windows", target_env = "msvc")) {
4162-
return;
4163-
}
41644156
let p = project()
41654157
.file("src/main.rs", "fn main() { panic!(); }")
41664158
.file("src/bin/b.rs", "fn main() { panic!(); }")
@@ -4171,8 +4163,10 @@ fn uplift_pdb_of_bin_on_windows() {
41714163
p.cargo("build --bins --examples --tests").run();
41724164
assert!(p.target_debug_dir().join("foo.pdb").is_file());
41734165
assert!(p.target_debug_dir().join("b.pdb").is_file());
4174-
assert!(!p.target_debug_dir().join("c.pdb").is_file());
4175-
assert!(!p.target_debug_dir().join("d.pdb").is_file());
4166+
assert!(!p.target_debug_dir().join("examples/c.pdb").exists());
4167+
assert_eq!(p.glob("target/debug/examples/c-*.pdb").count(), 1);
4168+
assert!(!p.target_debug_dir().join("c.pdb").exists());
4169+
assert!(!p.target_debug_dir().join("d.pdb").exists());
41764170
}
41774171

41784172
// Ensure that `cargo build` chooses the correct profile for building

tests/testsuite/support/paths.rs

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pub trait CargoPathExt {
7070
fn move_in_time<F>(&self, travel_amount: F)
7171
where
7272
F: Fn(i64, u32) -> (i64, u32);
73+
74+
fn is_symlink(&self) -> bool;
7375
}
7476

7577
impl CargoPathExt for Path {
@@ -142,6 +144,10 @@ impl CargoPathExt for Path {
142144
});
143145
}
144146
}
147+
148+
fn is_symlink(&self) -> bool {
149+
fs::symlink_metadata(self).map(|m| m.file_type().is_symlink()).unwrap_or(false)
150+
}
145151
}
146152

147153
fn do_op<F>(path: &Path, desc: &str, mut f: F)

0 commit comments

Comments
 (0)