mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-22 22:46:26 +00:00
generate unsafe extern for Rust to Rust
This commit is contained in:
parent
5f1207ae20
commit
6f15957032
35
csbindgen-tests/build.rs
vendored
35
csbindgen-tests/build.rs
vendored
@ -31,14 +31,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
// .generate()?
|
||||
// .write_to_file("src/quiche.rs")?;
|
||||
|
||||
bindgen::Builder::default()
|
||||
.header("c/bullet3/PhysicsClientC_API.h")
|
||||
.header("c/bullet3/PhysicsClientSharedMemory_C_API.h")
|
||||
.header("c/bullet3/PhysicsClientSharedMemory2_C_API.h")
|
||||
.header("c/bullet3/PhysicsDirectC_API.h")
|
||||
.header("c/bullet3/SharedMemoryPublic.h")
|
||||
.generate()?
|
||||
.write_to_file("src/bullet3.rs")?;
|
||||
// bindgen::Builder::default()
|
||||
// .header("c/bullet3/PhysicsClientC_API.h")
|
||||
// .header("c/bullet3/PhysicsClientSharedMemory_C_API.h")
|
||||
// .header("c/bullet3/PhysicsClientSharedMemory2_C_API.h")
|
||||
// .header("c/bullet3/PhysicsDirectC_API.h")
|
||||
// .header("c/bullet3/SharedMemoryPublic.h")
|
||||
// .generate()?
|
||||
// .write_to_file("src/bullet3.rs")?;
|
||||
|
||||
csbindgen::Builder::default()
|
||||
.input_bindgen_file("src/lz4.rs")
|
||||
@ -71,6 +71,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
// .input_bindgen_file("src/zstd.rs")
|
||||
// .method_filter(|x| x.starts_with("ZSTD_"))
|
||||
// .rust_method_prefix("csbindgen_zstd_")
|
||||
// .rust_file_header("use super::zstd::*;")
|
||||
// .csharp_class_name("LibZstd")
|
||||
// .csharp_dll_name("libzsd")
|
||||
// .generate_to_file("src/zstd_ffi.rs", "../dotnet-sandbox/zstd_bindgen.cs")?;
|
||||
@ -78,19 +79,21 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
// csbindgen::Builder::new()
|
||||
// .input_bindgen_file("src/quiche.rs")
|
||||
// .method_filter(|x| x.starts_with("quiche_"))
|
||||
// .rust_file_header("use super::quiche::*;")
|
||||
// .rust_method_prefix("csbindgen_quiche_")
|
||||
// .csharp_class_name("LibQuiche")
|
||||
// .csharp_dll_name("libquiche")
|
||||
// .generate_to_file("src/quiche_ffi.rs", "../dotnet-sandbox/quiche_bindgen.cs")?;
|
||||
|
||||
csbindgen::Builder::new()
|
||||
.input_bindgen_file("src/bullet3.rs")
|
||||
.method_filter(|x| x.starts_with("b3"))
|
||||
.rust_method_prefix("csbindgen_bullet3_")
|
||||
.csharp_entry_point_prefix("csbindgen_bullet3_")
|
||||
.csharp_class_name("LibBullet3")
|
||||
.csharp_dll_name("libbullet3")
|
||||
.generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
|
||||
// csbindgen::Builder::new()
|
||||
// .input_bindgen_file("src/bullet3.rs")
|
||||
// .method_filter(|x| x.starts_with("b3"))
|
||||
// .rust_file_header("use super::bullet3::*;")
|
||||
// .rust_method_prefix("csbindgen_bullet3_")
|
||||
// .csharp_entry_point_prefix("csbindgen_bullet3_")
|
||||
// .csharp_class_name("LibBullet3")
|
||||
// .csharp_dll_name("libbullet3")
|
||||
// .generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
28
csbindgen-tests/src/bullet3_ffi.rs
vendored
28
csbindgen-tests/src/bullet3_ffi.rs
vendored
@ -3,7 +3,7 @@
|
||||
#[allow(unused)]
|
||||
use ::std::os::raw::*;
|
||||
|
||||
|
||||
use super::bullet3::*;
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
@ -246,10 +246,10 @@ pub unsafe extern "C" fn csbindgen_bullet3_b3GetStatusActualState(
|
||||
bodyUniqueId: *mut c_int,
|
||||
numDegreeOfFreedomQ: *mut c_int,
|
||||
numDegreeOfFreedomU: *mut c_int,
|
||||
rootLocalInertialFrame: *mut *mut f64,
|
||||
actualStateQ: *mut *mut f64,
|
||||
actualStateQdot: *mut *mut f64,
|
||||
jointReactionForces: *mut *mut f64
|
||||
rootLocalInertialFrame: *mut *const f64,
|
||||
actualStateQ: *mut *const f64,
|
||||
actualStateQdot: *mut *const f64,
|
||||
jointReactionForces: *mut *const f64
|
||||
) -> c_int
|
||||
{
|
||||
b3GetStatusActualState(
|
||||
@ -271,14 +271,14 @@ pub unsafe extern "C" fn csbindgen_bullet3_b3GetStatusActualState2(
|
||||
numLinks: *mut c_int,
|
||||
numDegreeOfFreedomQ: *mut c_int,
|
||||
numDegreeOfFreedomU: *mut c_int,
|
||||
rootLocalInertialFrame: *mut *mut f64,
|
||||
actualStateQ: *mut *mut f64,
|
||||
actualStateQdot: *mut *mut f64,
|
||||
jointReactionForces: *mut *mut f64,
|
||||
linkLocalInertialFrames: *mut *mut f64,
|
||||
jointMotorForces: *mut *mut f64,
|
||||
linkStates: *mut *mut f64,
|
||||
linkWorldVelocities: *mut *mut f64
|
||||
rootLocalInertialFrame: *mut *const f64,
|
||||
actualStateQ: *mut *const f64,
|
||||
actualStateQdot: *mut *const f64,
|
||||
jointReactionForces: *mut *const f64,
|
||||
linkLocalInertialFrames: *mut *const f64,
|
||||
jointMotorForces: *mut *const f64,
|
||||
linkStates: *mut *const f64,
|
||||
linkWorldVelocities: *mut *const f64
|
||||
) -> c_int
|
||||
{
|
||||
b3GetStatusActualState2(
|
||||
@ -565,7 +565,7 @@ pub unsafe extern "C" fn csbindgen_bullet3_b3GetUserDataInfo(
|
||||
physClient: b3PhysicsClientHandle,
|
||||
bodyUniqueId: c_int,
|
||||
userDataIndex: c_int,
|
||||
keyOut: *mut *mut c_char,
|
||||
keyOut: *mut *const c_char,
|
||||
userDataIdOut: *mut c_int,
|
||||
linkIndexOut: *mut c_int,
|
||||
visualShapeIndexOut: *mut c_int
|
||||
|
39
csbindgen-tests/src/lib.rs
vendored
39
csbindgen-tests/src/lib.rs
vendored
@ -14,6 +14,45 @@ mod lz4;
|
||||
#[allow(non_camel_case_types)]
|
||||
mod lz4_ffi;
|
||||
|
||||
// #[allow(dead_code)]
|
||||
// #[allow(non_snake_case)]
|
||||
// #[allow(non_camel_case_types)]
|
||||
// #[allow(non_upper_case_globals)]
|
||||
// mod bullet3;
|
||||
|
||||
// #[allow(dead_code)]
|
||||
// #[allow(non_snake_case)]
|
||||
// #[allow(non_camel_case_types)]
|
||||
// mod bullet3_ffi;
|
||||
|
||||
|
||||
// #[allow(dead_code)]
|
||||
// #[allow(non_snake_case)]
|
||||
// #[allow(non_camel_case_types)]
|
||||
// #[allow(non_upper_case_globals)]
|
||||
// mod quiche;
|
||||
|
||||
// #[allow(dead_code)]
|
||||
// #[allow(non_snake_case)]
|
||||
// #[allow(non_camel_case_types)]
|
||||
// mod quiche_ffi;
|
||||
|
||||
|
||||
// #[allow(dead_code)]
|
||||
// #[allow(non_snake_case)]
|
||||
// #[allow(non_camel_case_types)]
|
||||
// #[allow(non_upper_case_globals)]
|
||||
// mod zstd;
|
||||
|
||||
// #[allow(dead_code)]
|
||||
// #[allow(non_snake_case)]
|
||||
// #[allow(non_camel_case_types)]
|
||||
// mod zstd_ffi;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type LONG_PTR = ::std::os::raw::c_longlong;
|
||||
#[allow(non_camel_case_types)]
|
||||
|
28
csbindgen-tests/src/quiche_ffi.rs
vendored
28
csbindgen-tests/src/quiche_ffi.rs
vendored
@ -3,7 +3,7 @@
|
||||
#[allow(unused)]
|
||||
use ::std::os::raw::*;
|
||||
|
||||
|
||||
use super::quiche::*;
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
@ -18,7 +18,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_version(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_enable_debug_logging(
|
||||
cb: Option<extern "C" fn(line: *const c_char, argp: *mut c_void)>,
|
||||
cb: Option<unsafe extern "C" fn(line: *const c_char, argp: *mut c_void)>,
|
||||
argp: *mut c_void
|
||||
) -> c_int
|
||||
{
|
||||
@ -899,7 +899,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_close(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_trace_id(
|
||||
conn: *const quiche_conn,
|
||||
out: *mut *mut u8,
|
||||
out: *mut *const u8,
|
||||
out_len: *mut usize
|
||||
)
|
||||
{
|
||||
@ -913,7 +913,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_trace_id(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_source_id(
|
||||
conn: *const quiche_conn,
|
||||
out: *mut *mut u8,
|
||||
out: *mut *const u8,
|
||||
out_len: *mut usize
|
||||
)
|
||||
{
|
||||
@ -927,7 +927,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_source_id(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_destination_id(
|
||||
conn: *const quiche_conn,
|
||||
out: *mut *mut u8,
|
||||
out: *mut *const u8,
|
||||
out_len: *mut usize
|
||||
)
|
||||
{
|
||||
@ -941,7 +941,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_destination_id(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_application_proto(
|
||||
conn: *const quiche_conn,
|
||||
out: *mut *mut u8,
|
||||
out: *mut *const u8,
|
||||
out_len: *mut usize
|
||||
)
|
||||
{
|
||||
@ -955,7 +955,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_application_proto(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_peer_cert(
|
||||
conn: *const quiche_conn,
|
||||
out: *mut *mut u8,
|
||||
out: *mut *const u8,
|
||||
out_len: *mut usize
|
||||
)
|
||||
{
|
||||
@ -969,7 +969,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_peer_cert(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_session(
|
||||
conn: *const quiche_conn,
|
||||
out: *mut *mut u8,
|
||||
out: *mut *const u8,
|
||||
out_len: *mut usize
|
||||
)
|
||||
{
|
||||
@ -1065,7 +1065,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_peer_error(
|
||||
conn: *const quiche_conn,
|
||||
is_app: *mut bool,
|
||||
error_code: *mut u64,
|
||||
reason: *mut *mut u8,
|
||||
reason: *mut *const u8,
|
||||
reason_len: *mut usize
|
||||
) -> bool
|
||||
{
|
||||
@ -1083,7 +1083,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_local_error(
|
||||
conn: *const quiche_conn,
|
||||
is_app: *mut bool,
|
||||
error_code: *mut u64,
|
||||
reason: *mut *mut u8,
|
||||
reason: *mut *const u8,
|
||||
reason_len: *mut usize
|
||||
) -> bool
|
||||
{
|
||||
@ -1261,7 +1261,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_dgram_send(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_conn_dgram_purge_outgoing(
|
||||
conn: *mut quiche_conn,
|
||||
f: Option<extern "C" fn(arg1: *mut u8, arg2: usize) -> bool>
|
||||
f: Option<unsafe extern "C" fn(arg1: *mut u8, arg2: usize) -> bool>
|
||||
)
|
||||
{
|
||||
quiche_conn_dgram_purge_outgoing(
|
||||
@ -1427,7 +1427,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_h3_event_type(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_h3_event_for_each_header(
|
||||
ev: *mut quiche_h3_event,
|
||||
cb: Option<extern "C" fn(name: *mut u8, name_len: usize, value: *mut u8, value_len: usize, argp: *mut c_void) -> c_int>,
|
||||
cb: Option<unsafe extern "C" fn(name: *mut u8, name_len: usize, value: *mut u8, value_len: usize, argp: *mut c_void) -> c_int>,
|
||||
argp: *mut c_void
|
||||
) -> c_int
|
||||
{
|
||||
@ -1441,7 +1441,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_h3_event_for_each_header(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_h3_for_each_setting(
|
||||
conn: *mut quiche_h3_conn,
|
||||
cb: Option<extern "C" fn(identifier: u64, value: u64, argp: *mut c_void) -> c_int>,
|
||||
cb: Option<unsafe extern "C" fn(identifier: u64, value: u64, argp: *mut c_void) -> c_int>,
|
||||
argp: *mut c_void
|
||||
) -> c_int
|
||||
{
|
||||
@ -1614,7 +1614,7 @@ pub unsafe extern "C" fn csbindgen_quiche_quiche_h3_send_priority_update_for_req
|
||||
pub unsafe extern "C" fn csbindgen_quiche_quiche_h3_take_last_priority_update(
|
||||
conn: *mut quiche_h3_conn,
|
||||
prioritized_element_id: u64,
|
||||
cb: Option<extern "C" fn(priority_field_value: *mut u8, priority_field_value_len: u64, argp: *mut c_void) -> c_int>,
|
||||
cb: Option<unsafe extern "C" fn(priority_field_value: *mut u8, priority_field_value_len: u64, argp: *mut c_void) -> c_int>,
|
||||
argp: *mut c_void
|
||||
) -> c_int
|
||||
{
|
||||
|
2
csbindgen-tests/src/zstd_ffi.rs
vendored
2
csbindgen-tests/src/zstd_ffi.rs
vendored
@ -3,7 +3,7 @@
|
||||
#[allow(unused)]
|
||||
use ::std::os::raw::*;
|
||||
|
||||
|
||||
use super::zstd::*;
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -349,7 +349,7 @@ fn parse_type(t: &syn::Type) -> RustType {
|
||||
};
|
||||
|
||||
return RustType {
|
||||
type_name: "extern \"C\" fn".to_string(),
|
||||
type_name: "unsafe extern \"C\" fn".to_string(),
|
||||
type_kind: TypeKind::Function(parameters, ret),
|
||||
};
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ impl RustType {
|
||||
ConstPointerPointer => sb.push_str("*const *const"),
|
||||
MutPointerPointer => sb.push_str("*mut *mut"),
|
||||
ConstMutPointerPointer =>sb.push_str("*const *mut"),
|
||||
MutConstPointerPointer =>sb.push_str("*mut *mut"),
|
||||
MutConstPointerPointer =>sb.push_str("*mut *const"),
|
||||
};
|
||||
}
|
||||
|
||||
|
3
dotnet-sandbox/Program.cs
vendored
3
dotnet-sandbox/Program.cs
vendored
@ -14,10 +14,11 @@ using System.Text;
|
||||
unsafe
|
||||
{
|
||||
|
||||
LibRust.call_bindgen_lz4();
|
||||
|
||||
LibRust.alias_test1(null);
|
||||
|
||||
//LibRust.call_bindgen_lz4();
|
||||
|
||||
|
||||
|
||||
// C# -> Rust, pass static UnmanagedCallersOnly method with `&`
|
||||
|
Loading…
Reference in New Issue
Block a user