Add example of binding C

toolchain_update
WangRunji 7 years ago
parent 7f872901ce
commit 8c7ca612e7

@ -21,6 +21,9 @@ x86_64 = "0.1.2"
once = "0.3.3"
linked_list_allocator = "0.5.0"
[build-dependencies]
cc = "1.0"
[dependencies.lazy_static]
version = "1.0.0"
features = ["spin_no_std"]

@ -0,0 +1,16 @@
extern crate cc;
use std::process::Command;
fn main() {
let output = Command::new("uname").output()
.expect("failed to get uname");
let compiler = match output.stdout.as_slice() {
b"Darwin\n" => "x86_64-elf-gcc",
b"Linux\n" => "gcc",
_ => panic!("unknown os")
};
cc::Build::new()
.compiler(compiler)
.file("src/test.c")
.compile("cobj");
}

@ -46,6 +46,7 @@ mod arch;
#[no_mangle]
pub extern "C" fn rust_main(multiboot_information_address: usize) {
// ATTENTION: we have a very small stack and no guard page
test!(extern_fn);
test!(find_mp);
arch::driver::acpi::init();
@ -80,6 +81,14 @@ pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
static HEAP_ALLOCATOR: LockedHeap = LockedHeap::empty();
mod test {
extern {
fn square(x: u32) -> u32;
}
pub fn extern_fn() {
assert_eq!(unsafe{square(2)}, 4);
}
pub fn global_allocator() {
for i in 0..10000 {
format!("Some String");

@ -0,0 +1,3 @@
int square(int x) {
return x * x;
}
Loading…
Cancel
Save