.NET 10 bindings and code-generation tooling for CUE
See LICENSE in this repository and the license of the libcue/CUE
project for the respective licensing terms.
Warning
cue-dotnet depends on the separate libcue
project. The native library must be built first and copied to the root
of this repository before building, testing, or running the generator.
This project integrates with the native Go implementation of cue through a CGO adapter forked from libcue:
flowchart LR
A["cuelang/cue<br/>Go"]
B["intresrl/libcue<br/>Go + CGO"]
D["this repository<br/>Cue.Api<br/>P/Invoke"]
E[".NET consumers"]
F["this repository<br/>Cue.Generator<br/>C#"]
G["Generated C#"]
A --> B --> D
D --> E
D --> F --> G
This repository has the following layout:
Cue.Api--- managed .NET API overlibcueusing P/Invoke.Cue.Generator--- CLI that compiles CUE schemas and generates C# code.Examples--- sample CUE schemas, generated C# files, andgenerator debug output.
- .NET 10 SDK.
- Go 1.25.0: CGO must be enabled and a compatible C compiler must be installed.
To check CGO run:
go env CGO_ENABLED # should output '1'A convenient checkout layout is:
<your_clone_directory>/
├── libcue/
└── cue-dotnet/
The output of the libcue build must be generated or copied into the root of
cue-dotnet.
On Linux:
cd libcue && go build -buildmode=c-shared -o ../cue-dotnet/libcue.soOn Windows (Git Bash, msys2 or similar):
Caution
On Windows, keep the "lib" prefix in libcue.dll to avoid overwriting cue.h in libcue.
cd libcue && go build -buildmode=c-shared -o ../cue-dotnet/libcue.dllAfter the native dependency is present in the repository root:
dotnet restore
dotnet buildWarning
Run a rebuild every time you make changes in libcue. The DLL or shared library is copied in the output directory of Cue.Api.
CUE operations begin with a context:
using Cuelang.Cue;
using var ctx = new CueContext();
using var value = ctx.Compile("name: string");CueContext owns the native CUE context while Value represents a
managed wrapper around a native CUE value.
Keep the context alive for the lifetime of values created from it and dispose native-backed objects appropriately.
Cue.Generator is a .NET CLI that compiles a CUE schema and generates
C# source.
You may execute it like this:
# dotnet run --project Cue.Generator -- <input.cue> <output.cs>
dotnet run --project Cue.Generator -- Examples/simple.cue generated.csAn optional debug output path can be supplied via the --debug parameter.
The current implementation and tests cover CUE concepts including:
- structs;
- lists;
- definitions;
- references;
- nullable values;
- disjunctions;
- constrained primitive values;
- expressions;
- discriminated alternatives;
matchNexpressions.
The generated representation can model alternatives as interfaces and record implementations instead of arbitrarily reducing a CUE disjunction to one type.