Skip to content

.NET Uniffi bindings - #374

Closed
dkackman wants to merge 69 commits into
xch-dev:mainfrom
dkackman:uniffi
Closed

.NET Uniffi bindings#374
dkackman wants to merge 69 commits into
xch-dev:mainfrom
dkackman:uniffi

Conversation

@dkackman

@dkackman dkackman commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Add C#/.NET bindings

Uses the bindy framework and adds UniFFI support, specifically UniFFI-bindgen-cs.

CS Projects

Adds another binding project that includes a uniffi crate, a c# assembly that can be published to nuget and xunit tests.

github workflow

Normal CI builds the .net assembly and the new github workflow creates and packages the nuget package.

  • targets macos-arm64, windows-x64, linux-x64 (more targets can be added as needed)
  • publishes to nuget.org. (Requires a nuget account and associated secrets - I've got one. We can publish under that or you can make one to keep it under your moniker. either way works for me)

dkackman and others added 29 commits April 8, 2026 06:26
Adds a new `uniffi` feature-gated backend to the bindy type conversion
framework, mirroring the existing pyo3/napi/wasm backends, with
`Uniffi` / `UniffiContext` marker types and conversions for BigInt,
u64, u128 (as String), and bytes types (as Vec<u8>).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Move uniffi dependency to workspace (consistent with all other deps)
- Add impl_self!(i64) and impl_self!(i128) to uniffi_impls.rs so signed
  64/128-bit types work with the uniffi feature
- Fix redundant Ok(...)? wrapping in IntoRust impls for u64 and u128
- Clarify the usize comment to reference the lib.rs blanket impl

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Create the uniffi/ crate as the C# bindings entry point. This required
several supporting changes:

- Add uniffi workspace member and create Cargo.toml, build.rs, src/lib.rs
- Hand-write the Clvm::alloc method dispatching ClvmType enum variants
- Add {usize} -> u32 mapping in bindings.json and FromRust/IntoRust impls
- Fix orphan rules: use concrete UniffiContext instead of generic T, add
  Clone derive to wrapper structs, add blanket Arc<U> FromRust/IntoRust
- Emit static methods as free functions (UniFFI 0.28 limitation)
- Gate peer/rpc types behind uniffi feature alongside napi/pyo3
- Add chia-sdk-client and chia-ssl deps to bindy uniffi feature

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Removes the num-bigint dependency from the uniffi crate (BigInt conversions
live entirely in bindy/src/uniffi_impls.rs). Adds a comment above Clvm::alloc
explaining that nil/int/bool/string/bytes must go through typed helper methods
in the UniFFI backend rather than the dynamic alloc path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Also fix String.Format ambiguity in generated bindings where Clvm.String(string)
method shadowed System.String within the Clvm class body.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Clvm class defines a String(string) method which shadows System.String
in the class body, causing CS0119 on the ObjectDisposedException /
OverflowException guard lines. Patch the two affected call sites in the
generated file to use System.String.Format explicitly.

Also suppress a nullability warning in CurryRoundtrip by asserting non-null
inline with the null-forgiving operator.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the manual sed step with a PatchClvmStringAmbiguity MSBuild
target that runs BeforeTargets="CoreCompile" on every build. The patch
is idempotent, so regenerating the bindings and running dotnet test is
enough — no separate script needed.

Update README to remove the manual patch step and reference the build
target instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use RoslynCodeTaskFactory to apply the String.Format fix in pure .NET,
eliminating the sed dependency. Works identically on Windows, macOS,
and Linux with no external tools.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Also adds InternalsVisibleTo in ChiaWalletSdk.csproj so the test
assembly can access the internal types in the generated bindings.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dkackman
dkackman marked this pull request as draft April 8, 2026 18:12
@dkackman
dkackman marked this pull request as ready for review April 10, 2026 16:08
@dkackman

dkackman commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

closing in favor of combined uniffi PR #406

@dkackman dkackman closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant