Skip to content

Latest commit

 

History

History
60 lines (44 loc) · 2.11 KB

File metadata and controls

60 lines (44 loc) · 2.11 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>net8.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" },
};

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.