diff --git a/Cargo.toml b/Cargo.toml index a60b1f6..bda48be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..2a620ec --- /dev/null +++ b/build.rs @@ -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"); +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1d6c0f0..3bf377c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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"); diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..59c6fdf --- /dev/null +++ b/src/test.c @@ -0,0 +1,3 @@ +int square(int x) { + return x * x; +} \ No newline at end of file