/always-abort-rs

Rust library to ensure that any panic aborts

Primary LanguageRustApache License 2.0Apache-2.0

always-abort

Goal

Allow library crates to invoke std::panic::always_abort() automatically on start (of the compiled binary). And, ensure this at the beginning of execution, before main(), even when the binary may not have yet executed any function from the library crate (that is, from the library that uses always-abort).

This is needed, because a library's Cargo.toml containing

[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

doesn't affect the result binary.

Motivation

TARGETS

Supported targets are as per ctor.

Rust version

Currently this requires nightly. Please,

  1. give thumbs up to rust-lang/rust#84438, and
  2. subscribe to peter-lyons-kehl/always-abort-rs#1.

How to use

  1. In Cargo.toml of your library have
[dependencies]
always-abort = "0.0.2"
  1. In lib.rs of your library have
#[allow(unused_imports)]
use always_abort;

That is required, even though you don't execute/use any item from always-abort (which doesn't have any public items anyway).

Alternatives

Binary crates

You don't need to use always-abort crate if your crate is a binary. Instead, either call std::panic::always_abort(), or have panic = "abort" in the binary's Cargo.toml (which you want anyway, to reduce the binary size).

Library crates on unsupported targets

On targets not supported by ctor, you could have your library invoke std::panic::always_abort() at some kind of initiation.

CONTRIBUTIONS ARE DUAL LICENSED

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.