mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-22 22:46:26 +00:00
Merge pull request #26 from Cysharp/libphysx_working2
add more features
This commit is contained in:
commit
250c66ef14
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,6 +6,8 @@
|
|||||||
.vs/
|
.vs/
|
||||||
dotnet-sandbox/obj/
|
dotnet-sandbox/obj/
|
||||||
dotnet-sandbox/bin/
|
dotnet-sandbox/bin/
|
||||||
|
GroupedNativeMethodsGenerator/obj/
|
||||||
|
GroupedNativeMethodsGenerator/bin/
|
||||||
unity-sandbox/obj/
|
unity-sandbox/obj/
|
||||||
unity-sandbox/bin/
|
unity-sandbox/bin/
|
||||||
unity-sandbox/Temp/
|
unity-sandbox/Temp/
|
||||||
@ -13,6 +15,4 @@ unity-sandbox/*.csproj
|
|||||||
unity-sandbox/*.csproj.user
|
unity-sandbox/*.csproj.user
|
||||||
unity-sandbox/*.sln
|
unity-sandbox/*.sln
|
||||||
unity-sandbox/Library
|
unity-sandbox/Library
|
||||||
|
|
||||||
|
|
||||||
unity-sandbox/Logs/
|
unity-sandbox/Logs/
|
||||||
|
1
.vscode/tasks.json
vendored
1
.vscode/tasks.json
vendored
@ -11,6 +11,7 @@
|
|||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": true
|
"isDefault": true
|
||||||
},
|
},
|
||||||
|
"args": ["-vv"],
|
||||||
"label": "rust: cargo build"
|
"label": "rust: cargo build"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
31
GroupedNativeMethodsGenerator.sln
Normal file
31
GroupedNativeMethodsGenerator.sln
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.33414.496
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CsbindgenDotnetConsoleApp", "dotnet-sandbox\CsbindgenDotnetConsoleApp.csproj", "{9FCF940C-368E-41C5-B83A-CFDEC01E2B70}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GroupedNativeMethodsGenerator", "GroupedNativeMethodsGenerator\GroupedNativeMethodsGenerator.csproj", "{C63592D1-9C02-43BF-A4E0-C23D4B1C0ACE}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{9FCF940C-368E-41C5-B83A-CFDEC01E2B70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9FCF940C-368E-41C5-B83A-CFDEC01E2B70}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9FCF940C-368E-41C5-B83A-CFDEC01E2B70}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9FCF940C-368E-41C5-B83A-CFDEC01E2B70}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C63592D1-9C02-43BF-A4E0-C23D4B1C0ACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C63592D1-9C02-43BF-A4E0-C23D4B1C0ACE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C63592D1-9C02-43BF-A4E0-C23D4B1C0ACE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C63592D1-9C02-43BF-A4E0-C23D4B1C0ACE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {8FAD332E-1845-455E-AB46-3F45699D2335}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
168
GroupedNativeMethodsGenerator/GroupedNativeMethodsGenerator.cs
Normal file
168
GroupedNativeMethodsGenerator/GroupedNativeMethodsGenerator.cs
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace GroupedNativeMethodsGenerator;
|
||||||
|
|
||||||
|
[Generator(LanguageNames.CSharp)]
|
||||||
|
public partial class GroupedNativeMethodsGenerator : IIncrementalGenerator
|
||||||
|
{
|
||||||
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
|
{
|
||||||
|
context.RegisterPostInitializationOutput(ctx =>
|
||||||
|
{
|
||||||
|
ctx.AddSource("GroupedNativeMethodsGenerator.Attribute.cs", """
|
||||||
|
namespace GroupedNativeMethodsGenerator
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
|
||||||
|
internal sealed class GroupedNativeMethodsAttribute : Attribute
|
||||||
|
{
|
||||||
|
public string RemovePrefix { get; }
|
||||||
|
public string RemoveSuffix { get; }
|
||||||
|
public bool RemoveUntilTypeName { get; }
|
||||||
|
public bool FixMethodName { get; }
|
||||||
|
|
||||||
|
public GroupedNativeMethodsAttribute(string removePrefix = "", string removeSuffix = "", bool removeUntilTypeName = true, bool fixMethodName = true)
|
||||||
|
{
|
||||||
|
this.RemovePrefix = removePrefix;
|
||||||
|
this.RemoveSuffix = removeSuffix;
|
||||||
|
this.RemoveUntilTypeName = removeUntilTypeName;
|
||||||
|
this.FixMethodName = fixMethodName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
});
|
||||||
|
|
||||||
|
var source = context.SyntaxProvider.ForAttributeWithMetadataName("GroupedNativeMethodsGenerator.GroupedNativeMethodsAttribute",
|
||||||
|
(node, token) => node is ClassDeclarationSyntax,
|
||||||
|
(ctx, token) => ctx);
|
||||||
|
|
||||||
|
context.RegisterSourceOutput(source, Emit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Emit(SourceProductionContext context, GeneratorAttributeSyntaxContext source)
|
||||||
|
{
|
||||||
|
var typeSymbol = (INamedTypeSymbol)source.TargetSymbol;
|
||||||
|
var typeNode = (TypeDeclarationSyntax)source.TargetNode;
|
||||||
|
|
||||||
|
var ns = typeSymbol.ContainingNamespace.IsGlobalNamespace
|
||||||
|
? ""
|
||||||
|
: $"namespace {typeSymbol.ContainingNamespace}\n{{";
|
||||||
|
|
||||||
|
var accessibility = typeSymbol.DeclaredAccessibility == Accessibility.Public ? "public" : "internal";
|
||||||
|
|
||||||
|
var fullType = typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
|
||||||
|
.Replace("global::", "")
|
||||||
|
.Replace("<", "_")
|
||||||
|
.Replace(">", "_");
|
||||||
|
|
||||||
|
var grouped = typeSymbol.GetMembers().OfType<IMethodSymbol>()
|
||||||
|
.Where(x => x.Parameters.Length != 0)
|
||||||
|
.Where(x => x.Parameters[0].Type is IPointerTypeSymbol t && (t.PointedAtType.SpecialType is SpecialType.None) && t.PointedAtType.TypeKind != TypeKind.Pointer)
|
||||||
|
.ToLookup(x =>
|
||||||
|
{
|
||||||
|
return ((IPointerTypeSymbol)x.Parameters[0].Type).PointedAtType.ToDisplayString();
|
||||||
|
});
|
||||||
|
|
||||||
|
var libTypeName = typeSymbol.Name;
|
||||||
|
var removePrefix = (string)source.Attributes[0].ConstructorArguments[0].Value!;
|
||||||
|
var removeSuffix = (string)source.Attributes[0].ConstructorArguments[1].Value!;
|
||||||
|
var removeUntilTypeName = (bool)source.Attributes[0].ConstructorArguments[2].Value!;
|
||||||
|
var fixMethodName = (bool)source.Attributes[0].ConstructorArguments[3].Value!;
|
||||||
|
|
||||||
|
var code = new StringBuilder();
|
||||||
|
|
||||||
|
code.AppendLine($$"""
|
||||||
|
// <auto-generated/>
|
||||||
|
#nullable enable
|
||||||
|
#pragma warning disable CS8600
|
||||||
|
#pragma warning disable CS8601
|
||||||
|
#pragma warning disable CS8602
|
||||||
|
#pragma warning disable CS8603
|
||||||
|
#pragma warning disable CS8604
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
{{ns}}
|
||||||
|
|
||||||
|
{{accessibility}} static unsafe class {{typeSymbol.Name}}GroupingExtensions
|
||||||
|
{
|
||||||
|
""");
|
||||||
|
foreach (var g in grouped)
|
||||||
|
{
|
||||||
|
code.AppendLine($"#region {g.Key}({g.Count()})");
|
||||||
|
code.AppendLine();
|
||||||
|
foreach (var item in g)
|
||||||
|
{
|
||||||
|
var firstArgument = item.Parameters[0];
|
||||||
|
var ret = item.ReturnType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||||
|
var requireRet = ret == "void" ? "" : "return ";
|
||||||
|
|
||||||
|
var convertedMethodName = ConvertMethodName(((IPointerTypeSymbol)firstArgument.Type).PointedAtType.Name, item.Name, removePrefix, removeSuffix, removeUntilTypeName, fixMethodName);
|
||||||
|
var pointedType = ((IPointerTypeSymbol)firstArgument.Type).PointedAtType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||||
|
var parameterPairs = string.Join("", item.Parameters.Skip(1).Select(x => $", {x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} @{x.Name}"));
|
||||||
|
var parameterNames = string.Join("", item.Parameters.Skip(1).Select(x => $", @{x.Name}"));
|
||||||
|
|
||||||
|
code.AppendLine($" public static {ret} {convertedMethodName}(this ref {pointedType} @{firstArgument.Name}{parameterPairs})");
|
||||||
|
code.AppendLine(" {");
|
||||||
|
code.AppendLine($" {requireRet}{libTypeName}.{item.Name}(({pointedType}*)Unsafe.AsPointer(ref @{firstArgument.Name}){parameterNames});");
|
||||||
|
code.AppendLine(" }");
|
||||||
|
code.AppendLine("");
|
||||||
|
}
|
||||||
|
code.AppendLine($"#endregion");
|
||||||
|
code.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
code.AppendLine(" }");
|
||||||
|
if (ns != "")
|
||||||
|
{
|
||||||
|
code.AppendLine("}");
|
||||||
|
}
|
||||||
|
|
||||||
|
context.AddSource($"{fullType}.GroupedNativeMethods.g.cs", code.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
static string ConvertMethodName(string typeName, string methodName, string removePrefix, string removeSuffix, bool removeUntilTypeName, bool fixMethodName)
|
||||||
|
{
|
||||||
|
if (removeUntilTypeName)
|
||||||
|
{
|
||||||
|
var match = methodName.IndexOf(typeName);
|
||||||
|
if (match != -1)
|
||||||
|
{
|
||||||
|
methodName = methodName.Substring(match + typeName.Length);
|
||||||
|
goto FINAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(removePrefix))
|
||||||
|
{
|
||||||
|
methodName = Regex.Replace(methodName, $"^{Regex.Escape(removePrefix)}", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
FINAL:
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(removeSuffix))
|
||||||
|
{
|
||||||
|
methodName = Regex.Replace(methodName, $"{Regex.Escape(removeSuffix)}$", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
methodName = methodName.Trim('_');
|
||||||
|
|
||||||
|
if (fixMethodName)
|
||||||
|
{
|
||||||
|
var split = methodName.Split('_');
|
||||||
|
methodName = string.Concat(split.Select(x =>
|
||||||
|
{
|
||||||
|
if (x.Length == 0) return x;
|
||||||
|
if (x.Length == 1) return char.ToUpper(x[0]).ToString();
|
||||||
|
return char.ToUpper(x[0]) + x.Substring(1);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return methodName;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<LangVersion>11</LangVersion>
|
||||||
|
<IsRoslynComponent>true</IsRoslynComponent>
|
||||||
|
<AnalyzerLanguage>cs</AnalyzerLanguage>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"P1": {
|
||||||
|
"commandName": "DebugRoslynComponent",
|
||||||
|
"targetProject": "..\\dotnet-sandbox\\CsbindgenDotnetConsoleApp.csproj"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
csbindgen-tests/Cargo.toml
vendored
1
csbindgen-tests/Cargo.toml
vendored
@ -14,6 +14,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
csbindgen = { path = "../csbindgen" }
|
csbindgen = { path = "../csbindgen" }
|
||||||
|
# physx-sys = "0.11.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cc = "1.0.79"
|
cc = "1.0.79"
|
||||||
|
12
csbindgen-tests/build.rs
vendored
12
csbindgen-tests/build.rs
vendored
@ -125,5 +125,17 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
.csharp_dll_name("libpng16")
|
.csharp_dll_name("libpng16")
|
||||||
.generate_csharp_file("../dotnet-sandbox/libpng16_csbindgen.cs")?;
|
.generate_csharp_file("../dotnet-sandbox/libpng16_csbindgen.cs")?;
|
||||||
|
|
||||||
|
|
||||||
|
csbindgen::Builder::new()
|
||||||
|
.input_bindgen_file("src/physx/lib.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/unix/structgen.rs")
|
||||||
|
// .csharp_disable_emit_dll_name(true)
|
||||||
|
.csharp_namespace("Physx")
|
||||||
|
.csharp_class_name("LibPhysx")
|
||||||
|
.csharp_dll_name("libphys")
|
||||||
|
.generate_csharp_file("../dotnet-sandbox/libphysx_csbindgen.cs")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
60
csbindgen-tests/src/lib.rs
vendored
60
csbindgen-tests/src/lib.rs
vendored
@ -124,6 +124,16 @@ pub extern "C" fn comment_one() {
|
|||||||
pub extern "C" fn long_jpn_comment() {
|
pub extern "C" fn long_jpn_comment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct my_int_vec3(i32,i32,i32);
|
||||||
|
|
||||||
|
pub extern "C" fn use_vec3(_v3: my_int_vec3) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct NfcCard {
|
pub struct NfcCard {
|
||||||
pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray
|
pub delegate: unsafe extern "C" fn(ByteArray) -> ByteArray
|
||||||
@ -455,11 +465,21 @@ fn build_test() {
|
|||||||
// // println!("lz4 num: {}", num);
|
// // println!("lz4 num: {}", num);
|
||||||
// // }
|
// // }
|
||||||
|
|
||||||
csbindgen::Builder::default()
|
// csbindgen::Builder::default()
|
||||||
.input_extern_file("csbindgen-tests/src/lib.rs")
|
// .input_extern_file("csbindgen-tests/src/lib.rs")
|
||||||
.csharp_class_name("NativeMethods")
|
// .csharp_class_name("NativeMethods")
|
||||||
.csharp_dll_name("csbindgen_tests")
|
// .csharp_dll_name("csbindgen_tests")
|
||||||
.generate_csharp_file("dotnet-sandbox/NativeMethods.cs")
|
// .generate_csharp_file("dotnet-sandbox/NativeMethods.cs")
|
||||||
|
// .unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
csbindgen::Builder::new()
|
||||||
|
.input_bindgen_file("csbindgen-tests/src/physx/physx_generated.rs")
|
||||||
|
.input_bindgen_file("csbindgen-tests/src/physx/x86_64-pc-windows-msvc/structgen.rs")
|
||||||
|
.csharp_namespace("Physx")
|
||||||
|
.csharp_class_name("LibPhysxd")
|
||||||
|
.csharp_dll_name("libphysx")
|
||||||
|
.generate_csharp_file("dotnet-sandbox/libphysx_csbindgen.cs")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,3 +566,33 @@ pub struct CallbackTable {
|
|||||||
pub foo: extern "C" fn(),
|
pub foo: extern "C" fn(),
|
||||||
pub foobar: extern "C" fn(i: i32) -> i32,
|
pub foobar: extern "C" fn(i: i32) -> i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// fn run_physix(){
|
||||||
|
// unsafe {
|
||||||
|
// let foundation = physx_create_foundation();
|
||||||
|
// let physics = physx_create_physics(foundation);
|
||||||
|
|
||||||
|
// let mut scene_desc = PxSceneDesc_new(PxPhysics_getTolerancesScale(physics));
|
||||||
|
// scene_desc.gravity = PxVec3 {
|
||||||
|
// x: 0.0,
|
||||||
|
// y: -9.81,
|
||||||
|
// z: 0.0,
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// let dispatcher = phys_PxDefaultCpuDispatcherCreate(
|
||||||
|
// 1,
|
||||||
|
// null_mut(),
|
||||||
|
// PxDefaultCpuDispatcherWaitForWorkMode::WaitForWork,
|
||||||
|
// 0,
|
||||||
|
// );
|
||||||
|
// scene_desc.cpuDispatcher = dispatcher.cast();
|
||||||
|
// scene_desc.filterShader = get_default_simulation_filter_shader();
|
||||||
|
|
||||||
|
// let scene = PxPhysics_createScene_mut(physics, &scene_desc);
|
||||||
|
|
||||||
|
// // Your physics simulation goes here
|
||||||
|
// }
|
||||||
|
// }
|
408
csbindgen-tests/src/physx/lib.rs
vendored
Normal file
408
csbindgen-tests/src/physx/lib.rs
vendored
Normal file
@ -0,0 +1,408 @@
|
|||||||
|
//! # 🎳 physx-sys
|
||||||
|
//!
|
||||||
|
//! ![Build Status](https://github.com/EmbarkStudios/physx-rs/workflows/CI/badge.svg)
|
||||||
|
//! [![Crates.io](https://img.shields.io/crates/v/physx-sys.svg)](https://crates.io/crates/physx-sys)
|
||||||
|
//! [![Docs](https://docs.rs/physx-sys/badge.svg)](https://docs.rs/physx-sys)
|
||||||
|
//! [![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4%20adopted-ff69b4.svg)](../CODE_OF_CONDUCT.md)
|
||||||
|
//! [![Embark](https://img.shields.io/badge/embark-open%20source-blueviolet.svg)](http://embark.games)
|
||||||
|
//!
|
||||||
|
//! Unsafe automatically-generated Rust bindings for [NVIDIA PhysX 4.1](https://github.com/NVIDIAGameWorks/PhysX) C++ API.
|
||||||
|
//!
|
||||||
|
//! Please also see the [repository](https://github.com/EmbarkStudios/physx-rs) containing a work-in-progress safe wrapper.
|
||||||
|
//!
|
||||||
|
//! ## Presentation
|
||||||
|
//!
|
||||||
|
//! [Tomasz Stachowiak](https://github.com/h3r2tic) did a presentation at the Stockholm Rust Meetup on October 2019
|
||||||
|
//! about this project that goes through the tecnical details of how C++ to Rust bindings of `physx-sys` works:
|
||||||
|
//!
|
||||||
|
//! [![](http://img.youtube.com/vi/RxtXGeDHu0w/0.jpg)](http://www.youtube.com/watch?v=RxtXGeDHu0w "An unholy fusion of
|
||||||
|
//! Rust and C++ in physx-rs (Stockholm Rust Meetup, October 2019)")
|
||||||
|
//!
|
||||||
|
//!
|
||||||
|
//! ## Basic usage
|
||||||
|
//!
|
||||||
|
//! ```Rust
|
||||||
|
//! unsafe {
|
||||||
|
//! let foundation = physx_create_foundation();
|
||||||
|
//! let physics = physx_create_physics(foundation);
|
||||||
|
//!
|
||||||
|
//! let mut scene_desc = PxSceneDesc_new(PxPhysics_getTolerancesScale(physics));
|
||||||
|
//! scene_desc.gravity = PxVec3 {
|
||||||
|
//! x: 0.0,
|
||||||
|
//! y: -9.81,
|
||||||
|
//! z: 0.0,
|
||||||
|
//! };
|
||||||
|
//!
|
||||||
|
//! let dispatcher = PxDefaultCpuDispatcherCreate(2, null_mut());
|
||||||
|
//!
|
||||||
|
//! scene_desc.cpuDispatcher = dispatcher as *mut PxCpuDispatcher;
|
||||||
|
//! scene_desc.filterShader = Some(PxDefaultSimulationFilterShader);
|
||||||
|
//!
|
||||||
|
//! let scene = PxPhysics_createScene_mut(physics, &scene_desc);
|
||||||
|
//!
|
||||||
|
//! // Your physics simulation goes here
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! ## Examples
|
||||||
|
//!
|
||||||
|
//! ### [Ball](examples/ball.rs)
|
||||||
|
//!
|
||||||
|
//! A simple example to showcase how to use physx-sys. It can be run with `cargo run --examples ball`.
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! o
|
||||||
|
//!
|
||||||
|
//! o
|
||||||
|
//! o
|
||||||
|
//!
|
||||||
|
//! o
|
||||||
|
//! ooooooooo
|
||||||
|
//! o oo oo
|
||||||
|
//! o o
|
||||||
|
//! o o o
|
||||||
|
//! o oo
|
||||||
|
//! o o o
|
||||||
|
//! o ooooooo
|
||||||
|
//! o o oo oo
|
||||||
|
//! o o o oo oo
|
||||||
|
//! o o o o ooooooooo
|
||||||
|
//! o o o oo oooooooooo oo
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! ## How it works
|
||||||
|
//!
|
||||||
|
//! The binding is generated using a custom C++ app written against clang's
|
||||||
|
//! [libtooling](https://clang.llvm.org/docs/LibTooling.html). It queries the compiler's abstract syntax tree, and maps
|
||||||
|
//! the C++ PhysX functions and types to Rust using heuristics chosen specifically for this SDK. It is not a general
|
||||||
|
//! C++ <-> Rust binding generator, and using it on other projects *will* likely crash and burn.
|
||||||
|
//!
|
||||||
|
//! Since C++ does not have a standardized and stable ABI, it's generally not safe to call it from Rust code; since
|
||||||
|
//! PhysX exposes a C++ interface, we can't use it directly. That's why `physx-sys` generates both a Rust interface as
|
||||||
|
//! well as a plain C wrapper. The C code is compiled into a static library at build time, and Rust then talks to C.
|
||||||
|
//!
|
||||||
|
//! In order to minimize the amount of work required to marshall data between the C wrapper and the original C++ API, we
|
||||||
|
//! generate a **bespoke C wrapper for each build target**. The wrapper is based on metadata about structure layout
|
||||||
|
//! extracted directly from compiling and running a tiny program against the PhysX SDK using the specific C++ compiler
|
||||||
|
//! used in the build process.
|
||||||
|
//!
|
||||||
|
//! The build process comprises a few steps:
|
||||||
|
//!
|
||||||
|
//! 1. The `pxbind` utility uses `clang` to extract metadata about PhysX functions and types, and generates partial
|
||||||
|
//! Rust and C bindings as `physx_generated.hpp` and `physx_generated.rs`. Those contain all function definitions, and
|
||||||
|
//! a small subset of types. It also generates a C++ utility called `structgen` by emitting `structgen.cpp`.
|
||||||
|
//! 2. `structgen` is compiled against the PhysX SDK, and generates all the remaining type wrappers. For each struct, it
|
||||||
|
//! queries the size and offset of its members, and generates `structgen_out.hpp` and `structgen_out.rs`. The types are
|
||||||
|
//! "plain old data" structs which will perfectly match the memory layout of the C++ types.
|
||||||
|
//! 3. All the generated C types are compiled together to form `physx_api`, a static library for Rust to link with.
|
||||||
|
//! 4. The Rust wrapper is compiled, and linked with PhysX and the C wrapper.
|
||||||
|
//!
|
||||||
|
//! Steps *2..4* are performed completely automatically from within `build.rs`, while step *1* is only necessary when
|
||||||
|
//! upgrading the PhysX SDK or modifying the generator. As such, building and running `pxbind` is a manual task, and is
|
||||||
|
//! currently only supported on \*nix systems.
|
||||||
|
//!
|
||||||
|
//! ## License
|
||||||
|
//!
|
||||||
|
//! Licensed under either of
|
||||||
|
//!
|
||||||
|
//! * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
//! * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||||
|
//!
|
||||||
|
//! at your option.
|
||||||
|
//!
|
||||||
|
//! Note that the [PhysX C++ SDK](https://github.com/NVIDIAGameWorks/PhysX) has it's
|
||||||
|
//! [own BSD 3 license](https://gameworksdocs.nvidia.com/PhysX/4.1/documentation/physxguide/Manual/License.html) and
|
||||||
|
//! depends on [additional C++ third party libraries](https://github.com/NVIDIAGameWorks/PhysX/tree/4.1/externals).
|
||||||
|
//!
|
||||||
|
//! ### Contribution
|
||||||
|
//!
|
||||||
|
//! Unless you explicitly state otherwise, any contribution intentionally
|
||||||
|
//! submitted for inclusion in the work by you, as defined in the Apache-2.0
|
||||||
|
//! license, shall be dual licensed as above, without any additional terms or
|
||||||
|
//! conditions.
|
||||||
|
|
||||||
|
// crate-specific exceptions:
|
||||||
|
#![allow(
|
||||||
|
unsafe_code,
|
||||||
|
non_upper_case_globals,
|
||||||
|
non_camel_case_types,
|
||||||
|
non_snake_case,
|
||||||
|
clippy::doc_markdown, // TODO: fixup comments and docs (though annoyingly complains about "PhysX")
|
||||||
|
clippy::unreadable_literal,
|
||||||
|
clippy::unused_unit,
|
||||||
|
clippy::upper_case_acronyms
|
||||||
|
)]
|
||||||
|
|
||||||
|
#[cfg(feature = "structgen")]
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/structgen_out.rs"));
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "structgen"),
|
||||||
|
target_os = "linux",
|
||||||
|
target_arch = "x86_64",
|
||||||
|
))]
|
||||||
|
include!("generated/unix/structgen.rs");
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "structgen"),
|
||||||
|
target_os = "linux",
|
||||||
|
target_arch = "aarch64",
|
||||||
|
))]
|
||||||
|
include!("generated/unix/structgen.rs");
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "structgen"),
|
||||||
|
target_os = "android",
|
||||||
|
target_arch = "aarch64",
|
||||||
|
))]
|
||||||
|
include!("generated/unix/structgen.rs");
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "structgen"),
|
||||||
|
target_os = "macos",
|
||||||
|
target_arch = "x86_64",
|
||||||
|
))]
|
||||||
|
include!("generated/unix/structgen.rs");
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "structgen"),
|
||||||
|
target_os = "macos",
|
||||||
|
target_arch = "aarch64",
|
||||||
|
))]
|
||||||
|
include!("generated/unix/structgen.rs");
|
||||||
|
|
||||||
|
#[cfg(all(
|
||||||
|
not(feature = "structgen"),
|
||||||
|
target_os = "windows",
|
||||||
|
target_arch = "x86_64",
|
||||||
|
target_env = "msvc",
|
||||||
|
))]
|
||||||
|
include!("generated/x86_64-pc-windows-msvc/structgen.rs");
|
||||||
|
|
||||||
|
include!("physx_generated.rs");
|
||||||
|
|
||||||
|
use std::ffi::c_void;
|
||||||
|
|
||||||
|
pub const fn version(major: u32, minor: u32, patch: u32) -> u32 {
|
||||||
|
(major << 24) + (minor << 16) + (patch << 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type CollisionCallback =
|
||||||
|
unsafe extern "C" fn(*mut c_void, *const PxContactPairHeader, *const PxContactPair, u32);
|
||||||
|
|
||||||
|
pub type TriggerCallback = unsafe extern "C" fn(*mut c_void, *const PxTriggerPair, u32);
|
||||||
|
|
||||||
|
pub type ConstraintBreakCallback = unsafe extern "C" fn(*mut c_void, *const PxConstraintInfo, u32);
|
||||||
|
|
||||||
|
pub type WakeSleepCallback = unsafe extern "C" fn(*mut c_void, *const *const PxActor, u32, bool);
|
||||||
|
|
||||||
|
pub type AdvanceCallback =
|
||||||
|
unsafe extern "C" fn(*mut c_void, *const *const PxRigidBody, *const PxTransform, u32);
|
||||||
|
|
||||||
|
// Function pointers in Rust are normally not nullable (which is why they don't require unsafe to call)
|
||||||
|
// but we need them to be, so we simply wrap them in Option<>. An Option<funcptr> is luckily represented
|
||||||
|
// by the compiler as a simple pointer with null representing None, so this is compatible with the C struct.
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct SimulationEventCallbackInfo {
|
||||||
|
// Callback for collision events.
|
||||||
|
pub collision_callback: Option<CollisionCallback>,
|
||||||
|
pub collision_user_data: *mut c_void,
|
||||||
|
// Callback for trigger shape events (an object entered or left a trigger shape).
|
||||||
|
pub trigger_callback: Option<TriggerCallback>,
|
||||||
|
pub trigger_user_data: *mut c_void,
|
||||||
|
// Callback for when a constraint breaks (such as a joint with a force limit)
|
||||||
|
pub constraint_break_callback: Option<ConstraintBreakCallback>,
|
||||||
|
pub constraint_break_user_data: *mut c_void,
|
||||||
|
// Callback for when an object falls asleep or is awoken.
|
||||||
|
pub wake_sleep_callback: Option<WakeSleepCallback>,
|
||||||
|
pub wake_sleep_user_data: *mut c_void,
|
||||||
|
// Callback to get the next pose early for objects (if flagged with eENABLE_POSE_INTEGRATION_PREVIEW).
|
||||||
|
pub advance_callback: Option<AdvanceCallback>,
|
||||||
|
pub advance_user_data: *mut c_void,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SimulationEventCallbackInfo {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
collision_callback: None,
|
||||||
|
collision_user_data: std::ptr::null_mut(),
|
||||||
|
trigger_callback: None,
|
||||||
|
trigger_user_data: std::ptr::null_mut(),
|
||||||
|
constraint_break_callback: None,
|
||||||
|
constraint_break_user_data: std::ptr::null_mut(),
|
||||||
|
wake_sleep_callback: None,
|
||||||
|
wake_sleep_user_data: std::ptr::null_mut(),
|
||||||
|
advance_callback: None,
|
||||||
|
advance_user_data: std::ptr::null_mut(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// return 0 = `PxQueryHitType::eNONE`
|
||||||
|
/// return 1 = `PxQueryHitType::eTOUCH`
|
||||||
|
/// return 2 = `PxQueryHitType::eBLOCK`
|
||||||
|
pub type RaycastHitCallback = unsafe extern "C" fn(
|
||||||
|
*const PxRigidActor,
|
||||||
|
*const PxFilterData,
|
||||||
|
*const PxShape,
|
||||||
|
hit_flags: u32,
|
||||||
|
*const c_void,
|
||||||
|
) -> PxQueryHitType;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct FilterShaderCallbackInfo {
|
||||||
|
pub attributes0: u32,
|
||||||
|
pub attributes1: u32,
|
||||||
|
pub filterData0: PxFilterData,
|
||||||
|
pub filterData1: PxFilterData,
|
||||||
|
pub pairFlags: *mut PxPairFlags,
|
||||||
|
pub constantBlock: *const std::ffi::c_void,
|
||||||
|
pub constantBlockSize: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type SimulationFilterShader =
|
||||||
|
unsafe extern "C" fn(*mut FilterShaderCallbackInfo) -> PxFilterFlags;
|
||||||
|
|
||||||
|
pub type RaycastProcessTouchesCallback =
|
||||||
|
unsafe extern "C" fn(*const PxRaycastHit, u32, *mut c_void) -> bool;
|
||||||
|
pub type SweepProcessTouchesCallback =
|
||||||
|
unsafe extern "C" fn(*const PxSweepHit, u32, *mut c_void) -> bool;
|
||||||
|
pub type OverlapProcessTouchesCallback =
|
||||||
|
unsafe extern "C" fn(*const PxOverlapHit, u32, *mut c_void) -> bool;
|
||||||
|
|
||||||
|
pub type FinalizeQueryCallback = unsafe extern "C" fn(*mut c_void);
|
||||||
|
|
||||||
|
pub type AllocCallback =
|
||||||
|
unsafe extern "C" fn(u64, *const c_void, *const c_void, u32, *const c_void) -> *mut c_void;
|
||||||
|
|
||||||
|
pub type DeallocCallback = unsafe extern "C" fn(*const c_void, *const c_void);
|
||||||
|
|
||||||
|
pub type ZoneStartCallback =
|
||||||
|
unsafe extern "C" fn(*const i8, bool, u64, *const c_void) -> *mut c_void;
|
||||||
|
|
||||||
|
pub type ZoneEndCallback = unsafe extern "C" fn(*const c_void, *const i8, bool, u64, *const c_void);
|
||||||
|
|
||||||
|
pub type ErrorCallback =
|
||||||
|
unsafe extern "C" fn(PxErrorCode, *const i8, *const i8, u32, *const c_void);
|
||||||
|
|
||||||
|
pub type AssertHandler = unsafe extern "C" fn(*const i8, *const i8, u32, *mut bool, *const c_void);
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
pub fn physx_create_foundation() -> *mut PxFoundation;
|
||||||
|
pub fn physx_create_foundation_with_alloc(
|
||||||
|
allocator: *mut PxDefaultAllocator,
|
||||||
|
) -> *mut PxFoundation;
|
||||||
|
pub fn physx_create_physics(foundation: *mut PxFoundation) -> *mut PxPhysics;
|
||||||
|
|
||||||
|
pub fn get_default_allocator() -> *mut PxDefaultAllocator;
|
||||||
|
pub fn get_default_error_callback() -> *mut PxDefaultErrorCallback;
|
||||||
|
|
||||||
|
/// Destroy the returned callback object using PxQueryFilterCallback_delete.
|
||||||
|
pub fn create_raycast_filter_callback(
|
||||||
|
actor_to_ignore: *const PxRigidActor,
|
||||||
|
) -> *mut PxQueryFilterCallback;
|
||||||
|
|
||||||
|
/// Destroy the returned callback object using PxQueryFilterCallback_delete.
|
||||||
|
pub fn create_raycast_filter_callback_func(
|
||||||
|
callback: RaycastHitCallback,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxQueryFilterCallback;
|
||||||
|
|
||||||
|
pub fn create_raycast_buffer() -> *mut PxRaycastCallback;
|
||||||
|
pub fn create_sweep_buffer() -> *mut PxSweepCallback;
|
||||||
|
pub fn create_overlap_buffer() -> *mut PxOverlapCallback;
|
||||||
|
|
||||||
|
pub fn create_raycast_callback(
|
||||||
|
process_touches_callback: RaycastProcessTouchesCallback,
|
||||||
|
finalize_query_callback: FinalizeQueryCallback,
|
||||||
|
touches_buffer: *mut PxRaycastHit,
|
||||||
|
num_touches: u32,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxRaycastCallback;
|
||||||
|
pub fn create_sweep_callback(
|
||||||
|
process_touches_callback: SweepProcessTouchesCallback,
|
||||||
|
finalize_query_callback: FinalizeQueryCallback,
|
||||||
|
touches_buffer: *mut PxSweepHit,
|
||||||
|
num_touches: u32,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxSweepCallback;
|
||||||
|
pub fn create_overlap_callback(
|
||||||
|
process_touches_callback: OverlapProcessTouchesCallback,
|
||||||
|
finalize_query_callback: FinalizeQueryCallback,
|
||||||
|
touches_buffer: *mut PxOverlapHit,
|
||||||
|
num_touches: u32,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxOverlapCallback;
|
||||||
|
|
||||||
|
pub fn delete_raycast_callback(callback: *mut PxRaycastCallback);
|
||||||
|
pub fn delete_sweep_callback(callback: *mut PxSweepCallback);
|
||||||
|
pub fn delete_overlap_callback(callback: *mut PxOverlapCallback);
|
||||||
|
|
||||||
|
pub fn create_alloc_callback(
|
||||||
|
alloc_callback: AllocCallback,
|
||||||
|
dealloc_callback: DeallocCallback,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxAllocatorCallback;
|
||||||
|
|
||||||
|
pub fn create_profiler_callback(
|
||||||
|
zone_start_callback: ZoneStartCallback,
|
||||||
|
zone_end_callback: ZoneEndCallback,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxProfilerCallback;
|
||||||
|
|
||||||
|
pub fn get_alloc_callback_user_data(alloc_callback: *mut PxAllocatorCallback) -> *mut c_void;
|
||||||
|
|
||||||
|
pub fn create_error_callback(
|
||||||
|
error_callback: ErrorCallback,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxErrorCallback;
|
||||||
|
|
||||||
|
pub fn create_assert_handler(
|
||||||
|
error_callback: AssertHandler,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxAssertHandler;
|
||||||
|
|
||||||
|
pub fn get_default_simulation_filter_shader() -> *mut c_void;
|
||||||
|
|
||||||
|
/// Create a C++ proxy callback which will forward contact events to `Callback`.
|
||||||
|
/// The returned pointer must be freed by calling `destroy_contact_callback` when done using.
|
||||||
|
#[deprecated]
|
||||||
|
pub fn create_contact_callback(
|
||||||
|
callback: CollisionCallback,
|
||||||
|
userdata: *mut c_void,
|
||||||
|
) -> *mut PxSimulationEventCallback;
|
||||||
|
/// Deallocates the PxSimulationEventCallback that has previously been created
|
||||||
|
#[deprecated()]
|
||||||
|
pub fn destroy_contact_callback(callback: *mut PxSimulationEventCallback);
|
||||||
|
|
||||||
|
/// New interface to handle simulation events, replacing create_contact_callback.
|
||||||
|
pub fn create_simulation_event_callbacks(
|
||||||
|
callbacks: *const SimulationEventCallbackInfo,
|
||||||
|
) -> *mut PxSimulationEventCallback;
|
||||||
|
|
||||||
|
pub fn get_simulation_event_info(
|
||||||
|
callback: *mut PxSimulationEventCallback,
|
||||||
|
) -> *mut SimulationEventCallbackInfo;
|
||||||
|
|
||||||
|
pub fn destroy_simulation_event_callbacks(callback: *mut PxSimulationEventCallback);
|
||||||
|
|
||||||
|
/// Override the default filter shader in the scene with a custom function.
|
||||||
|
/// If call_default_filter_shader_first is set to true, this will first call the
|
||||||
|
/// built-in PhysX filter (that matches Physx 2.8 behavior) before your callback.
|
||||||
|
pub fn enable_custom_filter_shader(
|
||||||
|
scene_desc: *mut PxSceneDesc,
|
||||||
|
shader: SimulationFilterShader,
|
||||||
|
call_default_filter_shader_first: u32,
|
||||||
|
);
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// Should only be used in testing etc! This isn't generated as we don't generate op functions.
|
||||||
|
pub fn PxAssertHandler_opCall_mut(
|
||||||
|
self_: *mut PxAssertHandler,
|
||||||
|
expr: *const i8,
|
||||||
|
file: *const i8,
|
||||||
|
line: i32,
|
||||||
|
ignore: *mut bool,
|
||||||
|
) -> ();
|
||||||
|
}
|
14250
csbindgen-tests/src/physx/physx_generated.rs
vendored
Normal file
14250
csbindgen-tests/src/physx/physx_generated.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2815
csbindgen-tests/src/physx/unix/structgen.rs
vendored
Normal file
2815
csbindgen-tests/src/physx/unix/structgen.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2822
csbindgen-tests/src/physx/x86_64-pc-windows-msvc/structgen.rs
vendored
Normal file
2822
csbindgen-tests/src/physx/x86_64-pc-windows-msvc/structgen.rs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,4 +15,5 @@ homepage = "https://github.com/Cysharp/csbindgen/"
|
|||||||
repository = "https://github.com/Cysharp/csbindgen/"
|
repository = "https://github.com/Cysharp/csbindgen/"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syn = { version = "1.0.109", features = ["full"] }
|
syn = { version = "1.0.109", features = ["full"] }
|
||||||
|
regex = "1.7.3"
|
@ -13,7 +13,7 @@ pub struct Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct BindgenOptions {
|
pub struct BindgenOptions {
|
||||||
pub input_bindgen_file: PathBuf,
|
pub input_bindgen_files: Vec<PathBuf>,
|
||||||
pub input_extern_files: Vec<PathBuf>,
|
pub input_extern_files: Vec<PathBuf>,
|
||||||
pub method_filter: fn(method_name: String) -> bool,
|
pub method_filter: fn(method_name: String) -> bool,
|
||||||
pub rust_method_type_path: String,
|
pub rust_method_type_path: String,
|
||||||
@ -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,
|
||||||
@ -34,7 +35,7 @@ impl Default for Builder {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
options: BindgenOptions {
|
options: BindgenOptions {
|
||||||
input_bindgen_file: PathBuf::new(),
|
input_bindgen_files: vec![],
|
||||||
input_extern_files: vec![],
|
input_extern_files: vec![],
|
||||||
method_filter: |x| !x.starts_with('_'),
|
method_filter: |x| !x.starts_with('_'),
|
||||||
rust_method_type_path: "".to_string(),
|
rust_method_type_path: "".to_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(),
|
||||||
@ -59,9 +61,9 @@ impl Builder {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change 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_file = input_bindgen_file.as_ref().to_path_buf();
|
self.options.input_bindgen_files.push(input_bindgen_file.as_ref().to_path_buf());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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>>(
|
||||||
@ -166,7 +174,7 @@ impl Builder {
|
|||||||
&self,
|
&self,
|
||||||
csharp_output_path: P,
|
csharp_output_path: P,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
if self.has_input_file() {
|
if !self.options.input_bindgen_files.is_empty() {
|
||||||
let (_, csharp) = generate(GenerateKind::InputBindgen, &self.options)?;
|
let (_, csharp) = generate(GenerateKind::InputBindgen, &self.options)?;
|
||||||
|
|
||||||
let mut csharp_file = make_file(csharp_output_path.as_ref())?;
|
let mut csharp_file = make_file(csharp_output_path.as_ref())?;
|
||||||
@ -185,8 +193,8 @@ impl Builder {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_input_file(&self) -> bool {
|
fn has_input_files(&self) -> bool {
|
||||||
!self.options.input_bindgen_file.to_string_lossy().is_empty()
|
!self.options.input_bindgen_files.is_empty()
|
||||||
}
|
}
|
||||||
fn has_input_externals(&self) -> bool {
|
fn has_input_externals(&self) -> bool {
|
||||||
!self.options.input_extern_files.is_empty()
|
!self.options.input_extern_files.is_empty()
|
||||||
@ -197,7 +205,7 @@ impl Builder {
|
|||||||
rust_output_path: P,
|
rust_output_path: P,
|
||||||
csharp_output_path: P,
|
csharp_output_path: P,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
if self.has_input_file() {
|
if self.has_input_files() {
|
||||||
let (rust, csharp) = generate(GenerateKind::InputBindgen, &self.options)?;
|
let (rust, csharp) = generate(GenerateKind::InputBindgen, &self.options)?;
|
||||||
|
|
||||||
if let Some(rust) = rust {
|
if let Some(rust) = rust {
|
||||||
|
@ -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 {
|
||||||
@ -271,6 +274,9 @@ pub fn emit_csharp(
|
|||||||
None => "".to_string(),
|
None => "".to_string(),
|
||||||
};
|
};
|
||||||
let name = &item.enum_name;
|
let name = &item.enum_name;
|
||||||
|
if item.is_flags {
|
||||||
|
enum_string.push_str_ln(" [Flags]");
|
||||||
|
}
|
||||||
enum_string.push_str_ln(format!(" {accessibility} enum {name}{repr}").as_str());
|
enum_string.push_str_ln(format!(" {accessibility} enum {name}{repr}").as_str());
|
||||||
enum_string.push_str_ln(" {");
|
enum_string.push_str_ln(" {");
|
||||||
for (name, value) in &item.fields {
|
for (name, value) in &item.fields {
|
||||||
@ -289,6 +295,7 @@ pub fn emit_csharp(
|
|||||||
// This code is generated by csbindgen.
|
// This code is generated by csbindgen.
|
||||||
// DON'T CHANGE THIS DIRECTLY.
|
// DON'T CHANGE THIS DIRECTLY.
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
|
#pragma warning disable CS8500
|
||||||
#pragma warning disable CS8981
|
#pragma warning disable CS8981
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@ -321,6 +328,14 @@ fn convert_token_enum_repr(repr: &str) -> &str {
|
|||||||
"(i16)" => "short",
|
"(i16)" => "short",
|
||||||
"(i32)" => "int",
|
"(i32)" => "int",
|
||||||
"(i64)" => "long",
|
"(i64)" => "long",
|
||||||
|
"u8" => "byte",
|
||||||
|
"u16" => "ushort",
|
||||||
|
"u32" => "uint",
|
||||||
|
"u64" => "ulong",
|
||||||
|
"i8" => "sbyte",
|
||||||
|
"i16" => "short",
|
||||||
|
"i32" => "int",
|
||||||
|
"i64" => "long",
|
||||||
x => x,
|
x => x,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,8 @@ pub(crate) fn generate(
|
|||||||
generate_kind: GenerateKind,
|
generate_kind: GenerateKind,
|
||||||
options: &BindgenOptions,
|
options: &BindgenOptions,
|
||||||
) -> Result<(Option<String>, String), Box<dyn Error>> {
|
) -> Result<(Option<String>, String), Box<dyn Error>> {
|
||||||
let temp_input = [options.input_bindgen_file.clone()];
|
|
||||||
let (paths, generate_rust) = match generate_kind {
|
let (paths, generate_rust) = match generate_kind {
|
||||||
GenerateKind::InputBindgen => (temp_input.as_slice(), true),
|
GenerateKind::InputBindgen => (options.input_bindgen_files.as_slice(), true),
|
||||||
GenerateKind::InputExtern => (options.input_extern_files.as_slice(), false),
|
GenerateKind::InputExtern => (options.input_extern_files.as_slice(), false),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::{alias_map::AliasMap, builder::BindgenOptions, field_map::FieldMap, type_meta::*};
|
use crate::{alias_map::AliasMap, builder::BindgenOptions, field_map::FieldMap, type_meta::*};
|
||||||
use std::collections::HashSet;
|
use regex::Regex;
|
||||||
|
use std::{collections::HashSet};
|
||||||
use syn::{ForeignItem, Item, Pat, ReturnType};
|
use syn::{ForeignItem, Item, Pat, ReturnType};
|
||||||
|
|
||||||
enum FnItem {
|
enum FnItem {
|
||||||
@ -155,7 +156,15 @@ pub fn collect_struct(ast: &syn::File, result: &mut Vec<RustStruct>) {
|
|||||||
fields,
|
fields,
|
||||||
is_union: false,
|
is_union: false,
|
||||||
});
|
});
|
||||||
};
|
} else if let syn::Fields::Unnamed(f) = &t.fields {
|
||||||
|
let struct_name = t.ident.to_string();
|
||||||
|
let fields = collect_fields_unnamed(f);
|
||||||
|
result.push(RustStruct {
|
||||||
|
struct_name,
|
||||||
|
fields,
|
||||||
|
is_union: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,6 +185,23 @@ fn collect_fields(fields: &syn::FieldsNamed) -> Vec<FieldMember> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn collect_fields_unnamed(fields: &syn::FieldsUnnamed) -> Vec<FieldMember> {
|
||||||
|
let mut result = Vec::new();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
for field in &fields.unnamed {
|
||||||
|
i += 1;
|
||||||
|
let name = format!("Item{i}");
|
||||||
|
let t = parse_type(&field.ty);
|
||||||
|
result.push(FieldMember {
|
||||||
|
name: name,
|
||||||
|
rust_type: t,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
||||||
for item in ast.items.iter() {
|
for item in ast.items.iter() {
|
||||||
if let Item::Enum(t) = item {
|
if let Item::Enum(t) = item {
|
||||||
@ -207,7 +233,57 @@ pub fn collect_enum(ast: &syn::File, result: &mut Vec<RustEnum>) {
|
|||||||
enum_name,
|
enum_name,
|
||||||
fields,
|
fields,
|
||||||
repr,
|
repr,
|
||||||
|
is_flags: false,
|
||||||
});
|
});
|
||||||
|
} else if let Item::Macro(t) = item {
|
||||||
|
let last_segment = t.mac.path.segments.last().unwrap();
|
||||||
|
if last_segment.ident == "bitflags" {
|
||||||
|
// bitflags parsing template:
|
||||||
|
// $(#[$outer:meta])*
|
||||||
|
// $vis:vis struct $BitFlags:ident: $T:ty {
|
||||||
|
// $(
|
||||||
|
// $(#[$inner:ident $($args:tt)*])*
|
||||||
|
// const $Flag:ident = $value:expr;
|
||||||
|
// )*
|
||||||
|
// }
|
||||||
|
|
||||||
|
let token_string = t.mac.tokens.to_string();
|
||||||
|
|
||||||
|
let match1 = Regex::new("pub struct ([^ ]+) : ([^ ]+)")
|
||||||
|
.unwrap()
|
||||||
|
.captures(token_string.as_str())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let enum_name = match1.get(1).unwrap().as_str().to_string();
|
||||||
|
let repr = Some(match1.get(2).unwrap().as_str().to_string());
|
||||||
|
|
||||||
|
let fields = Regex::new("const ([^ ]+) = ([^;]+)[ ]*;")
|
||||||
|
.unwrap()
|
||||||
|
.captures_iter(token_string.as_str())
|
||||||
|
.map(|x| {
|
||||||
|
(
|
||||||
|
x.get(1).unwrap().as_str().to_string(),
|
||||||
|
Some(
|
||||||
|
x.get(2)
|
||||||
|
.unwrap()
|
||||||
|
.as_str()
|
||||||
|
.to_string()
|
||||||
|
.replace("Self :: ", "")
|
||||||
|
.replace(" . bits", "")
|
||||||
|
.trim()
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
result.push(RustEnum {
|
||||||
|
enum_name,
|
||||||
|
fields,
|
||||||
|
repr,
|
||||||
|
is_flags: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,7 @@ pub struct RustEnum {
|
|||||||
pub enum_name: String,
|
pub enum_name: String,
|
||||||
pub fields: Vec<(String, Option<String>)>, // name, value
|
pub fields: Vec<(String, Option<String>)>, // name, value
|
||||||
pub repr: Option<String>,
|
pub repr: Option<String>,
|
||||||
|
pub is_flags: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustType {
|
impl RustType {
|
||||||
|
44
dotnet-sandbox/BindingGroupExtensions.cs
vendored
Normal file
44
dotnet-sandbox/BindingGroupExtensions.cs
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
|
||||||
|
namespace Physx
|
||||||
|
{
|
||||||
|
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "Px")]
|
||||||
|
internal static unsafe partial class LibPhysx
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace CsBindgen
|
||||||
|
{
|
||||||
|
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "b3")]
|
||||||
|
internal static unsafe partial class LibBullet3
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "quiche_")]
|
||||||
|
internal static unsafe partial class LibQuiche
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "sqlite3_")]
|
||||||
|
public static unsafe partial class LibSqlite3
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace PixivApi.ImageFile
|
||||||
|
{
|
||||||
|
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "png_")]
|
||||||
|
internal static unsafe partial class LibPng16
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Jolt
|
||||||
|
{
|
||||||
|
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "JPH_")]
|
||||||
|
internal static unsafe partial class NativeMethods
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
14
dotnet-sandbox/CsbindgenDotnetConsoleApp.csproj
vendored
14
dotnet-sandbox/CsbindgenDotnetConsoleApp.csproj
vendored
@ -8,13 +8,6 @@
|
|||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<!--<Compile Remove="bullet3_bindgen.cs" />
|
|
||||||
<Compile Remove="lz4_bindgen.cs" />
|
|
||||||
<Compile Remove="quiche_bindgen.cs" />
|
|
||||||
<Compile Remove="zstd_bindgen.cs" />-->
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="../target/debug/csbindgen_tests.dll">
|
<None Include="../target/debug/csbindgen_tests.dll">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
@ -24,4 +17,11 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\GroupedNativeMethodsGenerator\GroupedNativeMethodsGenerator.csproj">
|
||||||
|
<OutputItemType>Analyzer</OutputItemType>
|
||||||
|
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
25
dotnet-sandbox/CsbindgenDotnetConsoleApp.sln
vendored
25
dotnet-sandbox/CsbindgenDotnetConsoleApp.sln
vendored
@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.5.33414.496
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsbindgenDotnetConsoleApp", "CsbindgenDotnetConsoleApp.csproj", "{3ED7C644-A880-426C-9BF1-24675D7A6299}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{3ED7C644-A880-426C-9BF1-24675D7A6299}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{3ED7C644-A880-426C-9BF1-24675D7A6299}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{3ED7C644-A880-426C-9BF1-24675D7A6299}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{3ED7C644-A880-426C-9BF1-24675D7A6299}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {DD647440-C307-4A09-9D97-DEA74660F797}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
12
dotnet-sandbox/NativeMethods.cs
vendored
12
dotnet-sandbox/NativeMethods.cs
vendored
@ -2,6 +2,7 @@
|
|||||||
// This code is generated by csbindgen.
|
// This code is generated by csbindgen.
|
||||||
// DON'T CHANGE THIS DIRECTLY.
|
// DON'T CHANGE THIS DIRECTLY.
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
|
#pragma warning disable CS8500
|
||||||
#pragma warning disable CS8981
|
#pragma warning disable CS8981
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@ -23,6 +24,9 @@ namespace CsBindgen
|
|||||||
[DllImport(__DllName, EntryPoint = "long_jpn_comment", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "long_jpn_comment", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void long_jpn_comment();
|
public static extern void long_jpn_comment();
|
||||||
|
|
||||||
|
[DllImport(__DllName, EntryPoint = "use_vec3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void use_vec3(my_int_vec3 _v3);
|
||||||
|
|
||||||
[DllImport(__DllName, EntryPoint = "other_2", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "other_2", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void other_2(NfcCard _hoge);
|
public static extern void other_2(NfcCard _hoge);
|
||||||
|
|
||||||
@ -156,6 +160,14 @@ namespace CsBindgen
|
|||||||
public fixed byte png_name[5];
|
public fixed byte png_name[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
internal unsafe partial struct my_int_vec3
|
||||||
|
{
|
||||||
|
public int Item1;
|
||||||
|
public int Item2;
|
||||||
|
public int Item3;
|
||||||
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
internal unsafe partial struct NfcCard
|
internal unsafe partial struct NfcCard
|
||||||
{
|
{
|
||||||
|
47
dotnet-sandbox/Program.cs
vendored
47
dotnet-sandbox/Program.cs
vendored
@ -8,11 +8,32 @@ using System.Reflection;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
|
// $vis:vis struct $BitFlags:ident: $T:ty {
|
||||||
|
// $(
|
||||||
|
// $(#[$inner:ident $($args:tt)*])*
|
||||||
|
// const $Flag:ident = $value:expr;
|
||||||
|
// )*
|
||||||
|
// }
|
||||||
|
|
||||||
|
var foo = """
|
||||||
|
[doc = " Flags for [`PxRigidBodyFlag`]"] # [derive (Default)] # [repr (transparent)] pub struct PxRigidBodyFlags : u16 { const Kinematic = 1 << 0 ; const UseKinematicTargetForSceneQueries = 1 << 1; const EnableCcd = 1 << 2 ; const EnableCcdFriction = 1 << 3 ; const EnableSpeculativeCcd = 1 << 4 ; const EnablePoseIntegrationPreview = 1 << 5 ; const EnableCcdMaxContactImpulse = 1 << 6 ; const RetainAccelerations = 1 << 7 ; const ForceKineKineNotifications = 1 << 8 ; const ForceStaticKineNotifications = 1 << 9 ; const EnableGyroscopicForces = 1 << 10 ; }
|
||||||
|
"""
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
var match1 = Regex.Match(foo, "pub struct ([^ ]+) : ([^ ]+) {");
|
||||||
|
|
||||||
|
var enum_name = match1.Groups[1].Value;
|
||||||
|
var enum_type = match1.Groups[2].Value;
|
||||||
|
|
||||||
|
var match2 = Regex.Matches(foo, "const ([^ ]+) = ([^;]+)[ ]*;");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -165,25 +186,25 @@ public static unsafe partial class LibraryImportNativeMethods
|
|||||||
const string __DllName = "csbindgen_tests";
|
const string __DllName = "csbindgen_tests";
|
||||||
|
|
||||||
|
|
||||||
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
|
//[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||||
[LibraryImport(__DllName, EntryPoint = "my_bool")]
|
//[LibraryImport(__DllName, EntryPoint = "my_bool")]
|
||||||
[return: MarshalAs(UnmanagedType.U1)]
|
//[return: MarshalAs(UnmanagedType.U1)]
|
||||||
public static partial bool my_bool([MarshalAs(UnmanagedType.U1)] bool x, [MarshalAs(UnmanagedType.U1)] bool y, [MarshalAs(UnmanagedType.U1)] bool z, bool* xr, bool* yr, bool* zr);
|
//public static partial bool my_bool([MarshalAs(UnmanagedType.U1)] bool x, [MarshalAs(UnmanagedType.U1)] bool y, [MarshalAs(UnmanagedType.U1)] bool z, bool* xr, bool* yr, bool* zr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//[LibraryImport(__DllName)]
|
////[LibraryImport(__DllName)]
|
||||||
//public static partial void foo(Foo f);
|
////public static partial void foo(Foo f);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[LibraryImport(__DllName, EntryPoint = "nullable_callback_test")]
|
//[LibraryImport(__DllName, EntryPoint = "nullable_callback_test")]
|
||||||
public static partial int nullable_callback_test([MarshalAs(UnmanagedType.FunctionPtr)] Func<int, int> cb);
|
//public static partial int nullable_callback_test([MarshalAs(UnmanagedType.FunctionPtr)] Func<int, int> cb);
|
||||||
|
|
||||||
[LibraryImport(__DllName, EntryPoint = "nullable_callback_test")]
|
//[LibraryImport(__DllName, EntryPoint = "nullable_callback_test")]
|
||||||
[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
|
//[UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||||
public static partial int nullable_callback_test2(delegate* unmanaged[Cdecl]<int, int> cb);
|
//public static partial int nullable_callback_test2(delegate* unmanaged[Cdecl]<int, int> cb);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4198
dotnet-sandbox/jolt_bindgen.cs
vendored
Normal file
4198
dotnet-sandbox/jolt_bindgen.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11271
dotnet-sandbox/libphysx_csbindgen.cs
vendored
Normal file
11271
dotnet-sandbox/libphysx_csbindgen.cs
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
dotnet-sandbox/libpng16_csbindgen.cs
vendored
1
dotnet-sandbox/libpng16_csbindgen.cs
vendored
@ -2,6 +2,7 @@
|
|||||||
// This code is generated by csbindgen.
|
// This code is generated by csbindgen.
|
||||||
// DON'T CHANGE THIS DIRECTLY.
|
// DON'T CHANGE THIS DIRECTLY.
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
|
#pragma warning disable CS8500
|
||||||
#pragma warning disable CS8981
|
#pragma warning disable CS8981
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
1
dotnet-sandbox/lz4_bindgen.cs
vendored
1
dotnet-sandbox/lz4_bindgen.cs
vendored
@ -2,6 +2,7 @@
|
|||||||
// This code is generated by csbindgen.
|
// This code is generated by csbindgen.
|
||||||
// DON'T CHANGE THIS DIRECTLY.
|
// DON'T CHANGE THIS DIRECTLY.
|
||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
|
#pragma warning disable CS8500
|
||||||
#pragma warning disable CS8981
|
#pragma warning disable CS8981
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
@ -43,7 +43,7 @@ MonoBehaviour:
|
|||||||
width: 1953
|
width: 1953
|
||||||
height: 1546
|
height: 1546
|
||||||
m_ShowMode: 4
|
m_ShowMode: 4
|
||||||
m_Title: Game
|
m_Title: Console
|
||||||
m_RootView: {fileID: 11}
|
m_RootView: {fileID: 11}
|
||||||
m_MinSize: {x: 875, y: 300}
|
m_MinSize: {x: 875, y: 300}
|
||||||
m_MaxSize: {x: 10000, y: 10000}
|
m_MaxSize: {x: 10000, y: 10000}
|
||||||
@ -97,7 +97,7 @@ MonoBehaviour:
|
|||||||
m_MinSize: {x: 640, y: 601}
|
m_MinSize: {x: 640, y: 601}
|
||||||
m_MaxSize: {x: 4000, y: 4021}
|
m_MaxSize: {x: 4000, y: 4021}
|
||||||
vertical: 0
|
vertical: 0
|
||||||
controlID: 2323
|
controlID: 123
|
||||||
--- !u!114 &5
|
--- !u!114 &5
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 52
|
m_ObjectHideFlags: 52
|
||||||
@ -148,7 +148,7 @@ MonoBehaviour:
|
|||||||
m_MinSize: {x: 200, y: 100}
|
m_MinSize: {x: 200, y: 100}
|
||||||
m_MaxSize: {x: 16192, y: 8096}
|
m_MaxSize: {x: 16192, y: 8096}
|
||||||
vertical: 0
|
vertical: 0
|
||||||
controlID: 24
|
controlID: 231
|
||||||
--- !u!114 &7
|
--- !u!114 &7
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 52
|
m_ObjectHideFlags: 52
|
||||||
@ -173,7 +173,7 @@ MonoBehaviour:
|
|||||||
m_MinSize: {x: 300, y: 200}
|
m_MinSize: {x: 300, y: 200}
|
||||||
m_MaxSize: {x: 24288, y: 16192}
|
m_MaxSize: {x: 24288, y: 16192}
|
||||||
vertical: 0
|
vertical: 0
|
||||||
controlID: 17
|
controlID: 108
|
||||||
--- !u!114 &8
|
--- !u!114 &8
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 52
|
m_ObjectHideFlags: 52
|
||||||
@ -193,8 +193,8 @@ MonoBehaviour:
|
|||||||
y: 0
|
y: 0
|
||||||
width: 456
|
width: 456
|
||||||
height: 1496
|
height: 1496
|
||||||
m_MinSize: {x: 276, y: 71}
|
m_MinSize: {x: 275, y: 50}
|
||||||
m_MaxSize: {x: 4001, y: 4021}
|
m_MaxSize: {x: 4000, y: 4000}
|
||||||
m_ActualView: {fileID: 20}
|
m_ActualView: {fileID: 20}
|
||||||
m_Panes:
|
m_Panes:
|
||||||
- {fileID: 20}
|
- {fileID: 20}
|
||||||
@ -236,7 +236,7 @@ MonoBehaviour:
|
|||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 1
|
m_EditorHideFlags: 1
|
||||||
m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0}
|
m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
m_Name: ProjectSettingsWindow
|
m_Name: ConsoleWindow
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Position:
|
m_Position:
|
||||||
@ -245,14 +245,14 @@ MonoBehaviour:
|
|||||||
y: 0
|
y: 0
|
||||||
width: 997
|
width: 997
|
||||||
height: 608
|
height: 608
|
||||||
m_MinSize: {x: 311, y: 221}
|
m_MinSize: {x: 101, y: 121}
|
||||||
m_MaxSize: {x: 4001, y: 4021}
|
m_MaxSize: {x: 4001, y: 4021}
|
||||||
m_ActualView: {fileID: 18}
|
m_ActualView: {fileID: 24}
|
||||||
m_Panes:
|
m_Panes:
|
||||||
- {fileID: 24}
|
- {fileID: 24}
|
||||||
- {fileID: 18}
|
- {fileID: 18}
|
||||||
m_Selected: 1
|
m_Selected: 0
|
||||||
m_LastSelected: 0
|
m_LastSelected: 1
|
||||||
--- !u!114 &11
|
--- !u!114 &11
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 52
|
m_ObjectHideFlags: 52
|
||||||
@ -348,7 +348,7 @@ MonoBehaviour:
|
|||||||
m_MinSize: {x: 200, y: 200}
|
m_MinSize: {x: 200, y: 200}
|
||||||
m_MaxSize: {x: 16192, y: 16192}
|
m_MaxSize: {x: 16192, y: 16192}
|
||||||
vertical: 1
|
vertical: 1
|
||||||
controlID: 123
|
controlID: 109
|
||||||
--- !u!114 &15
|
--- !u!114 &15
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 52
|
m_ObjectHideFlags: 52
|
||||||
@ -373,7 +373,7 @@ MonoBehaviour:
|
|||||||
m_MinSize: {x: 200, y: 100}
|
m_MinSize: {x: 200, y: 100}
|
||||||
m_MaxSize: {x: 16192, y: 8096}
|
m_MaxSize: {x: 16192, y: 8096}
|
||||||
vertical: 0
|
vertical: 0
|
||||||
controlID: 124
|
controlID: 110
|
||||||
--- !u!114 &16
|
--- !u!114 &16
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 52
|
m_ObjectHideFlags: 52
|
||||||
@ -560,9 +560,9 @@ MonoBehaviour:
|
|||||||
m_IsLocked: 0
|
m_IsLocked: 0
|
||||||
m_FolderTreeState:
|
m_FolderTreeState:
|
||||||
scrollPos: {x: 0, y: 0}
|
scrollPos: {x: 0, y: 0}
|
||||||
m_SelectedIDs: b65f0000
|
m_SelectedIDs: de5f0000
|
||||||
m_LastClickedID: 24502
|
m_LastClickedID: 24542
|
||||||
m_ExpandedIDs: 00000000b65f000000ca9a3bffffff7f
|
m_ExpandedIDs: 00000000de5f000000ca9a3bffffff7f
|
||||||
m_RenameOverlay:
|
m_RenameOverlay:
|
||||||
m_UserAcceptedRename: 0
|
m_UserAcceptedRename: 0
|
||||||
m_Name:
|
m_Name:
|
||||||
@ -590,7 +590,7 @@ MonoBehaviour:
|
|||||||
scrollPos: {x: 0, y: 0}
|
scrollPos: {x: 0, y: 0}
|
||||||
m_SelectedIDs:
|
m_SelectedIDs:
|
||||||
m_LastClickedID: 0
|
m_LastClickedID: 0
|
||||||
m_ExpandedIDs: 00000000b65f0000
|
m_ExpandedIDs: 00000000de5f0000
|
||||||
m_RenameOverlay:
|
m_RenameOverlay:
|
||||||
m_UserAcceptedRename: 0
|
m_UserAcceptedRename: 0
|
||||||
m_Name:
|
m_Name:
|
||||||
@ -617,7 +617,7 @@ MonoBehaviour:
|
|||||||
m_ListAreaState:
|
m_ListAreaState:
|
||||||
m_SelectedInstanceIDs:
|
m_SelectedInstanceIDs:
|
||||||
m_LastClickedInstanceID: 0
|
m_LastClickedInstanceID: 0
|
||||||
m_HadKeyboardFocusLastEvent: 1
|
m_HadKeyboardFocusLastEvent: 0
|
||||||
m_ExpandedInstanceIDs: c6230000
|
m_ExpandedInstanceIDs: c6230000
|
||||||
m_RenameOverlay:
|
m_RenameOverlay:
|
||||||
m_UserAcceptedRename: 0
|
m_UserAcceptedRename: 0
|
||||||
@ -720,21 +720,21 @@ MonoBehaviour:
|
|||||||
scrollPos: {x: 0, y: 0}
|
scrollPos: {x: 0, y: 0}
|
||||||
m_SelectedIDs:
|
m_SelectedIDs:
|
||||||
m_LastClickedID: 0
|
m_LastClickedID: 0
|
||||||
m_ExpandedIDs: 6ccbffffb6cbffff16cdffff84cfffffcecfffff2ed1ffff2cd5ffff76d5ffffd6d6ffff2ad9ffff74d9ffffd4daffff1eddffff68ddffffc8deffff24e1ffff6ee1ffffcee2ffff74e6ffffbee6ffff1ee8ffff26eaffff70eaffffd0ebfffffcf3ffff8af4ffffccf4ffff3af6ffff22fbffff78780000
|
m_ExpandedIDs: 18d4ffff60d4ffffc0d5ffff12d8ffff5ad8ffffbad9ffff04dcffff4cdcffffacddfffff6dfffff3ee0ffff58e0ffff00e1ffff48e1ffffa8e2ffff90e6ffffd8e6ffff38e8ffff5cebffffa4ebffff04edffff2afbffff
|
||||||
m_RenameOverlay:
|
m_RenameOverlay:
|
||||||
m_UserAcceptedRename: 0
|
m_UserAcceptedRename: 0
|
||||||
m_Name: Text (Legacy)
|
m_Name:
|
||||||
m_OriginalName: Text (Legacy)
|
m_OriginalName:
|
||||||
m_EditFieldRect:
|
m_EditFieldRect:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
x: 0
|
x: 0
|
||||||
y: 0
|
y: 0
|
||||||
width: 0
|
width: 0
|
||||||
height: 0
|
height: 0
|
||||||
m_UserData: -3120
|
m_UserData: 0
|
||||||
m_IsWaitingForDelay: 0
|
m_IsWaitingForDelay: 0
|
||||||
m_IsRenaming: 0
|
m_IsRenaming: 0
|
||||||
m_OriginalEventType: 4
|
m_OriginalEventType: 11
|
||||||
m_IsRenamingFilename: 0
|
m_IsRenamingFilename: 0
|
||||||
m_ClientGUIView: {fileID: 9}
|
m_ClientGUIView: {fileID: 9}
|
||||||
m_SearchString:
|
m_SearchString:
|
||||||
@ -991,9 +991,9 @@ MonoBehaviour:
|
|||||||
m_PlayAudio: 0
|
m_PlayAudio: 0
|
||||||
m_AudioPlay: 0
|
m_AudioPlay: 0
|
||||||
m_Position:
|
m_Position:
|
||||||
m_Target: {x: 639.1462, y: 631.1552, z: -5.5470376}
|
m_Target: {x: 499.8913, y: 522.92053, z: 0}
|
||||||
speed: 2
|
speed: 2
|
||||||
m_Value: {x: 639.1462, y: 631.1552, z: -5.5470376}
|
m_Value: {x: 499.8913, y: 522.92053, z: 0}
|
||||||
m_RenderMode: 0
|
m_RenderMode: 0
|
||||||
m_CameraMode:
|
m_CameraMode:
|
||||||
drawMode: 0
|
drawMode: 0
|
||||||
@ -1044,9 +1044,9 @@ MonoBehaviour:
|
|||||||
speed: 2
|
speed: 2
|
||||||
m_Value: {x: 0, y: 0, z: 0, w: 1}
|
m_Value: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_Size:
|
m_Size:
|
||||||
m_Target: 636.09985
|
m_Target: 494.99554
|
||||||
speed: 2
|
speed: 2
|
||||||
m_Value: 636.09985
|
m_Value: 494.99554
|
||||||
m_Ortho:
|
m_Ortho:
|
||||||
m_Target: 1
|
m_Target: 1
|
||||||
speed: 2
|
speed: 2
|
||||||
|
Loading…
Reference in New Issue
Block a user