csbindgen/csbindgen-tests/src/lib.rs

96 lines
2.1 KiB
Rust
Raw Normal View History

2023-02-28 05:49:04 +00:00
#[allow(dead_code)]
#[allow(non_snake_case)]
#[allow(non_camel_case_types)]
#[allow(non_upper_case_globals)]
mod lz4;
2023-02-26 18:31:44 +00:00
2023-02-27 23:08:46 +00:00
#[allow(dead_code)]
#[allow(non_snake_case)]
#[allow(non_camel_case_types)]
mod lz4_ffi;
2023-02-26 18:31:44 +00:00
2023-02-28 05:49:04 +00:00
#[no_mangle]
pub extern "C" fn my_add(x: i32, y: i32) -> i32 {
x + y
}
#[no_mangle]
2023-03-04 05:39:45 +00:00
pub extern "C" fn my_bool(
x: bool,
y: bool,
z: bool,
xr: *mut bool,
yr: *mut bool,
zr: *mut bool,
) -> bool {
unsafe {
*xr = x;
*yr = y;
*zr = z;
}
2023-03-04 05:39:45 +00:00
true
}
2023-03-04 05:54:48 +00:00
// #[no_mangle]
// pub unsafe extern "C" fn new(x: *mut *mut Vec<u8>) {
// let v = Box::new(Vec::new());
// *x = Box::into_raw(v);
// }
2023-03-04 05:39:45 +00:00
#[no_mangle]
pub unsafe extern "C" fn unsafe_return_string() -> *const u8 {
2023-03-04 05:54:48 +00:00
todo!();
2023-03-04 05:39:45 +00:00
}
#[no_mangle]
pub unsafe extern "C" fn unsafe_return_string2() -> *const u8 {
todo!();
}
#[no_mangle]
pub extern "C" fn unsafe_destroy_string(s: *mut String) {
unsafe { Box::from_raw(s) };
}
2023-03-04 05:54:48 +00:00
#[no_mangle]
pub extern "C" fn create_context() -> *mut Context {
let ctx = Box::new(Context { foo: true });
Box::into_raw(ctx)
}
#[no_mangle]
pub extern "C" fn delete_context(context: *mut Context) {
unsafe { Box::from_raw(context) };
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Context {
pub foo: bool,
}
2023-02-27 22:18:10 +00:00
#[test]
fn build_test() {
2023-02-28 05:49:04 +00:00
// let path = std::env::current_dir().unwrap();
// println!("starting dir: {}", path.display()); // csbindgen/csbindgen-tests
2023-02-26 18:31:44 +00:00
2023-02-28 05:49:04 +00:00
// // unsafe {
// // let num = lz4::LZ4_versionNumber();
// // println!("lz4 num: {}", num);
// // }
2023-02-26 18:31:44 +00:00
2023-02-28 05:49:04 +00:00
// csbindgen::Builder::default()
// .input_bindgen_file("src/lz4.rs")
// .rust_method_prefix("csbindgen_")
// .rust_file_header("use super::lz4;")
// .rust_method_type_path("lz4")
// .csharp_class_name("LibLz4")
// .csharp_dll_name("csbindgen_tests")
// .csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal")
// .csharp_entry_point_prefix("csbindgen_")
// .csharp_method_prefix("")
// .generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs")
// .unwrap();
2023-02-26 18:31:44 +00:00
}