Home About Eric Topics SourceGear

2023-04-10 13:00:00

Binding Generator Preview Release

This is part of a series on Native AOT.
Previous -- Top -- Next

I have finally published a preview release of the Native AOT binding generator I've been working on. I wouldn't call it "production-ready" yet, but having the tool publicly available makes it more tangible and real. Folks can give it a try, and give feedback if they wish.

There's a GitHub repo for samples and other information:


The content there is fairly bare-bones right now, but there are a few Rust samples, including the QuestPDF demo I discussed a few weeks ago, plus two little apps that use Avalonia. One of the Avalonia samples is written against the very basic controls. The other uses NXUI, which is a pretty cool library offering a different way of working with Avalonia:


These "Work on My Machine", and should hopefully work for you as well.

A word about ugliness

Some folks have contributed various aesthetic opinions about the nature of .NET APIs projected into Rust. :-)

The simple fact is that Rust lacks a number of key things that C# uses a lot:

This impedance mismatch causes the Rust projection of a .NET API to be far less ergonomic than things are in C#.

So I am certainly not suggesting that Rust could become a preferred way of using .NET. I am exploring the boundaries of what is possible in interop situations. Some .NET libraries turn out better than others. For Rust, Avalonia hits almost all of the difficulties at one time. That makes it a nice test case, but not necessarily a practical use case.

What got published

The binding generator itself is contained in a nuget package:


But that package is not intended to be used directly. Rather, a Cargo build script will deal with all that. The dependency for that build script is this crate:


Several things need to be done to integrate that build script into a Cargo project. Take a look at the samples I mentioned above. Also, there is a Cargo subcommand designed to help make this easier:


If you have any questions or feedback, please feel free to post in the Discussions or Issues area of the sourcegear/bridge-info repo linked above.