Fix rust host with surgical linking

This commit is contained in:
Brendan Hansknecht 2021-09-24 21:37:07 -07:00
parent eae8a2ea37
commit 411ed58eec
16 changed files with 920 additions and 67 deletions

View file

@ -12,12 +12,12 @@ extern "C" {
}
#[no_mangle]
pub unsafe fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
pub unsafe extern "C" fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
return libc::malloc(size);
}
#[no_mangle]
pub unsafe fn roc_realloc(
pub unsafe extern "C" fn roc_realloc(
c_ptr: *mut c_void,
new_size: usize,
_old_size: usize,
@ -27,12 +27,12 @@ pub unsafe fn roc_realloc(
}
#[no_mangle]
pub unsafe fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
pub unsafe extern "C" fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
return libc::free(c_ptr);
}
#[no_mangle]
pub unsafe fn roc_panic(c_ptr: *mut c_void, tag_id: u32) {
pub unsafe extern "C" fn roc_panic(c_ptr: *mut c_void, tag_id: u32) {
match tag_id {
0 => {
let slice = CStr::from_ptr(c_ptr as *const c_char);
@ -45,7 +45,17 @@ pub unsafe fn roc_panic(c_ptr: *mut c_void, tag_id: u32) {
}
#[no_mangle]
pub fn rust_main() -> isize {
pub unsafe extern "C" fn roc_memcpy(dst: *mut c_void, src: *mut c_void, n: usize) -> *mut c_void {
libc::memcpy(dst, src, n)
}
#[no_mangle]
pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut c_void {
libc::memset(dst, c, n)
}
#[no_mangle]
pub extern "C" fn rust_main() -> isize {
unsafe {
let roc_str = roc_main();