Skip to content

Instantly share code, notes, and snippets.

@madsmtm
Created March 28, 2025 08:26
Show Gist options
  • Save madsmtm/3c53305b58624ee8251a38b709db6412 to your computer and use it in GitHub Desktop.
Save madsmtm/3c53305b58624ee8251a38b709db6412 to your computer and use it in GitHub Desktop.
Minimal `cc-rs` `#![no_std]` example
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=foo.c");
cc::Build::new().file("foo.c").compile("foo");
}
[package]
name = "example"
version = "0.1.0"
edition = "2021"
publish = false
[build-dependencies]
cc = "1.2.17"
[lib]
path = "lib.rs"
int foo(void) {
return 42;
}
#![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