diff --git a/csbindgen-tests/build.rs b/csbindgen-tests/build.rs index d7b4801..35dfd61 100644 --- a/csbindgen-tests/build.rs +++ b/csbindgen-tests/build.rs @@ -129,9 +129,10 @@ fn main() -> Result<(), Box> { csbindgen::Builder::new() .input_bindgen_file("src/physx/physx_generated.rs") .input_bindgen_file("src/physx/x86_64-pc-windows-msvc/structgen.rs") + // .csharp_disable_emit_dll_name(true) .csharp_namespace("Physx") - .csharp_class_name("LibPhysxd") - .csharp_dll_name("libphysx") + .csharp_class_name("LibPhysx") + .csharp_dll_name("libphys") .generate_csharp_file("../dotnet-sandbox/libphysx_csbindgen.cs")?; Ok(()) diff --git a/csbindgen/src/builder.rs b/csbindgen/src/builder.rs index 6d44107..4ff3427 100644 --- a/csbindgen/src/builder.rs +++ b/csbindgen/src/builder.rs @@ -22,6 +22,7 @@ pub struct BindgenOptions { pub csharp_namespace: String, pub csharp_class_name: String, pub csharp_dll_name: String, + pub csharp_disable_emit_dll_name: bool, pub csharp_class_accessibility: String, pub csharp_entry_point_prefix: String, pub csharp_method_prefix: String, @@ -43,6 +44,7 @@ impl Default for Builder { csharp_namespace: "CsBindgen".to_string(), csharp_class_name: "NativeMethods".to_string(), csharp_dll_name: "".to_string(), + csharp_disable_emit_dll_name: false, csharp_entry_point_prefix: "".to_string(), csharp_method_prefix: "".to_string(), csharp_class_accessibility: "internal".to_string(), @@ -121,6 +123,12 @@ impl Builder { 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, /// `[DllImport(, EntryPoint ="{csharp_entry_point_prefix}foo")]` pub fn csharp_entry_point_prefix>( diff --git a/csbindgen/src/emitter.rs b/csbindgen/src/emitter.rs index 9f68467..9c5d7f9 100644 --- a/csbindgen/src/emitter.rs +++ b/csbindgen/src/emitter.rs @@ -87,7 +87,7 @@ pub fn emit_csharp( let method_prefix = &options.csharp_method_prefix; 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!( " const string __DllName = \"{}\";", 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(); for item in methods { diff --git a/dotnet-sandbox/BindingGroupExtensions.cs b/dotnet-sandbox/BindingGroupExtensions.cs index 09c500c..cc05e58 100644 --- a/dotnet-sandbox/BindingGroupExtensions.cs +++ b/dotnet-sandbox/BindingGroupExtensions.cs @@ -3,7 +3,7 @@ namespace Physx { [GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "Px")] - internal static unsafe partial class LibPhysxd + internal static unsafe partial class LibPhysx { } } diff --git a/dotnet-sandbox/libphysx_csbindgen.cs b/dotnet-sandbox/libphysx_csbindgen.cs index 5a1c68e..240d28c 100644 --- a/dotnet-sandbox/libphysx_csbindgen.cs +++ b/dotnet-sandbox/libphysx_csbindgen.cs @@ -9,9 +9,9 @@ using System.Runtime.InteropServices; 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)] public static extern void PxAllocatorCallback_delete(PxAllocatorCallback* self_);