Skip to content

Commit

Permalink
feat: Add native crash reporter (getsentry#795)
Browse files Browse the repository at this point in the history
feat: Add native crash reporter

This adds an optional native crash reporter modeled on `relay-crash`.
  • Loading branch information
loewenheim authored and Jos Backus committed Jun 6, 2022
1 parent 7926bfd commit b6b7511
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Install libcurl-dev
run: |
sudo apt update
sudo apt-get install -y libcurl4-openssl-dev
- name: Checkout sources
uses: actions/checkout@v2

Expand Down Expand Up @@ -60,6 +65,11 @@ jobs:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Install libcurl-dev
run: |
sudo apt update
sudo apt-get install -y libcurl4-openssl-dev
- name: Checkout sources
uses: actions/checkout@v2

Expand Down Expand Up @@ -89,6 +99,11 @@ jobs:
name: Integration Tests
runs-on: ubuntu-latest
steps:
- name: Install libcurl-dev
run: |
sudo apt update
sudo apt-get install -y libcurl4-openssl-dev
- name: Checkout sources
uses: actions/checkout@v2

Expand Down Expand Up @@ -121,6 +136,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install libcurl-dev
run: |
sudo apt update
sudo apt-get install -y libcurl4-openssl-dev
- name: Checkout Symbolicator
uses: actions/checkout@v2

Expand Down Expand Up @@ -175,6 +195,11 @@ jobs:
env:
RUSTDOCFLAGS: -Dwarnings
steps:
- name: Install libcurl-dev
run: |
sudo apt update
sudo apt-get install -y libcurl4-openssl-dev
- name: Checkout sources
uses: actions/checkout@v2

Expand Down Expand Up @@ -222,6 +247,11 @@ jobs:
continue-on-error: true # well, its nightly and highly experimental

steps:
- name: Install libcurl-dev
run: |
sudo apt update
sudo apt-get install -y libcurl4-openssl-dev
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "crates/symbolicator-crash/sentry-native"]
path = crates/symbolicator-crash/sentry-native
url = https://github.com/getsentry/sentry-native
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Added an internal option to capture minidumps for hard crashes. This has to be enabled via the `_crash_db` config parameter. ([#795](https://github.com/getsentry/symbolicator/pull/795))

## 0.5.0

### Features
Expand Down
105 changes: 105 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ WORKDIR /work

RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential ca-certificates curl libssl-dev pkg-config git zip \
# below required for sentry-native
clang libcurl4-openssl-dev \
&& rm -rf /var/lib/apt/lists/*

ENV CARGO_HOME=/usr/local/cargo \
Expand All @@ -17,6 +19,9 @@ ENV RUST_TOOLCHAIN=1.57.0

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain $RUST_TOOLCHAIN

ARG SYMBOLICATOR_FEATURES=symbolicator-crash
ENV SYMBOLICATOR_FEATURES=${SYMBOLICATOR_FEATURES}

# Build only dependencies to speed up subsequent builds
COPY Cargo.toml Cargo.lock ./

Expand All @@ -37,7 +42,7 @@ COPY .git ./.git/
# Ignore missing (deleted) files for dirty-check in `git describe` call for version
# This is a bit hacky because it ignores *all* deleted files, not just the ones we skipped in Docker
RUN git update-index --skip-worktree $(git status | grep deleted | awk '{print $2}')
RUN cargo build --release
RUN cargo build --release --features=${SYMBOLICATOR_FEATURES}
RUN objcopy --only-keep-debug target/release/symbolicator target/release/symbolicator.debug \
&& objcopy --strip-debug --strip-unneeded target/release/symbolicator \
&& objcopy --add-gnu-debuglink target/release/symbolicator target/release/symbolicator.debug \
Expand Down
17 changes: 17 additions & 0 deletions crates/symbolicator-crash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "symbolicator-crash"
authors = ["Sentry <[email protected]>"]
description = "Native crash reporting for Symbolicator"
homepage = "https://getsentry.github.io/symbolicator/"
repository = "https://github.com/getsentry/symbolicator"
version = "0.5.0"
edition = "2018"
build = "build.rs"
license-file = "../LICENSE"
publish = false

[dependencies]

[build-dependencies]
bindgen = "0.59.1"
cmake = { version = "0.1.46" }
49 changes: 49 additions & 0 deletions crates/symbolicator-crash/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::path::{Path, PathBuf};
use std::process::Command;

fn main() {
// sentry-native dependencies
match std::env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
"macos" => println!("cargo:rustc-link-lib=dylib=c++"),
"linux" => println!("cargo:rustc-link-lib=dylib=stdc++"),
_ => return, // allow building with --all-features, fail during runtime
}

println!("cargo:rustc-link-lib=curl");

if !Path::new("sentry-native/.git").exists() {
let _ = Command::new("git")
.args(&["submodule", "update", "--init", "--recursive"])
.status();
}

let destination = cmake::Config::new("sentry-native")
// we never need a debug build of sentry-native
.profile("RelWithDebInfo")
// always build breakpad regardless of platform defaults
.define("SENTRY_BACKEND", "breakpad")
// build a static library
.define("BUILD_SHARED_LIBS", "OFF")
// disable additional targets
.define("SENTRY_BUILD_TESTS", "OFF")
.define("SENTRY_BUILD_EXAMPLES", "OFF")
.build();

println!(
"cargo:rustc-link-search=native={}",
destination.join("lib").display()
);
println!("cargo:rustc-link-lib=static=breakpad_client");
println!("cargo:rustc-link-lib=static=sentry");

let bindings = bindgen::Builder::default()
.header("sentry-native/include/sentry.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");

let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_dir.join("bindings.rs"))
.expect("Couldn't write bindings");
}
1 change: 1 addition & 0 deletions crates/symbolicator-crash/sentry-native
Submodule sentry-native added at bd5610
Loading

0 comments on commit b6b7511

Please sign in to comment.