|
| 1 | +// Exercise unwinding a panic. This catches a panic across an FFI (foreign function interface) |
| 2 | +// boundary and downcasts it into an integer. |
| 3 | +// The Rust code that panics is in a separate crate. |
| 4 | +// See https://github.com/rust-lang/rust/commit/baf227ea0c1e07fc54395a51e4b3881d701180cb |
| 5 | + |
| 6 | +//@ ignore-cross-compile |
| 7 | +// Reason: the compiled binary is executed |
| 8 | +//@ needs-unwind |
| 9 | +// Reason: this test exercises unwinding a panic |
| 10 | + |
| 11 | +use run_make_support::{cc, is_msvc, llvm_ar, run, rustc}; |
| 12 | + |
| 13 | +fn main() { |
| 14 | + // Compile `add.c` into an object file. |
| 15 | + if is_msvc() { |
| 16 | + cc().arg("-c").out_exe("add").input("add.c").run(); |
| 17 | + } else { |
| 18 | + cc().arg("-v").arg("-c").out_exe("add.o").input("add.c").run(); |
| 19 | + }; |
| 20 | + |
| 21 | + // Compile `panic.rs` into an object file. |
| 22 | + // Note that we invoke `rustc` directly, so we may emit an object rather |
| 23 | + // than an archive. We'll do that later. |
| 24 | + rustc().emit("obj").input("panic.rs").run(); |
| 25 | + |
| 26 | + // Now, create an archive using these two objects. |
| 27 | + if is_msvc() { |
| 28 | + llvm_ar().obj_to_ar().args(&["libadd.a", "add.obj", "panic.o"]).run(); |
| 29 | + } else { |
| 30 | + llvm_ar().obj_to_ar().args(&["libadd.a", "add.o", "panic.o"]).run(); |
| 31 | + }; |
| 32 | + |
| 33 | + // Compile `main.rs`, which will link into our library, and run it. |
| 34 | + rustc().input("main.rs").run(); |
| 35 | + run("main"); |
| 36 | +} |
0 commit comments