Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 2.22 KB

README.md

File metadata and controls

64 lines (47 loc) · 2.22 KB

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 look 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",

    // Pass raw source code instead
    // TreatInputFileAsRawSourceCode = true,
    InputFile = "path/header.h",
    OutputFile = "path/Header.cs",
    
    IncludeDirectories = { "path/include" },
    SystemIncludeDirectories = { "path/include" },

    GenerateFunctionPointers = true,
    GenerateMacros = 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.