Skip to content

Commit

Permalink
Add an example using c-gull and panic = "abort".
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Oct 20, 2024
1 parent cb6562c commit 4a3669f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example-crates/c-gull-example-panic-abort/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
26 changes: 26 additions & 0 deletions example-crates/c-gull-example-panic-abort/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 3 additions & 0 deletions example-crates/c-gull-example-panic-abort/README.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions example-crates/c-gull-example-panic-abort/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
// Pass -nostartfiles to the linker.
println!("cargo:rustc-link-arg=-nostartfiles");
}
8 changes: 8 additions & 0 deletions example-crates/c-gull-example-panic-abort/src/main.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}
12 changes: 12 additions & 0 deletions tests/example_crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 4a3669f

Please sign in to comment.