Skip to content

Unity / C# bindings (oxbitnet-csharp) #7

Description

@m96-chan

Summary

Add C# bindings for oxbitnet, enabling Unity and .NET applications to run BitNet b1.58 inference with wgpu.

Approach

  • C FFI crate (oxbitnet-ffi) wrapping the Rust oxbitnet crate (shared with Swift bindings)
  • C# P/Invoke wrapper with managed API
  • Unity-friendly: native plugin (.so/.dylib/.dll) + C# scripts
  • Publish as NuGet package: OxBitNet
  • Streaming token output via callback delegate or IAsyncEnumerable

API sketch

var model = await BitNet.Load("model.gguf");

var messages = new[] {
    new ChatMessage("system", "You are a helpful assistant."),
    new ChatMessage("user", "Hello!")
};

model.Chat(messages, token => Console.Write(token), new GenerateOptions {
    Temperature = 0.7f,
    MaxTokens = 256
});

model.Dispose();

Unity usage

public class BitNetChat : MonoBehaviour
{
    private BitNet model;

    async void Start()
    {
        model = await BitNet.Load("model.gguf");
    }

    public async void OnSend(string userMessage)
    {
        await model.Chat(
            new[] { new ChatMessage("user", userMessage) },
            token => chatUI.AppendText(token)
        );
    }
}

Tasks

  • C FFI crate (oxbitnet-ffi) with stable ABI (shared with Swift bindings (oxbitnet-swift) #6)
  • C# P/Invoke bindings + managed wrapper
  • Unity native plugin setup (multi-platform .so/.dylib/.dll)
  • Interactive chat example (.NET console)
  • Unity sample scene
  • NuGet publish in CI
  • README with quick start (both .NET and Unity)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions