Skip to content

TheAjaykrishnanR/dflat

Repository files navigation

dflat, a native aot compiler for C#

A portable and relatively lightweight C# AOT compiler. Build native executables, libraries on windows and linux. Inspired by bflat


Usage

Download from releases

Description:
  dflat, a native aot compiler for c#
  Ajaykrishnan R, 2025

Usage:
  dflat [<SOURCE FILES>...] [options]

Arguments:
  <SOURCE FILES>  .cs files to compile

Options:
  /?, /h, /help                                                      Show help and usage information
  /version                                                           Show version information
  /out                                                               Output file name
  /main                                                              Specify the class containing Main()
  /r                                                                 Additional reference .dlls or folders containing them
  /il                                                                Compile to IL
  /verbosity                                                         Set verbosity
  /langversion                                                       Print supported lang versions
  /target <EXE|LIBRARY|WINEXE>                                       Specify the target
  /platform <anycpu|anycpu32bitpreferred|arm|arm64|Itamium|x64|x86>  Specify the platform
  /optimize                                                          optimize
  /csc                                                               extra csc flags [as a single string]
  /ilc                                                               extra ilc flags [as a single string]
  /lld                                                               extra lld flags [as a single string]

Building

Windows

Preferrable to run it as a github workflow

Requirements:

1. Git
2. python

Build:

git clone https://github.com/TheAjaykrishnanR/dflat
cd dflat
.\assemble.ps1

Linux

Preferrable to run it as a github workflow

Requirements:

GLIBC>=2.38
Git
Python
Powershell
binutils

Build:

git clone https://github.com/TheAjaykrishnanR/dflat
cd dflat
.\assemble-linux.sh

How it works

To compile a C# program to a native executable we need:

  1. CSC
  2. ILCompiler
  3. A linker
  4. runtime (managed + native)

csc.exe: To get the csc executable we build the csc project in the dotnet/roslyn repo. A slight modification is made to the csc.csproj file so that csc itself is aot compiled and we get a single native executable.However on linux we skip AOT due to some quirks and publish it just as a single file.

ilc.exe: Building the dotnet/runtime repo yields ilc.exe.

linker: On Windows we go with the native MSVC link.exe and on Linux we use the native ld.bfd linker part of gnu binutils.

About

C# Aot compiler inspired by bflat

Resources

Stars

Watchers

Forks

Packages

No packages published