Skip to content

BeanCheeseBurrito/Bindgen.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bindgen.NET

MIT Nuget

WORK IN PROGRESS

Usage

Download the nuget package.

dotnet add package Bindgen.NET --version *-*

A runtime id is needed to resolve the ClangSharp native dependencies. Your project file should like like this.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0</TargetFramework>
        <!-- This line is required -->
        <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Bindgen.NET" Version="*-*" />
    </ItemGroup>

</Project>

Configure your binding options and generate!

Example:

using Bindgen.NET;

BindingOptions exampleConfig = new()
{
    Namespace = "ExampleNamespace",
    Class = "ExampleClass",

    DllImportPath = "libexample",
    
    // Some options require manually exporting symbols
    // It will try different name combinations like DllImportAttribute
    DllFilePaths = { 
        "libexample", 
        "example.so", 
        // List your nuget native folders too
        "runtimes/linux-x64/native/example",
        "runtimes/osx-x64/native/libexample",
        "runtimes/win-x64/native/libexample.dll" 
    },

    // Pass raw source code instead
    // TreatInputFileAsRawSourceCode = true,
    InputFile = "path/header.h",
    OutputFile = "path/Header.cs",
    
    // Optional included built-in clang headers
    IncludeBuiltInClangHeaders = true,
    IncludeDirectories = { "path/include" },
    SystemIncludeDirectories = { "path/include" },

    GenerateFunctionPointers = true,
    GenerateMacros = true,
    GenerateExternVariables = true,
    GenerateSuppressGcTransition = true,
    GenerateStructEqualityFunctions = true
};

string output = BindingGenerator.Generate(exampleConfig);

A runnable example can be found here.

A basic example of generated bindings can be found in here.

A real world example of generated bindings can be seen in the Flecs.NET repo here.

Releases

No releases published

Packages

No packages published

Languages