RustMaui.Generators
1.0.0.3
dotnet add package RustMaui.Generators --version 1.0.0.3
NuGet\Install-Package RustMaui.Generators -Version 1.0.0.3
<PackageReference Include="RustMaui.Generators" Version="1.0.0.3"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="RustMaui.Generators" Version="1.0.0.3" />
<PackageReference Include="RustMaui.Generators"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add RustMaui.Generators --version 1.0.0.3
#r "nuget: RustMaui.Generators, 1.0.0.3"
#:package RustMaui.Generators@1.0.0.3
#addin nuget:?package=RustMaui.Generators&version=1.0.0.3
#tool nuget:?package=RustMaui.Generators&version=1.0.0.3
RustMaui.Generators
Build-time package for .NET MAUI + Rust projects.
Reads your rust/lib.rs, creates the user-owned companion file if it is missing, and generates matching [LibraryImport] P/Invoke bindings into Rust.Generated.cs — automatically, on every build.
How it works
Add a Rust export:
#[no_mangle]
pub extern "C" fn compute(value: f32) -> f32 {
value * 2.0
}
The generator emits:
// Rust.Generated.cs — do not edit
[LibraryImport(Lib, EntryPoint = "compute")]
[UnmanagedCallConv(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial float Compute(float value);
Call it from C#:
var result = Rust.Compute(3.14f);
On first build the package also creates Rust.cs if it is missing. That file is yours to keep and edit.
Override a binding
Declare the same EntryPoint in your Rust.cs — the generator skips it:
// Rust.cs — your file, generator leaves this alone
[LibraryImport(Lib, EntryPoint = "compute")]
public static partial float Compute(float value);
Rename the bindings type
Use one property, RustBindingsName, to rename the partial class and the default interop filenames together.
<PropertyGroup>
<RustBindingsName>MyBindings</RustBindingsName>
</PropertyGroup>
That gives you:
MyBindings.csas the user-owned companion fileMyBindings.Generated.csas the generated filepublic static partial class MyBindings
If you want a non-default generated file path, keep RustBindingsName for the base name and override only RustGeneratedFile.
Unknown types
If the generator cannot map a Rust type to C#, it emits a TODO comment instead of broken code:
// TODO: bind 'complex_func' — unrecognized type(s), declare manually in Rust.cs
Setup
Installed via RustMaui.Templates
Zero config. The template package includes the generator and emits a fixed RustMaui.Generators package reference in the scaffolded app.
Install into an existing app from NuGet
You can also add the package to an existing MAUI project with the CLI:
dotnet add package RustMaui.Generators
After that, make sure your project follows the expected layout or set the relevant MSBuild overrides shown below.
Manual install
<PackageReference Include="RustMaui.Generators" Version="1.0.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
The package reads rust/Cargo.toml to infer the native library name and writes the generated Lib constant for you when the user-owned companion file does not already define one.
On Apple targets, RustMaui uses one linking model consistently:
- iOS device and iOS simulator: statically linked Rust archive, imported from
__Internal - MacCatalyst: bundled dynamic library, imported by library name
That means custom Rust code should treat all iOS targets as the static-link path. Only MacCatalyst should rely on dynamic loading behavior.
The package also wires the build-time generation logic from the repo-level build/RustMaui.Generators.targets file. RustCrateDir defaults to the template layout, but you can override it.
Optional MSBuild properties
The package works with no required properties in template-generated projects, but it supports these optional overrides in your app .csproj:
| Property | Default value | Purpose |
|---|---|---|
RustCrateDir |
../../rust from the app project directory |
Path to the Rust crate root |
RustBindingsName |
Rust |
Base name for the partial class and default interop files |
RustLibName |
Auto-read from Cargo.toml [package].name and normalized for Rust |
Native library name |
RustProfile |
release |
Cargo profile to build with |
RustCargoToolchainArgs |
Empty | Extra toolchain selector arguments such as +nightly |
RustGeneratorSrcDir |
$(RustCrateDir) |
Override path for lib.rs when it is not under the crate root |
RustGeneratedFile |
$(MSBuildProjectDirectory)\$(RustBindingsName).Generated.cs |
Override output path for the generated bindings file |
For example, with a custom layout:
<PropertyGroup>
<RustBindingsName>MyBindings</RustBindingsName>
<RustCrateDir>..\..\native\mycrate</RustCrateDir>
<RustGeneratorSrcDir>..\..\rust</RustGeneratorSrcDir>
<RustLibName>your_crate_name</RustLibName>
<RustProfile>release</RustProfile>
<RustGeneratedFile>Generated\MyBindings.g.cs</RustGeneratedFile>
</PropertyGroup>
Supported type mappings
| Rust | C# |
|---|---|
i32 / c_int |
int |
u32 / c_uint |
uint |
f32 / c_float |
float |
f64 / c_double |
double |
i64 / u64 |
long / ulong |
isize / usize |
nint / nuint |
*mut c_void / *const c_void |
IntPtr |
*mut u8 / *const u8 |
IntPtr |
Everything else → TODO comment.
Repo layout
Inside the combined RustMaui repo the package lives here:
src/RustMaui.Generators/
build/RustMaui.Generators.targets
build/RustMaui.Generators.props
The template package under src/RustMaui.Templates/ consumes this package.
Both packages are released together from the combined repo via .github/workflows/nuget-release.yml.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0.3 | 99 | 4/26/2026 |
| 1.0.0.2 | 111 | 4/26/2026 |
| 1.0.0.1 | 94 | 4/26/2026 |
| 1.0.0-pre15 | 99 | 4/26/2026 |
| 1.0.0-pre13 | 97 | 4/26/2026 |
| 1.0.0-pre12 | 93 | 4/26/2026 |