mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2025-01-10 13:57:45 +00:00
add csharp_class_accessibility
This commit is contained in:
parent
50e406b5c8
commit
5bc027201b
@ -69,7 +69,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace CsBindgen
|
namespace CsBindgen
|
||||||
{
|
{
|
||||||
public static unsafe partial class NativeMethods
|
internal static unsafe partial class NativeMethods
|
||||||
{
|
{
|
||||||
const string __DllName = "liblz4";
|
const string __DllName = "liblz4";
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace CsBindgen
|
namespace CsBindgen
|
||||||
{
|
{
|
||||||
public static unsafe partial class NativeMethods
|
internal static unsafe partial class NativeMethods
|
||||||
{
|
{
|
||||||
const string __DllName = "nativelib";
|
const string __DllName = "nativelib";
|
||||||
|
|
||||||
@ -148,6 +148,7 @@ csbindgen::Builder::default()
|
|||||||
.rust_file_header("use super::lz4;")
|
.rust_file_header("use super::lz4;")
|
||||||
.rust_method_type_path("lz4")
|
.rust_method_type_path("lz4")
|
||||||
.csharp_class_name("LibLz4")
|
.csharp_class_name("LibLz4")
|
||||||
|
.csharp_class_accessibility("public")
|
||||||
.csharp_namespace("CsBindgen")
|
.csharp_namespace("CsBindgen")
|
||||||
.csharp_dll_name("csbindgen_tests")
|
.csharp_dll_name("csbindgen_tests")
|
||||||
.csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal")
|
.csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal")
|
||||||
@ -182,7 +183,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace {csharp_namespace}
|
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,...)}
|
#if {csharp_dll_name_if(if_symbol,...)}
|
||||||
const string __DllName = "{csharp_dll_name_if(...,if_dll_name)}";
|
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.
|
If the file path to be loaded needs to be changed depending on the operating system, the following load code can be used.
|
||||||
|
|
||||||
```csharp
|
```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
|
// https://docs.microsoft.com/en-us/dotnet/standard/native-interop/cross-platform
|
||||||
// Library path will search
|
// Library path will search
|
||||||
|
1
csbindgen-tests/build.rs
vendored
1
csbindgen-tests/build.rs
vendored
@ -52,6 +52,7 @@ fn main() {
|
|||||||
.csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal")
|
.csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal")
|
||||||
.csharp_entry_point_prefix("csbindgen_")
|
.csharp_entry_point_prefix("csbindgen_")
|
||||||
.csharp_method_prefix("")
|
.csharp_method_prefix("")
|
||||||
|
.csharp_class_accessibility("public")
|
||||||
.csharp_c_long_convert("int")
|
.csharp_c_long_convert("int")
|
||||||
.csharp_c_ulong_convert("uint")
|
.csharp_c_ulong_convert("uint")
|
||||||
.generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs")
|
.generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "csbindgen"
|
name = "csbindgen"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = [
|
authors = [
|
||||||
"Yoshifumi Kawai <ils@neue.cc>",
|
"Yoshifumi Kawai <ils@neue.cc>",
|
||||||
|
@ -21,6 +21,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_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,
|
||||||
pub csharp_c_long_convert: String,
|
pub csharp_c_long_convert: String,
|
||||||
@ -44,6 +45,7 @@ impl Default for Builder {
|
|||||||
csharp_dll_name: "".to_string(),
|
csharp_dll_name: "".to_string(),
|
||||||
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_c_long_convert: "int".to_string(),
|
csharp_c_long_convert: "int".to_string(),
|
||||||
csharp_c_ulong_convert: "uint".to_string(),
|
csharp_c_ulong_convert: "uint".to_string(),
|
||||||
csharp_if_symbol: "".to_string(),
|
csharp_if_symbol: "".to_string(),
|
||||||
@ -135,6 +137,13 @@ impl Builder {
|
|||||||
self
|
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,
|
/// configure c_long to {csharp_c_long_convert} type,
|
||||||
/// default is `int`.
|
/// default is `int`.
|
||||||
pub fn csharp_c_long_convert<T: Into<String>>(mut self, csharp_c_long_convert: T) -> Builder {
|
pub fn csharp_c_long_convert<T: Into<String>>(mut self, csharp_c_long_convert: T) -> Builder {
|
||||||
|
@ -87,6 +87,7 @@ pub fn emit_csharp(
|
|||||||
let namespace = &options.csharp_namespace;
|
let namespace = &options.csharp_namespace;
|
||||||
let class_name = &options.csharp_class_name;
|
let class_name = &options.csharp_class_name;
|
||||||
let method_prefix = &options.csharp_method_prefix;
|
let method_prefix = &options.csharp_method_prefix;
|
||||||
|
let accessibility = &options.csharp_class_accessibility;
|
||||||
|
|
||||||
let dll_name = match options.csharp_if_symbol.as_str() {
|
let dll_name = match options.csharp_if_symbol.as_str() {
|
||||||
"" => format!(" const string __DllName = \"{}\";", options.csharp_dll_name),
|
"" => format!(" const string __DllName = \"{}\";", options.csharp_dll_name),
|
||||||
@ -176,7 +177,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace {namespace}
|
namespace {namespace}
|
||||||
{{
|
{{
|
||||||
public static unsafe partial class {class_name}
|
{accessibility} static unsafe partial class {class_name}
|
||||||
{{
|
{{
|
||||||
{dll_name}
|
{dll_name}
|
||||||
|
|
||||||
|
3
dotnet-sandbox/Program.cs
vendored
3
dotnet-sandbox/Program.cs
vendored
@ -11,7 +11,7 @@ unsafe
|
|||||||
var z = LibRust.my_add(100, 200);
|
var z = LibRust.my_add(100, 200);
|
||||||
Console.WriteLine(z);
|
Console.WriteLine(z);
|
||||||
|
|
||||||
var s = LibLz4.LZ4_versionString();
|
var s = CsBindgen.LibLz4.LZ4_versionString();
|
||||||
var ss = new string((sbyte*)s);
|
var ss = new string((sbyte*)s);
|
||||||
Console.WriteLine(ss);
|
Console.WriteLine(ss);
|
||||||
|
|
||||||
@ -33,7 +33,6 @@ unsafe
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CsBindgen
|
|
||||||
{
|
{
|
||||||
public static unsafe partial class LibLz4
|
public static unsafe partial class LibLz4
|
||||||
{
|
{
|
||||||
|
2
dotnet-sandbox/method_call.cs
vendored
2
dotnet-sandbox/method_call.cs
vendored
@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
namespace CsBindgen
|
namespace CsBindgen
|
||||||
{
|
{
|
||||||
public static unsafe partial class LibRust
|
internal static unsafe partial class LibRust
|
||||||
{
|
{
|
||||||
const string __DllName = "csbindgen_tests";
|
const string __DllName = "csbindgen_tests";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user