-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.rs
More file actions
44 lines (43 loc) · 1.64 KB
/
build.rs
File metadata and controls
44 lines (43 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fn main() {
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
.clang_args([
"-Iinclude",
"-Iinclude/badgelib",
"-Icpu/riscv64/include",
"-Wno-unknown-attributes",
"-DBADGEROS_KERNEL",
])
// Fix: For some reason, `malloc` and `realloc` specifically do not use `usize`.
.blocklist_function("malloc")
.blocklist_function("realloc")
.blocklist_function("calloc")
.raw_line(
"use core::ffi::{c_char, c_void};
unsafe extern \"C\" {
pub fn malloc(_: usize) -> *mut c_void;
pub fn calloc(_: usize, _: usize) -> *mut c_void;
pub fn realloc(_: *mut c_void, _: usize) -> *mut c_void;
pub fn memset(dest: *mut c_void, val: u8, size: usize);
pub fn memcpy(dest: *mut c_void, src: *const c_void, size: usize);
pub fn strlen(cstr: *const c_char) -> usize;
}",
)
// The input header we would like to generate
// bindings for.
.header("include/rust_bindgen_wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Use core, not std.
.use_core()
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
bindings
.write_to_file("target/bindings.rs")
.expect("Couldn't write bindings!");
}