5

If I specify panic like this, it works for all targets:

[profile.release]
panic = "abort"

I want to specify panic = "abort" only for target=arm-linux-androideabi.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
user1244932
  • 7,352
  • 5
  • 46
  • 103

2 Answers2

6

You will need to add a .cargo/config to your project and use it to specify the panic settings instead of Cargo.toml:

[target.arm-linux-androideabi]
rustflags = ["-C", "panic=abort"]

The two main configuration headings you will want to look at are [target.$triple] and [target.'cfg(...)'].

Brian Cain
  • 14,403
  • 3
  • 50
  • 88
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
0

There is another way you could try to accomplish this: add a custom panic handler, gather a stack-trace, parse the stack-trace to determine what library the panic occurred in, and then only abort if you detect it as having occurred within that library.

Is this hacky/brittle? Yes.

But the option is there if for some reason you want it!

Starting point:

panic::set_hook(Box::new(|info| {
    //let stacktrace = Backtrace::capture();
    let stacktrace = Backtrace::force_capture();
    println!("Got panic. @info:{}\n@stackTrace:{}", info, stacktrace);
    if guess_library_from_stacktrace(stacktrace) == "library-X" {
        std::process::abort();
    }
}));

Here is a GitHub comment with more details: https://github.com/tokio-rs/tokio/issues/2002#issuecomment-1020443386

Venryx
  • 15,624
  • 10
  • 70
  • 96