Created
March 28, 2025 08:26
-
-
Save madsmtm/3c53305b58624ee8251a38b709db6412 to your computer and use it in GitHub Desktop.
Minimal `cc-rs` `#![no_std]` example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
println!("cargo:rerun-if-changed=build.rs"); | |
println!("cargo:rerun-if-changed=foo.c"); | |
cc::Build::new().file("foo.c").compile("foo"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "example" | |
version = "0.1.0" | |
edition = "2021" | |
publish = false | |
[build-dependencies] | |
cc = "1.2.17" | |
[lib] | |
path = "lib.rs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int foo(void) { | |
return 42; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_std] | |
use core::ffi::c_int; | |
unsafe extern "C" { | |
safe fn foo() -> c_int; | |
} | |
pub fn bar() { | |
assert_eq!(foo(), 42); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment