This commit is contained in:
neuecc 2023-02-28 14:49:04 +09:00
parent f7aba95ada
commit a550205058
12 changed files with 2651 additions and 128 deletions

View File

@ -3,14 +3,20 @@ use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
bindgen::Builder::default()
.header("c/lz4/lz4.h")
//.header("c/lz4/lz4hc.h")
//.header("c/lz4/lz4frame.h")
//.header("c/lz4/xxhash.h")
.header("c/lz4/lz4hc.h")
.header("c/lz4/lz4frame.h")
.header("c/lz4/xxhash.h")
.generate()?
.write_to_file("src/lz4.rs")?;
// TODO:build this
cc::Build::new().file("c/lz4/lz4.c").compile("lz4");
cc::Build::new()
.files([
"c/lz4/lz4.c",
"c/lz4/lz4hc.c",
"c/lz4/lz4frame.c",
"c/lz4/xxhash.c",
])
.compile("lz4");
// bindgen::Builder::default()
// .header("c/zstd/zstd.h")
@ -31,7 +37,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// .generate()?
// .write_to_file("src/bullet3.rs")?;
csbindgen::Builder::new()
csbindgen::Builder::default()
.input_bindgen_file("src/lz4.rs")
.rust_method_prefix("csbindgen_")
.rust_file_header("use super::lz4;")
@ -43,6 +49,12 @@ fn main() -> Result<(), Box<dyn Error>> {
.csharp_method_prefix("")
.generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs")?;
csbindgen::Builder::default()
.input_extern_file("src/lib.rs")
.csharp_class_name("LibRust")
.csharp_dll_name("csbindgen_tests")
.generate_csharp_file("../dotnet-sandbox/method_call.cs")?;
// csbindgen::Builder::new()
// .input_bindgen_file("src/zstd.rs")
// .rust_method_prefix("csbindgen_zstd_")

View File

@ -9,21 +9,31 @@
#[allow(non_camel_case_types)]
mod lz4_ffi;
#[no_mangle]
pub extern "C" fn my_add(x: i32, y: i32) -> i32 {
x + y
}
#[test]
fn build_test() {
let path = std::env::current_dir().unwrap();
println!("starting dir: {}", path.display()); // csbindgen/csbindgen-tests
// let path = std::env::current_dir().unwrap();
// println!("starting dir: {}", path.display()); // csbindgen/csbindgen-tests
// unsafe {
// let num = lz4::LZ4_versionNumber();
// println!("lz4 num: {}", num);
// }
// // unsafe {
// // let num = lz4::LZ4_versionNumber();
// // println!("lz4 num: {}", num);
// // }
csbindgen::Builder::new()
.input_bindgen_file("src/quiche.rs")
.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")
.unwrap();
// 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();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@ use std::{
path::Path,
};
use crate::generate;
use crate::{generate, GenerateKind};
pub struct Builder {
options: BindgenOptions,
@ -13,6 +13,7 @@ pub struct Builder {
pub struct BindgenOptions {
pub input_bindgen_file: String,
pub input_extern_file: String,
pub method_filter: fn(method_name: String) -> bool,
pub rust_method_type_path: String,
pub rust_method_prefix: String,
@ -28,12 +29,13 @@ pub struct BindgenOptions {
pub csharp_if_dll_name: String,
}
impl Builder {
pub fn new() -> Self {
impl Default for Builder {
fn default() -> Self {
Self {
options: BindgenOptions {
input_bindgen_file: "".to_string(),
method_filter: |x| !x.starts_with("_"),
input_extern_file: "".to_string(),
method_filter: |x| !x.starts_with('_'),
rust_method_type_path: "".to_string(),
rust_method_prefix: "".to_string(),
rust_file_header: "".to_string(),
@ -49,6 +51,12 @@ impl Builder {
},
}
}
}
impl Builder {
pub fn new() -> Self {
Self::default()
}
/// Change an input .rs file(such as generated from bindgen) to generate binding.
pub fn input_bindgen_file<T: Into<String>>(mut self, input_bindgen_file: T) -> Builder {
@ -56,7 +64,13 @@ impl Builder {
self
}
/// Filter generate method callback, default is `!x.starts_with("_")`
/// Change an input .rs file for collect extern methods to C# binding.
pub fn input_extern_file<T: Into<String>>(mut self, input_extern_file: T) -> Builder {
self.options.input_extern_file = input_extern_file.into();
self
}
/// Filter generate method callback, default is `!x.starts_with('_')`
pub fn method_filter(mut self, method_filter: fn(method_name: String) -> bool) -> Builder {
self.options.method_filter = method_filter;
self
@ -141,35 +155,63 @@ impl Builder {
self
}
// pub fn generate_csharp_file<T: AsRef<Path>>(&self, csharp_output_path: T) -> io::Result<()> {
// let mut file = OpenOptions::new()
// .write(true)
// .truncate(true)
// .create(true)
// .open(csharp_output_path.as_ref())?;
pub fn generate_csharp_file<P: AsRef<Path>>(
&self,
csharp_output_path: P,
) -> Result<(), Box<dyn Error>> {
if !self.options.input_bindgen_file.is_empty() {
let (_, csharp) = generate(GenerateKind::InputBindgen, &self.options)?;
// let code = self.generate();
// file.write_all(code.as_bytes())?;
// file.flush()?;
let mut csharp_file = make_file(csharp_output_path.as_ref())?;
csharp_file.write_all(csharp.as_bytes())?;
csharp_file.flush()?;
}
// Ok(())
// }
if !self.options.input_extern_file.is_empty() {
let (_, csharp) = generate(GenerateKind::InputExtern, &self.options)?;
let mut csharp_file = make_file(csharp_output_path.as_ref())?;
csharp_file.write_all(csharp.as_bytes())?;
csharp_file.flush()?;
}
Ok(())
}
pub fn generate_to_file<P: AsRef<Path>>(
&self,
rust_output_path: P,
csharp_output_path: P,
) -> Result<(), Box<dyn Error>> {
let (rust, csharp) = generate(&self.options)?;
if !self.options.input_bindgen_file.is_empty() {
let (rust, csharp) = generate(GenerateKind::InputBindgen, &self.options)?;
let mut rust_file = make_file(rust_output_path)?;
let mut csharp_file = make_file(csharp_output_path)?;
if let Some(rust) = rust {
let mut rust_file = make_file(rust_output_path.as_ref())?;
rust_file.write_all(rust.as_bytes())?;
rust_file.flush()?;
}
let mut csharp_file = make_file(csharp_output_path.as_ref())?;
csharp_file.write_all(csharp.as_bytes())?;
csharp_file.flush()?;
}
if !self.options.input_extern_file.is_empty() {
let (rust, csharp) = generate(GenerateKind::InputExtern, &self.options)?;
if let Some(rust) = rust {
let mut rust_file = make_file(rust_output_path.as_ref())?;
rust_file.write_all(rust.as_bytes())?;
rust_file.flush()?;
}
let mut csharp_file = make_file(csharp_output_path.as_ref())?;
csharp_file.write_all(csharp.as_bytes())?;
csharp_file.flush()?;
}
Ok(())
}

View File

@ -74,7 +74,7 @@ use ::std::os::raw::*;
"
);
return result;
result
}
pub fn emit_csharp(
@ -107,14 +107,14 @@ pub fn emit_csharp(
x => format!("{x}{method_name}"),
};
let return_type = match &item.return_type {
Some(x) => x.to_csharp_string(&options, &aliases),
Some(x) => x.to_csharp_string(options, aliases),
None => "void".to_string(),
};
let parameters = item
.parameters
.iter()
.map(|p| format!("{} {}", p.rust_type.to_csharp_string(&options, &aliases), p.escape_name()))
.map(|p| format!("{} {}", p.rust_type.to_csharp_string(options, aliases), p.escape_name()))
.collect::<Vec<_>>()
.join(", ");
@ -124,7 +124,7 @@ pub fn emit_csharp(
method_list_string.push_str_ln(
format!(" public static extern {return_type} {method_prefix}{method_name}({parameters});").as_str(),
);
method_list_string.push_str("\n");
method_list_string.push('\n');
}
let mut structs_string = String::new();
@ -147,7 +147,7 @@ pub fn emit_csharp(
structs_string.push_str(
format!(
" public {} {}",
field.rust_type.to_csharp_string(&options, &aliases),
field.rust_type.to_csharp_string(options, aliases),
field.name
)
.as_str(),
@ -163,7 +163,7 @@ pub fn emit_csharp(
structs_string.push_str_ln(";");
}
structs_string.push_str_ln(" }");
structs_string.push_str("\n");
structs_string.push('\n');
}
// TODO: for Unity, `__Intern`.
@ -189,5 +189,5 @@ namespace {namespace}
"
);
return result;
result
}

View File

@ -11,12 +11,26 @@ use emitter::*;
use parser::*;
use std::{collections::HashSet, error::Error};
pub(crate) fn generate(options: &BindgenOptions) -> Result<(String, String), Box<dyn Error>> {
let path = &options.input_bindgen_file;
let file_content = std::fs::read_to_string(path)?;
enum GenerateKind {
InputBindgen,
InputExtern,
}
pub(crate) fn generate(
generate_kind: GenerateKind,
options: &BindgenOptions,
) -> Result<(Option<String>, String), Box<dyn Error>> {
let path = match generate_kind{
GenerateKind::InputBindgen => &options.input_bindgen_file,
GenerateKind::InputExtern => &options.input_extern_file,
};
let file_content = std::fs::read_to_string(path).expect(("input file not found, path:".to_string() + path).as_str());
let file_ast = syn::parse_file(file_content.as_str())?;
let methods = collect_method(&file_ast, options);
let (methods, generate_rust) = match generate_kind {
GenerateKind::InputBindgen => (collect_foreign_method(&file_ast, options), true),
GenerateKind::InputExtern => (collect_extern_method(&file_ast, options), false),
};
let aliases = collect_type_alias(&file_ast);
let structs = collect_struct(&file_ast);
@ -42,10 +56,14 @@ pub(crate) fn generate(options: &BindgenOptions) -> Result<(String, String), Box
let structs = reduce_struct(&structs, &using_types);
let rust = emit_rust_method(&methods, &options);
let csharp = emit_csharp(&methods, &aliases, &structs, &options);
let rust = if generate_rust {
Some(emit_rust_method(&methods, options))
} else {
None
};
let csharp = emit_csharp(&methods, &aliases, &structs, options);
return Ok((rust, csharp));
Ok((rust, csharp))
}
// #[test]

View File

@ -2,20 +2,60 @@ use crate::{builder::BindgenOptions, type_meta::*};
use std::collections::{HashMap, HashSet};
use syn::{ForeignItem, Item, Pat, ReturnType};
pub fn collect_method(ast: &syn::File, options: &BindgenOptions) -> Vec<ExternMethod> {
enum FnItem {
ForeignItem(syn::ForeignItemFn),
Item(syn::ItemFn),
}
pub fn collect_foreign_method(ast: &syn::File, options: &BindgenOptions) -> Vec<ExternMethod> {
let mut list: Vec<ExternMethod> = Vec::new();
for item in ast.items.iter() {
if let Item::ForeignMod(m) = item {
for item in m.items.iter() {
if let ForeignItem::Fn(m) = item {
let method_name = m.sig.ident.to_string();
let method = parse_method(FnItem::ForeignItem(m.clone()), options);
if let Some(x) = method {
list.push(x);
}
}
}
}
}
list
}
pub fn collect_extern_method(ast: &syn::File, options: &BindgenOptions) -> Vec<ExternMethod> {
let mut list: Vec<ExternMethod> = Vec::new();
for item in ast.items.iter() {
if let Item::Fn(m) = item {
if let Some(_) = &m.sig.abi { // has extern
let method = parse_method(FnItem::Item(m.clone()), options);
if let Some(x) = method {
list.push(x);
}
}
}
}
list
}
fn parse_method(item: FnItem, options: &BindgenOptions) -> Option<ExternMethod> {
let sig = match item {
FnItem::ForeignItem(x) => x.sig,
FnItem::Item(x) => x.sig,
};
let method_name = sig.ident.to_string();
let mut parameters: Vec<Parameter> = Vec::new();
let mut retrun_type: Option<RustType> = None;
let mut return_type: Option<RustType> = None;
// argument
for arg in m.sig.inputs.iter() {
for arg in sig.inputs.iter() {
if let syn::FnArg::Typed(t) = arg {
let mut parameter_name: String = "".to_string();
@ -27,34 +67,30 @@ pub fn collect_method(ast: &syn::File, options: &BindgenOptions) -> Vec<ExternMe
parameters.push(Parameter {
name: parameter_name,
rust_type: rust_type,
rust_type,
});
}
}
// return
if let ReturnType::Type(_, b) = &m.sig.output {
let rust_type = parse_type(&b);
if rust_type.type_name == "" {
continue;
if let ReturnType::Type(_, b) = &sig.output {
let rust_type = parse_type(b);
if rust_type.type_name.is_empty() {
return None;
}
retrun_type = Some(rust_type);
return_type = Some(rust_type);
}
if method_name != "" && (&options.method_filter)(method_name.clone()) {
list.push(ExternMethod {
method_name: method_name.clone(),
parameters: parameters,
return_type: retrun_type,
if !method_name.is_empty() && (options.method_filter)(method_name.clone()) {
return Some(ExternMethod {
method_name,
parameters,
return_type,
});
}
}
}
}
}
return list;
None
}
pub fn collect_type_alias(ast: &syn::File) -> Vec<(String, RustType)> {
@ -85,7 +121,7 @@ pub fn collect_type_alias(ast: &syn::File) -> Vec<(String, RustType)> {
}
}
}
return result;
result
}
pub fn collect_struct(ast: &syn::File) -> Vec<RustStruct> {
@ -94,28 +130,28 @@ pub fn collect_struct(ast: &syn::File) -> Vec<RustStruct> {
for item in ast.items.iter() {
if let Item::Union(t) = item {
let name = t.ident.to_string();
let struct_name = t.ident.to_string();
let fields = collect_fields(&t.fields);
result.push(RustStruct {
struct_name: name,
fields: fields,
struct_name,
fields,
is_union: true,
});
} else if let Item::Struct(t) = item {
if let syn::Fields::Named(f) = &t.fields {
let name = t.ident.to_string();
let fields = collect_fields(&f);
let struct_name = t.ident.to_string();
let fields = collect_fields(f);
result.push(RustStruct {
struct_name: name,
fields: fields,
struct_name,
fields,
is_union: false,
});
};
}
}
return result;
result
}
fn collect_fields(fields: &syn::FieldsNamed) -> Vec<FieldMember> {
@ -131,7 +167,7 @@ fn collect_fields(fields: &syn::FieldsNamed) -> Vec<FieldMember> {
}
}
return result;
result
}
pub fn reduce_type_alias(
@ -152,7 +188,7 @@ pub fn reduce_type_alias(
}
}
return map;
map
}
pub fn reduce_struct(structs: &Vec<RustStruct>, using_types: &HashSet<String>) -> Vec<RustStruct> {
@ -163,7 +199,7 @@ pub fn reduce_struct(structs: &Vec<RustStruct>, using_types: &HashSet<String>) -
}
}
return result;
result
}
fn parse_type(t: &syn::Type) -> RustType {
@ -206,13 +242,13 @@ fn parse_type(t: &syn::Type) -> RustType {
_ => "".to_string(),
};
return RustType {
RustType {
is_const: has_const,
is_mut: has_mut,
is_pointer: has_star,
is_pointer_pointer: has_star_star,
is_fixed_array: (digits != ""),
is_fixed_array: !digits.is_empty(),
type_name: name,
fixed_array_digits: digits,
};
}
}

View File

@ -64,7 +64,7 @@ impl RustType {
let mut sb = String::new();
if self.is_pointer || self.is_pointer_pointer {
sb.push_str("*");
sb.push('*');
}
if self.is_const {
sb.push_str("const");
@ -80,18 +80,19 @@ impl RustType {
}
}
sb.push_str(" ");
sb.push(' ');
if self.is_fixed_array {
sb.push_str("[");
sb.push('[');
sb.push_str(self.type_name.as_str());
sb.push_str("; ");
sb.push_str(self.fixed_array_digits.as_str());
sb.push_str("]");
sb.push(']');
} else {
if !self.type_name.starts_with("c_")
&& !(self.type_name == "usize" || self.type_name == "isize")
&& !(type_path == "")
if !(self.type_name.starts_with("c_")
|| self.type_name == "usize"
|| self.type_name == "isize"
|| (type_path.is_empty()))
{
sb.push_str(type_path);
sb.push_str("::");
@ -157,7 +158,7 @@ impl RustType {
if self.is_fixed_array {
sb.push_str("fixed ");
let type_name = convert_type_name(use_type.type_name.as_str(), &options);
let type_name = convert_type_name(use_type.type_name.as_str(), options);
let type_name = match type_name.as_str() {
// C# fixed allow types
"bool" | "byte" | "short" | "int" | "long" | "char" | "sbyte" | "ushort"
@ -167,10 +168,10 @@ impl RustType {
sb.push_str(type_name.as_str());
} else {
sb.push_str(convert_type_name(use_type.type_name.as_str(), &options).as_str());
sb.push_str(convert_type_name(use_type.type_name.as_str(), options).as_str());
if use_alias {
if use_type.is_pointer {
sb.push_str("*");
sb.push('*');
}
if use_type.is_pointer_pointer {
sb.push_str("**");
@ -178,7 +179,7 @@ impl RustType {
}
if self.is_pointer {
sb.push_str("*");
sb.push('*');
}
if self.is_pointer_pointer {
sb.push_str("**");

View File

@ -7,6 +7,9 @@ unsafe
{
//var v = NativeMethods();
var z = LibRust.my_add(100, 200);
Console.WriteLine(z);
var s = LibLz4.LZ4_versionString();
var ss = new string((sbyte*)s);
Console.WriteLine(ss);

View File

@ -142,6 +142,210 @@ namespace CsBindgen
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStream", CallingConvention = CallingConvention.Cdecl)]
public static extern void LZ4_resetStream(LZ4_stream_u* streamPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compress_HC(byte* src, byte* dst, int srcSize, int dstCapacity, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_sizeofStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_sizeofStateHC();
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_extStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compress_HC_extStateHC(void* stateHC, byte* src, byte* dst, int srcSize, int maxDstSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_destSize", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compress_HC_destSize(void* stateHC, byte* src, byte* dst, int* srcSizePtr, int targetDstSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_createStreamHC", CallingConvention = CallingConvention.Cdecl)]
public static extern LZ4_streamHC_u* LZ4_createStreamHC();
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_freeStreamHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_freeStreamHC(LZ4_streamHC_u* streamHCPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStreamHC_fast", CallingConvention = CallingConvention.Cdecl)]
public static extern void LZ4_resetStreamHC_fast(LZ4_streamHC_u* streamHCPtr, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_loadDictHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_loadDictHC(LZ4_streamHC_u* streamHCPtr, byte* dictionary, int dictSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_continue", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compress_HC_continue(LZ4_streamHC_u* streamHCPtr, byte* src, byte* dst, int srcSize, int maxDstSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compress_HC_continue_destSize", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compress_HC_continue_destSize(LZ4_streamHC_u* LZ4_streamHCPtr, byte* src, byte* dst, int* srcSizePtr, int targetDstSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_saveDictHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_saveDictHC(LZ4_streamHC_u* streamHCPtr, byte* safeBuffer, int maxDictSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_initStreamHC", CallingConvention = CallingConvention.Cdecl)]
public static extern LZ4_streamHC_u* LZ4_initStreamHC(void* buffer, UIntPtr size);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC(byte* source, byte* dest, int inputSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_limitedOutput", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC_limitedOutput(byte* source, byte* dest, int inputSize, int maxOutputSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC2(byte* source, byte* dest, int inputSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_limitedOutput", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC2_limitedOutput(byte* source, byte* dest, int inputSize, int maxOutputSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_withStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC_withStateHC(void* state, byte* source, byte* dest, int inputSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_limitedOutput_withStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC_limitedOutput_withStateHC(void* state, byte* source, byte* dest, int inputSize, int maxOutputSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_withStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC2_withStateHC(void* state, byte* source, byte* dest, int inputSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_limitedOutput_withStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC2_limitedOutput_withStateHC(void* state, byte* source, byte* dest, int inputSize, int maxOutputSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_continue", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC_continue(LZ4_streamHC_u* LZ4_streamHCPtr, byte* source, byte* dest, int inputSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC_limitedOutput_continue", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC_limitedOutput_continue(LZ4_streamHC_u* LZ4_streamHCPtr, byte* source, byte* dest, int inputSize, int maxOutputSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_createHC", CallingConvention = CallingConvention.Cdecl)]
public static extern void* LZ4_createHC(byte* inputBuffer);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_freeHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_freeHC(void* LZ4HC_Data);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_slideInputBufferHC", CallingConvention = CallingConvention.Cdecl)]
public static extern byte* LZ4_slideInputBufferHC(void* LZ4HC_Data);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_continue", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC2_continue(void* LZ4HC_Data, byte* source, byte* dest, int inputSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_compressHC2_limitedOutput_continue", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_compressHC2_limitedOutput_continue(void* LZ4HC_Data, byte* source, byte* dest, int inputSize, int maxOutputSize, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_sizeofStreamStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_sizeofStreamStateHC();
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStreamStateHC", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4_resetStreamStateHC(void* state, byte* inputBuffer);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_resetStreamHC", CallingConvention = CallingConvention.Cdecl)]
public static extern void LZ4_resetStreamHC(LZ4_streamHC_u* streamHCPtr, int compressionLevel);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_isError", CallingConvention = CallingConvention.Cdecl)]
public static extern uint LZ4F_isError(UIntPtr code);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_getErrorName", CallingConvention = CallingConvention.Cdecl)]
public static extern byte* LZ4F_getErrorName(UIntPtr code);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressionLevel_max", CallingConvention = CallingConvention.Cdecl)]
public static extern int LZ4F_compressionLevel_max();
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressFrameBound", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_compressFrameBound(UIntPtr srcSize, LZ4F_preferences_t* preferencesPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressFrame", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_compressFrame(void* dstBuffer, UIntPtr dstCapacity, void* srcBuffer, UIntPtr srcSize, LZ4F_preferences_t* preferencesPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_getVersion", CallingConvention = CallingConvention.Cdecl)]
public static extern uint LZ4F_getVersion();
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_createCompressionContext", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_createCompressionContext(LZ4F_cctx_s** cctxPtr, uint version);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_freeCompressionContext", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_freeCompressionContext(LZ4F_cctx_s* cctx);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressBegin", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_compressBegin(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_preferences_t* prefsPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressBound", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_compressBound(UIntPtr srcSize, LZ4F_preferences_t* prefsPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressUpdate", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_compressUpdate(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, void* srcBuffer, UIntPtr srcSize, LZ4F_compressOptions_t* cOptPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_flush", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_flush(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_compressOptions_t* cOptPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_compressEnd", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_compressEnd(LZ4F_cctx_s* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_compressOptions_t* cOptPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_createDecompressionContext", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_createDecompressionContext(LZ4F_dctx_s** dctxPtr, uint version);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_freeDecompressionContext", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_freeDecompressionContext(LZ4F_dctx_s* dctx);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_headerSize", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_headerSize(void* src, UIntPtr srcSize);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_getFrameInfo", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_getFrameInfo(LZ4F_dctx_s* dctx, LZ4F_frameInfo_t* frameInfoPtr, void* srcBuffer, UIntPtr* srcSizePtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_decompress", CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr LZ4F_decompress(LZ4F_dctx_s* dctx, void* dstBuffer, UIntPtr* dstSizePtr, void* srcBuffer, UIntPtr* srcSizePtr, LZ4F_decompressOptions_t* dOptPtr);
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4F_resetDecompressionContext", CallingConvention = CallingConvention.Cdecl)]
public static extern void LZ4F_resetDecompressionContext(LZ4F_dctx_s* dctx);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH_versionNumber", CallingConvention = CallingConvention.Cdecl)]
public static extern uint XXH_versionNumber();
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32", CallingConvention = CallingConvention.Cdecl)]
public static extern uint XXH32(void* input, UIntPtr length, uint seed);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_createState", CallingConvention = CallingConvention.Cdecl)]
public static extern XXH32_state_s* XXH32_createState();
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_freeState", CallingConvention = CallingConvention.Cdecl)]
public static extern int XXH32_freeState(XXH32_state_s* statePtr);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_copyState", CallingConvention = CallingConvention.Cdecl)]
public static extern void XXH32_copyState(XXH32_state_s* dst_state, XXH32_state_s* src_state);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_reset", CallingConvention = CallingConvention.Cdecl)]
public static extern int XXH32_reset(XXH32_state_s* statePtr, uint seed);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_update", CallingConvention = CallingConvention.Cdecl)]
public static extern int XXH32_update(XXH32_state_s* statePtr, void* input, UIntPtr length);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_digest", CallingConvention = CallingConvention.Cdecl)]
public static extern uint XXH32_digest(XXH32_state_s* statePtr);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_canonicalFromHash", CallingConvention = CallingConvention.Cdecl)]
public static extern void XXH32_canonicalFromHash(XXH32_canonical_t* dst, uint hash);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH32_hashFromCanonical", CallingConvention = CallingConvention.Cdecl)]
public static extern uint XXH32_hashFromCanonical(XXH32_canonical_t* src);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64", CallingConvention = CallingConvention.Cdecl)]
public static extern ulong XXH64(void* input, UIntPtr length, ulong seed);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_createState", CallingConvention = CallingConvention.Cdecl)]
public static extern XXH64_state_s* XXH64_createState();
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_freeState", CallingConvention = CallingConvention.Cdecl)]
public static extern int XXH64_freeState(XXH64_state_s* statePtr);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_copyState", CallingConvention = CallingConvention.Cdecl)]
public static extern void XXH64_copyState(XXH64_state_s* dst_state, XXH64_state_s* src_state);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_reset", CallingConvention = CallingConvention.Cdecl)]
public static extern int XXH64_reset(XXH64_state_s* statePtr, ulong seed);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_update", CallingConvention = CallingConvention.Cdecl)]
public static extern int XXH64_update(XXH64_state_s* statePtr, void* input, UIntPtr length);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_digest", CallingConvention = CallingConvention.Cdecl)]
public static extern ulong XXH64_digest(XXH64_state_s* statePtr);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_canonicalFromHash", CallingConvention = CallingConvention.Cdecl)]
public static extern void XXH64_canonicalFromHash(XXH64_canonical_t* dst, ulong hash);
[DllImport(__DllName, EntryPoint = "csbindgen_XXH64_hashFromCanonical", CallingConvention = CallingConvention.Cdecl)]
public static extern ulong XXH64_hashFromCanonical(XXH64_canonical_t* src);
}
@ -183,6 +387,106 @@ namespace CsBindgen
public LZ4_streamDecode_t_internal internal_donotuse;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct LZ4HC_CCtx_internal
{
public fixed uint hashTable[32768];
public fixed ushort chainTable[65536];
public byte* end;
public byte* prefixStart;
public byte* dictStart;
public uint dictLimit;
public uint lowLimit;
public uint nextToUpdate;
public short compressionLevel;
public sbyte favorDecSpeed;
public sbyte dirty;
public LZ4HC_CCtx_internal* dictCtx;
}
[StructLayout(LayoutKind.Explicit)]
public unsafe struct LZ4_streamHC_u
{
[FieldOffset(0)]
public fixed byte minStateSize[262200];
[FieldOffset(0)]
public LZ4HC_CCtx_internal internal_donotuse;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct LZ4F_frameInfo_t
{
public int blockSizeID;
public int blockMode;
public int contentChecksumFlag;
public int frameType;
public ulong contentSize;
public uint dictID;
public int blockChecksumFlag;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct LZ4F_preferences_t
{
public LZ4F_frameInfo_t frameInfo;
public int compressionLevel;
public uint autoFlush;
public uint favorDecSpeed;
public fixed uint reserved[3];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct LZ4F_cctx_s
{
public fixed byte _unused[1];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct LZ4F_compressOptions_t
{
public uint stableSrc;
public fixed uint reserved[3];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct LZ4F_dctx_s
{
public fixed byte _unused[1];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct LZ4F_decompressOptions_t
{
public uint stableDst;
public uint skipChecksums;
public uint reserved1;
public uint reserved0;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct XXH32_state_s
{
public fixed byte _unused[1];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct XXH32_canonical_t
{
public fixed byte digest[4];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct XXH64_state_s
{
public fixed byte _unused[1];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct XXH64_canonical_t
{
public fixed byte digest[8];
}
}

View File

@ -0,0 +1,22 @@
// <auto-generated>
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
using System;
using System.Runtime.InteropServices;
namespace CsBindgen
{
public static unsafe partial class LibRust
{
const string __DllName = "csbindgen_tests";
[DllImport(__DllName, EntryPoint = "my_add", CallingConvention = CallingConvention.Cdecl)]
public static extern int my_add(int x, int y);
}
}