Skip to content

Commit 594ffa6

Browse files
authored
Don't use mmap on macOS (#302)
* Add regression test for SIGPIPE on macOS * Disable `mmap` on macOS See rust-lang/rust#45866 for more details * Run `cargo fmt` * Remove unused variable name * s/macos/darwin/ * Move macOS test to its own file * Move macOS dSYM test to its own directory * Remove 'darwin' check to verify new test * Fix rustfmt * Re-add darwin check * Move macOS test to a non-workspace crate
1 parent a9d6076 commit 594ffa6

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

.github/workflows/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
- run: cargo test --no-default-features --features "dbghelp std"
7979
- run: cargo test --no-default-features --features "dbghelp std verify-winapi"
8080
- run: cargo test --manifest-path crates/cpp_smoke_test/Cargo.toml
81+
- run: cargo test --manifest-path crates/macos_frames_test/Cargo.toml
8182
- run: cargo test --features libbacktrace --manifest-path crates/without_debuginfo/Cargo.toml
8283
- run: cargo test --features "libbacktrace coresymbolication" --manifest-path crates/without_debuginfo/Cargo.toml
8384
- run: cargo test --features "libbacktrace gimli-symbolize" --manifest-path crates/without_debuginfo/Cargo.toml

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ edition = "2018"
1616

1717
[workspace]
1818
members = ['crates/cpp_smoke_test']
19-
exclude = ['crates/without_debuginfo']
19+
exclude = ['crates/without_debuginfo', 'crates/macos_frames_test']
2020

2121
[dependencies]
2222
cfg-if = "0.1.10"

crates/backtrace-sys/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ fn main() {
3636

3737
// `mmap` does not exist on Windows, so we use
3838
// the less efficient `read`-based code.
39-
if target.contains("windows") {
39+
// Using `mmap` on macOS causes weird isseus - see
40+
// https://github.com/rust-lang/rust/pull/45866
41+
if target.contains("windows") || target.contains("darwin") {
4042
build.file("src/libbacktrace/read.c");
4143
} else {
4244
build.file("src/libbacktrace/mmapio.c");

crates/macos_frames_test/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "macos_frames_test"
3+
version = "0.1.0"
4+
authors = ["Aaron Hill <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies.backtrace]
8+
path = "../.."

crates/macos_frames_test/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// intentionally blank
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Based on from https://github.com/rust-lang/rust/blob/2cb0b8582ebbf9784db9cec06fff517badbf4553/src/test/ui/issues/issue-45731.rs
2+
// This needs to go in a crate by itself, since it modifies the dSYM for the entire test
3+
// output directory.
4+
//
5+
// Note that this crate is *not* part of the overall `backtrace-rs` workspace,
6+
// so that it gets its own 'target' directory. We manually invoke this test
7+
// in .github/workflows/main.yml by passing `--manifest-path` to Cargo
8+
#[test]
9+
#[cfg(target_os = "macos")]
10+
fn backtrace_no_dsym() {
11+
use std::{env, fs, panic};
12+
13+
// Find our dSYM and replace the DWARF binary with an empty file
14+
let mut dsym_path = env::current_exe().unwrap();
15+
let executable_name = dsym_path.file_name().unwrap().to_str().unwrap().to_string();
16+
assert!(dsym_path.pop()); // Pop executable
17+
dsym_path.push(format!(
18+
"{}.dSYM/Contents/Resources/DWARF/{0}",
19+
executable_name
20+
));
21+
let _ = fs::OpenOptions::new()
22+
.read(false)
23+
.write(true)
24+
.truncate(true)
25+
.create(false)
26+
.open(&dsym_path)
27+
.unwrap();
28+
29+
backtrace::Backtrace::new();
30+
}

0 commit comments

Comments
 (0)