Skip to content

Commit

Permalink
Auto merge of #6891 - ehuss:uplift-mac-dsym-example, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Apr 30, 2019
2 parents 6f39916 + f95f55a commit af1fcb3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
16 changes: 10 additions & 6 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,16 @@ impl TargetInfo {
}

// See rust-lang/cargo#4490, rust-lang/cargo#4960.
// - Only uplift debuginfo for binaries.
// Tests are run directly from `target/debug/deps/`
// and examples are inside target/debug/examples/ which already have symbols next to them,
// so no need to do anything.
if *kind == TargetKind::Bin {
if target_triple.contains("-apple-") {
// Only uplift debuginfo for binaries.
// - Tests are run directly from `target/debug/deps/` with the
// metadata hash still in the filename.
// - Examples are only uplifted for apple because the symbol file
// needs to match the executable file name to be found (i.e., it
// needs to remove the hash in the filename). On Windows, the path
// to the .pdb with the hash is embedded in the executable.
let is_apple = target_triple.contains("-apple-");
if *kind == TargetKind::Bin || (*kind == TargetKind::ExampleBin && is_apple) {
if is_apple {
ret.push(FileType {
suffix: ".dSYM".to_string(),
prefix: prefix.clone(),
Expand Down
30 changes: 12 additions & 18 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4132,10 +4132,8 @@ fn building_a_dependent_crate_witout_bin_should_fail() {
}

#[test]
#[cfg(any(target_os = "macos", target_os = "ios"))]
fn uplift_dsym_of_bin_on_mac() {
if !cfg!(any(target_os = "macos", target_os = "ios")) {
return;
}
let p = project()
.file("src/main.rs", "fn main() { panic!(); }")
.file("src/bin/b.rs", "fn main() { panic!(); }")
Expand All @@ -4144,23 +4142,17 @@ fn uplift_dsym_of_bin_on_mac() {
.build();

p.cargo("build --bins --examples --tests").run();
assert!(p.bin("foo.dSYM").is_dir());
assert!(p.bin("b.dSYM").is_dir());
assert!(p
.bin("b.dSYM")
.symlink_metadata()
.expect("read metadata from b.dSYM")
.file_type()
.is_symlink());
assert!(!p.bin("c.dSYM").is_dir());
assert!(!p.bin("d.dSYM").is_dir());
assert!(p.target_debug_dir().join("foo.dSYM").is_dir());
assert!(p.target_debug_dir().join("b.dSYM").is_dir());
assert!(p.target_debug_dir().join("b.dSYM").is_symlink());
assert!(p.target_debug_dir().join("examples/c.dSYM").is_symlink());
assert!(!p.target_debug_dir().join("c.dSYM").exists());
assert!(!p.target_debug_dir().join("d.dSYM").exists());
}

#[test]
#[cfg(all(target_os = "windows", target_env = "msvc"))]
fn uplift_pdb_of_bin_on_windows() {
if !cfg!(all(target_os = "windows", target_env = "msvc")) {
return;
}
let p = project()
.file("src/main.rs", "fn main() { panic!(); }")
.file("src/bin/b.rs", "fn main() { panic!(); }")
Expand All @@ -4171,8 +4163,10 @@ fn uplift_pdb_of_bin_on_windows() {
p.cargo("build --bins --examples --tests").run();
assert!(p.target_debug_dir().join("foo.pdb").is_file());
assert!(p.target_debug_dir().join("b.pdb").is_file());
assert!(!p.target_debug_dir().join("c.pdb").is_file());
assert!(!p.target_debug_dir().join("d.pdb").is_file());
assert!(!p.target_debug_dir().join("examples/c.pdb").exists());
assert_eq!(p.glob("target/debug/examples/c-*.pdb").count(), 1);
assert!(!p.target_debug_dir().join("c.pdb").exists());
assert!(!p.target_debug_dir().join("d.pdb").exists());
}

// Ensure that `cargo build` chooses the correct profile for building
Expand Down
6 changes: 6 additions & 0 deletions tests/testsuite/support/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub trait CargoPathExt {
fn move_in_time<F>(&self, travel_amount: F)
where
F: Fn(i64, u32) -> (i64, u32);

fn is_symlink(&self) -> bool;
}

impl CargoPathExt for Path {
Expand Down Expand Up @@ -142,6 +144,10 @@ impl CargoPathExt for Path {
});
}
}

fn is_symlink(&self) -> bool {
fs::symlink_metadata(self).map(|m| m.file_type().is_symlink()).unwrap_or(false)
}
}

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

0 comments on commit af1fcb3

Please sign in to comment.