Skip to content

Commit

Permalink
Don't use mmap on macOS (#302)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Aaron1011 authored Mar 10, 2020
1 parent a9d6076 commit 594ffa6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion crates/backtrace-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions crates/macos_frames_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "macos_frames_test"
version = "0.1.0"
authors = ["Aaron Hill <[email protected]>"]
edition = "2018"

[dependencies.backtrace]
path = "../.."
1 change: 1 addition & 0 deletions crates/macos_frames_test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// intentionally blank
30 changes: 30 additions & 0 deletions crates/macos_frames_test/tests/main.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 594ffa6

Please sign in to comment.