diff --git a/example-crates/c-gull-example-panic-abort/.gitignore b/example-crates/c-gull-example-panic-abort/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/example-crates/c-gull-example-panic-abort/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/example-crates/c-gull-example-panic-abort/Cargo.toml b/example-crates/c-gull-example-panic-abort/Cargo.toml new file mode 100644 index 0000000..005746a --- /dev/null +++ b/example-crates/c-gull-example-panic-abort/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "c-gull-example-panic-abort" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.libc] +path = "../../c-gull" +default-features = false +features = [ + "take-charge", + "std", + "thread", + "call-main", + "malloc-via-crates", + "threadsafe-setenv" +] +package = "c-gull" + +[profile.dev] +panic = "abort" +[profile.release] +panic = "abort" + +# This is just an example crate, and not part of the c-ward workspace. +[workspace] diff --git a/example-crates/c-gull-example-panic-abort/README.md b/example-crates/c-gull-example-panic-abort/README.md new file mode 100644 index 0000000..ca16608 --- /dev/null +++ b/example-crates/c-gull-example-panic-abort/README.md @@ -0,0 +1,3 @@ +Like the [c-gull-example example], but uses panic=abort in Cargo.toml. + +[c-gull-example example]: https://github.com/sunfishcode/c-ward/blob/main/example-crates/c-gull-example/README.md diff --git a/example-crates/c-gull-example-panic-abort/build.rs b/example-crates/c-gull-example-panic-abort/build.rs new file mode 100644 index 0000000..ccccd22 --- /dev/null +++ b/example-crates/c-gull-example-panic-abort/build.rs @@ -0,0 +1,4 @@ +fn main() { + // Pass -nostartfiles to the linker. + println!("cargo:rustc-link-arg=-nostartfiles"); +} diff --git a/example-crates/c-gull-example-panic-abort/src/main.rs b/example-crates/c-gull-example-panic-abort/src/main.rs new file mode 100644 index 0000000..0cc190a --- /dev/null +++ b/example-crates/c-gull-example-panic-abort/src/main.rs @@ -0,0 +1,8 @@ +//! A simple example using "take-charge" mode. + +fn main() { + println!("Hello world using Rust `println!`!"); + unsafe { + libc::printf("Hello world using libc `printf`!\n\0".as_ptr().cast()); + } +} diff --git a/tests/example_crates.rs b/tests/example_crates.rs index 80ee010..f0756af 100644 --- a/tests/example_crates.rs +++ b/tests/example_crates.rs @@ -73,6 +73,18 @@ fn example_crate_c_gull_example() { ); } +#[test] +fn example_crate_c_gull_example_panic_abort() { + test_crate( + "c-gull-example-panic-abort", + &[], + &[], + "Hello world using Rust `println!`!\nHello world using libc `printf`!\n", + "", + None, + ); +} + #[test] fn example_crate_c_gull_lto() { test_crate(