mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
feat: add extra namespaces to the exported file
This commit is contained in:
parent
e9071f3bd5
commit
8a837b8973
@ -29,6 +29,7 @@ pub struct BindgenOptions {
|
|||||||
pub csharp_if_symbol: String,
|
pub csharp_if_symbol: String,
|
||||||
pub csharp_if_dll_name: String,
|
pub csharp_if_dll_name: String,
|
||||||
pub csharp_use_function_pointer: bool,
|
pub csharp_use_function_pointer: bool,
|
||||||
|
pub csharp_imported_namespaces: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Builder {
|
impl Default for Builder {
|
||||||
@ -51,6 +52,7 @@ impl Default for Builder {
|
|||||||
csharp_if_symbol: "".to_string(),
|
csharp_if_symbol: "".to_string(),
|
||||||
csharp_if_dll_name: "".to_string(),
|
csharp_if_dll_name: "".to_string(),
|
||||||
csharp_use_function_pointer: true,
|
csharp_use_function_pointer: true,
|
||||||
|
csharp_imported_namespaces: vec![],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,7 +65,9 @@ impl Builder {
|
|||||||
|
|
||||||
/// Add an input .rs file(such as generated from bindgen) to generate binding.
|
/// Add an input .rs file(such as generated from bindgen) to generate binding.
|
||||||
pub fn input_bindgen_file<T: AsRef<Path>>(mut self, input_bindgen_file: T) -> Builder {
|
pub fn input_bindgen_file<T: AsRef<Path>>(mut self, input_bindgen_file: T) -> Builder {
|
||||||
self.options.input_bindgen_files.push(input_bindgen_file.as_ref().to_path_buf());
|
self.options
|
||||||
|
.input_bindgen_files
|
||||||
|
.push(input_bindgen_file.as_ref().to_path_buf());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +113,15 @@ impl Builder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// configure C# extra import namespace,
|
||||||
|
/// "using {csharp_namespace};"
|
||||||
|
pub fn csharp_import_namespace<T: Into<String>>(mut self, csharp_namespace: T) -> Builder {
|
||||||
|
self.options
|
||||||
|
.csharp_imported_namespaces
|
||||||
|
.push(csharp_namespace.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// configure C# class name(default is `NativeMethods`),
|
/// configure C# class name(default is `NativeMethods`),
|
||||||
/// `public static unsafe partial class {csharp_class_name}`
|
/// `public static unsafe partial class {csharp_class_name}`
|
||||||
pub fn csharp_class_name<T: Into<String>>(mut self, csharp_class_name: T) -> Builder {
|
pub fn csharp_class_name<T: Into<String>>(mut self, csharp_class_name: T) -> Builder {
|
||||||
|
@ -46,7 +46,7 @@ pub fn emit_rust_method(list: &Vec<ExternMethod>, options: &BindgenOptions) -> S
|
|||||||
"
|
"
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern \"C\" fn {method_prefix}{method_name}(
|
pub unsafe extern \"C\" fn {method_prefix}{method_name}(
|
||||||
{parameters}
|
{parameters}
|
||||||
){return_line}
|
){return_line}
|
||||||
{{
|
{{
|
||||||
{method_type_path2}{method_name}(
|
{method_type_path2}{method_name}(
|
||||||
@ -290,6 +290,11 @@ pub fn emit_csharp(
|
|||||||
enum_string.push('\n');
|
enum_string.push('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut imported_namespaces = String::new();
|
||||||
|
for name in &options.csharp_imported_namespaces {
|
||||||
|
imported_namespaces.push_str_ln(format!("using {name};").as_str());
|
||||||
|
}
|
||||||
|
|
||||||
let result = format!(
|
let result = format!(
|
||||||
"// <auto-generated>
|
"// <auto-generated>
|
||||||
// This code is generated by csbindgen.
|
// This code is generated by csbindgen.
|
||||||
@ -299,6 +304,7 @@ pub fn emit_csharp(
|
|||||||
#pragma warning disable CS8981
|
#pragma warning disable CS8981
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
{imported_namespaces}
|
||||||
|
|
||||||
namespace {namespace}
|
namespace {namespace}
|
||||||
{{
|
{{
|
||||||
|
Loading…
Reference in New Issue
Block a user