LLVM FRONT-END // C# 14 // .NET 11

C# TO NATIVE
THROUGH LLVM.

csharpc compiles C# source, and .NET libraries shipped as IL, straight to small, fast, hardened native executables: what clang is to C and rustc to Rust. Use it on its own, or as the AOT layer behind PublishAot.

[oracle] byte-identical to real .NET [order] security > speed > size [target] NativeAOT parity
> csharpc hello.cs -o hello
> ./hello         Hello from C# compiled by LLVM!
> pipeline       roslyn -> cfg -> llvm ir -> lto -> clang link
> runtime        csrt // gc // threads // unwinding // no jit
> hardening     relro // nx stack // stack-clash // fortify=3
> targets        linux x64/arm64 // macos arm64 // windows x64 // wasm32-wasi
> rule           not supported yet = diagnostic, never a guess
>
Lines in the repo
233,942
counted when this site was built
Code generation
45,268
CFG and IL to LLVM IR
C runtime
20,951
GC, unwinding, threads, OS
Documents
87
design notes, ADRs and IL notes

compile path

FROM SOURCE TO ONE NATIVE FILE.

Roslyn's control-flow graph is csharpc's mid-level IR; everything between it and LLVM is csharpc.

  1. 01 // inputC# or IL

    .cs files, a .csproj, or DLLs and NuGet packages read through the IL front-end.

  2. 02 // bindRoslyn

    Parsing, binding and every diagnostic, exactly the official compiler's.

  3. 03 // lowerCFG to LLVM IR

    Generics, closures, async, exceptions and reflection metadata, one partial per feature.

  4. 04 // optimizeWhole-program LTO

    The program, the C# corelib and the csrt runtime optimized together.

  5. 05 // linkNative executable

    One hardened file: no JIT, no CoreCLR, no IL at run time.

the one rule

SAME OUTPUT AS REAL .NET.

A program compiled by csharpc behaves exactly like the same program under .NET: byte-identical stdout and the same exit code. Every test is recorded from dotnet run, or from NativeAOT where the two differ, and anything csharpc cannot do yet is an explicit diagnostic.

vision00-vision.md

Vision

What csharpc is for, its goals and its non-goals.

open
architecture02-architecture.md

Architecture

The pipeline, its phases and how the pieces fit together.

open
runtime04-runtime.md

Runtime

csrt: the GC, exception dispatch, threads and the C / C# boundary.

open
toolchain08-drop-in.md

Drop-in toolchain

.csproj input and dotnet build / run / publish integration.

open
oracle05-testing.md

Testing

Every test is recorded from real .NET and compared byte for byte.

open
roadmap06-roadmap.md

Roadmap

Milestones, the feature-support matrix and what comes next.

open

quick start

BUILD IT, COMPILE A PROGRAM.

Linux, macOS or Windows with the .NET 11 SDK, LLVM 18 and clang. Setup per platform is in the drop-in guide.

> dotnet build src/Csharpc -c Release
> dotnet src/Csharpc/bin/Release/net11.0/csharpc.dll hello.cs -o hello
> dotnet src/Csharpc/bin/Release/net11.0/csharpc.dll MyApp.csproj -o myapp
> csharpc app.cs --target wasm32-wasip1 -o app.wasm