diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd0fc4bf9..a039f23df 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,6 +78,7 @@ jobs: - run: cargo test --no-default-features --features "dbghelp std" - run: cargo test --no-default-features --features "dbghelp std verify-winapi" - run: cargo test --manifest-path crates/cpp_smoke_test/Cargo.toml + - run: cargo test --manifest-path crates/macos_frames_test/Cargo.toml - run: cargo test --features libbacktrace --manifest-path crates/without_debuginfo/Cargo.toml - run: cargo test --features "libbacktrace coresymbolication" --manifest-path crates/without_debuginfo/Cargo.toml - run: cargo test --features "libbacktrace gimli-symbolize" --manifest-path crates/without_debuginfo/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index 1b5300cf7..61e350895 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2018" [workspace] members = ['crates/cpp_smoke_test'] -exclude = ['crates/without_debuginfo'] +exclude = ['crates/without_debuginfo', 'crates/macos_frames_test'] [dependencies] cfg-if = "0.1.10" diff --git a/crates/backtrace-sys/build.rs b/crates/backtrace-sys/build.rs index 564f23a91..e96311356 100644 --- a/crates/backtrace-sys/build.rs +++ b/crates/backtrace-sys/build.rs @@ -36,7 +36,9 @@ fn main() { // `mmap` does not exist on Windows, so we use // the less efficient `read`-based code. - if target.contains("windows") { + // Using `mmap` on macOS causes weird isseus - see + // https://github.com/rust-lang/rust/pull/45866 + if target.contains("windows") || target.contains("darwin") { build.file("src/libbacktrace/read.c"); } else { build.file("src/libbacktrace/mmapio.c"); diff --git a/crates/macos_frames_test/Cargo.toml b/crates/macos_frames_test/Cargo.toml new file mode 100644 index 000000000..278d51e79 --- /dev/null +++ b/crates/macos_frames_test/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "macos_frames_test" +version = "0.1.0" +authors = ["Aaron Hill "] +edition = "2018" + +[dependencies.backtrace] +path = "../.." diff --git a/crates/macos_frames_test/src/lib.rs b/crates/macos_frames_test/src/lib.rs new file mode 100644 index 000000000..65e2cc340 --- /dev/null +++ b/crates/macos_frames_test/src/lib.rs @@ -0,0 +1 @@ +// intentionally blank diff --git a/crates/macos_frames_test/tests/main.rs b/crates/macos_frames_test/tests/main.rs new file mode 100644 index 000000000..1d28f2022 --- /dev/null +++ b/crates/macos_frames_test/tests/main.rs @@ -0,0 +1,30 @@ +// Based on from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs +// This needs to go in a crate by itself, since it modifies the dSYM for the entire test +// output directory. +// +// Note that this crate is *not* part of the overall `backtrace-rs` workspace, +// so that it gets its own 'target' directory. We manually invoke this test +// in .github/workflows/main.yml by passing `--manifest-path` to Cargo +#[test] +#[cfg(target_os = "macos")] +fn backtrace_no_dsym() { + use std::{env, fs, panic}; + + // Find our dSYM and replace the DWARF binary with an empty file + let mut dsym_path = env::current_exe().unwrap(); + let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string(); + assert!(dsym_path.pop()); // Pop executable + dsym_path.push(format!( + "{}.dSYM/Contents/Resources/DWARF/{0}", + executable_name + )); + let _ = fs::OpenOptions::new() + .read(false) + .write(true) + .truncate(true) + .create(false) + .open(&dsym_path) + .unwrap(); + + backtrace::Backtrace::new(); +}