add csharp_class_accessibility

This commit is contained in:
neuecc 2023-02-28 19:24:11 +09:00
parent 50e406b5c8
commit 5bc027201b
7 changed files with 20 additions and 9 deletions

View File

@ -69,7 +69,7 @@ using System.Runtime.InteropServices;
namespace CsBindgen
{
public static unsafe partial class NativeMethods
internal static unsafe partial class NativeMethods
{
const string __DllName = "liblz4";
@ -126,7 +126,7 @@ using System.Runtime.InteropServices;
namespace CsBindgen
{
public static unsafe partial class NativeMethods
internal static unsafe partial class NativeMethods
{
const string __DllName = "nativelib";
@ -148,6 +148,7 @@ csbindgen::Builder::default()
.rust_file_header("use super::lz4;")
.rust_method_type_path("lz4")
.csharp_class_name("LibLz4")
.csharp_class_accessibility("public")
.csharp_namespace("CsBindgen")
.csharp_dll_name("csbindgen_tests")
.csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal")
@ -182,7 +183,7 @@ using System.Runtime.InteropServices;
namespace {csharp_namespace}
{
public static unsafe partial class {csharp_class_name}
{csharp_class_accessibility} static unsafe partial class {csharp_class_name}
{
#if {csharp_dll_name_if(if_symbol,...)}
const string __DllName = "{csharp_dll_name_if(...,if_dll_name)}";
@ -207,7 +208,7 @@ Adjust `rust_file_header` and `rust_method_type_path` to match your module confi
If the file path to be loaded needs to be changed depending on the operating system, the following load code can be used.
```csharp
public static unsafe partial class NativeMethods
internal static unsafe partial class NativeMethods
{
// https://docs.microsoft.com/en-us/dotnet/standard/native-interop/cross-platform
// Library path will search

View File

@ -52,6 +52,7 @@ fn main() {
.csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal")
.csharp_entry_point_prefix("csbindgen_")
.csharp_method_prefix("")
.csharp_class_accessibility("public")
.csharp_c_long_convert("int")
.csharp_c_ulong_convert("uint")
.generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs")

View File

@ -1,6 +1,6 @@
[package]
name = "csbindgen"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = [
"Yoshifumi Kawai <ils@neue.cc>",

View File

@ -21,6 +21,7 @@ pub struct BindgenOptions {
pub csharp_namespace: String,
pub csharp_class_name: String,
pub csharp_dll_name: String,
pub csharp_class_accessibility: String,
pub csharp_entry_point_prefix: String,
pub csharp_method_prefix: String,
pub csharp_c_long_convert: String,
@ -44,6 +45,7 @@ impl Default for Builder {
csharp_dll_name: "".to_string(),
csharp_entry_point_prefix: "".to_string(),
csharp_method_prefix: "".to_string(),
csharp_class_accessibility: "internal".to_string(),
csharp_c_long_convert: "int".to_string(),
csharp_c_ulong_convert: "uint".to_string(),
csharp_if_symbol: "".to_string(),
@ -135,6 +137,13 @@ impl Builder {
self
}
/// configure C# class accessibility, default is internal
/// `{csharp_class_accessibility} static unsafe partial class NativeMethods`
pub fn csharp_class_accessibility<T: Into<String>>(mut self, csharp_class_accessibility: T) -> Builder {
self.options.csharp_class_accessibility = csharp_class_accessibility.into();
self
}
/// configure c_long to {csharp_c_long_convert} type,
/// default is `int`.
pub fn csharp_c_long_convert<T: Into<String>>(mut self, csharp_c_long_convert: T) -> Builder {

View File

@ -87,6 +87,7 @@ pub fn emit_csharp(
let namespace = &options.csharp_namespace;
let class_name = &options.csharp_class_name;
let method_prefix = &options.csharp_method_prefix;
let accessibility = &options.csharp_class_accessibility;
let dll_name = match options.csharp_if_symbol.as_str() {
"" => format!(" const string __DllName = \"{}\";", options.csharp_dll_name),
@ -176,7 +177,7 @@ using System.Runtime.InteropServices;
namespace {namespace}
{{
public static unsafe partial class {class_name}
{accessibility} static unsafe partial class {class_name}
{{
{dll_name}

View File

@ -11,7 +11,7 @@ unsafe
var z = LibRust.my_add(100, 200);
Console.WriteLine(z);
var s = LibLz4.LZ4_versionString();
var s = CsBindgen.LibLz4.LZ4_versionString();
var ss = new string((sbyte*)s);
Console.WriteLine(ss);
@ -33,7 +33,6 @@ unsafe
}
namespace CsBindgen
{
public static unsafe partial class LibLz4
{

View File

@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
namespace CsBindgen
{
public static unsafe partial class LibRust
internal static unsafe partial class LibRust
{
const string __DllName = "csbindgen_tests";