This commit is contained in:
neuecc 2023-04-15 23:32:00 +09:00
parent 32af3f29e0
commit a03eb06808
5 changed files with 18 additions and 6 deletions

View File

@ -129,9 +129,10 @@ fn main() -> Result<(), Box<dyn Error>> {
csbindgen::Builder::new() csbindgen::Builder::new()
.input_bindgen_file("src/physx/physx_generated.rs") .input_bindgen_file("src/physx/physx_generated.rs")
.input_bindgen_file("src/physx/x86_64-pc-windows-msvc/structgen.rs") .input_bindgen_file("src/physx/x86_64-pc-windows-msvc/structgen.rs")
// .csharp_disable_emit_dll_name(true)
.csharp_namespace("Physx") .csharp_namespace("Physx")
.csharp_class_name("LibPhysxd") .csharp_class_name("LibPhysx")
.csharp_dll_name("libphysx") .csharp_dll_name("libphys")
.generate_csharp_file("../dotnet-sandbox/libphysx_csbindgen.cs")?; .generate_csharp_file("../dotnet-sandbox/libphysx_csbindgen.cs")?;
Ok(()) Ok(())

View File

@ -22,6 +22,7 @@ pub struct BindgenOptions {
pub csharp_namespace: String, pub csharp_namespace: String,
pub csharp_class_name: String, pub csharp_class_name: String,
pub csharp_dll_name: String, pub csharp_dll_name: String,
pub csharp_disable_emit_dll_name: bool,
pub csharp_class_accessibility: String, pub csharp_class_accessibility: String,
pub csharp_entry_point_prefix: String, pub csharp_entry_point_prefix: String,
pub csharp_method_prefix: String, pub csharp_method_prefix: String,
@ -43,6 +44,7 @@ impl Default for Builder {
csharp_namespace: "CsBindgen".to_string(), csharp_namespace: "CsBindgen".to_string(),
csharp_class_name: "NativeMethods".to_string(), csharp_class_name: "NativeMethods".to_string(),
csharp_dll_name: "".to_string(), csharp_dll_name: "".to_string(),
csharp_disable_emit_dll_name: false,
csharp_entry_point_prefix: "".to_string(), csharp_entry_point_prefix: "".to_string(),
csharp_method_prefix: "".to_string(), csharp_method_prefix: "".to_string(),
csharp_class_accessibility: "internal".to_string(), csharp_class_accessibility: "internal".to_string(),
@ -121,6 +123,12 @@ impl Builder {
self self
} }
/// configure don't emit __DllName
pub fn csharp_disable_emit_dll_name(mut self, csharp_disable_emit_dll_name: bool) -> Builder {
self.options.csharp_disable_emit_dll_name = csharp_disable_emit_dll_name;
self
}
/// configure C# DllImport EntryPoint prefix, /// configure C# DllImport EntryPoint prefix,
/// `[DllImport(, EntryPoint ="{csharp_entry_point_prefix}foo")]` /// `[DllImport(, EntryPoint ="{csharp_entry_point_prefix}foo")]`
pub fn csharp_entry_point_prefix<T: Into<String>>( pub fn csharp_entry_point_prefix<T: Into<String>>(

View File

@ -87,7 +87,7 @@ pub fn emit_csharp(
let method_prefix = &options.csharp_method_prefix; let method_prefix = &options.csharp_method_prefix;
let accessibility = &options.csharp_class_accessibility; let accessibility = &options.csharp_class_accessibility;
let dll_name = match options.csharp_if_symbol.as_str() { let mut dll_name = match options.csharp_if_symbol.as_str() {
"" => format!( "" => format!(
" const string __DllName = \"{}\";", " const string __DllName = \"{}\";",
options.csharp_dll_name options.csharp_dll_name
@ -104,6 +104,9 @@ pub fn emit_csharp(
) )
} }
}; };
if options.csharp_disable_emit_dll_name {
dll_name = "".to_string();
}
let mut method_list_string = String::new(); let mut method_list_string = String::new();
for item in methods { for item in methods {

View File

@ -3,7 +3,7 @@
namespace Physx namespace Physx
{ {
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "Px")] [GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "Px")]
internal static unsafe partial class LibPhysxd internal static unsafe partial class LibPhysx
{ {
} }
} }

View File

@ -9,9 +9,9 @@ using System.Runtime.InteropServices;
namespace Physx namespace Physx
{ {
internal static unsafe partial class LibPhysxd internal static unsafe partial class LibPhysx
{ {
const string __DllName = "libphysx"; const string __DllName = "libphys";
[DllImport(__DllName, EntryPoint = "PxAllocatorCallback_delete", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "PxAllocatorCallback_delete", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void PxAllocatorCallback_delete(PxAllocatorCallback* self_); public static extern void PxAllocatorCallback_delete(PxAllocatorCallback* self_);