by MStrehovsky on 6/25/21, 9:47 AM with 1 comments
by MStrehovsky on 6/25/21, 9:47 AM
.NET made huge progress since .NET Core (Linux support, single executable support, etc.) and I think it's getting where I would like to see it, but I decided to "help it" a little with a different take on the tooling. It's a prototype.
I took the experimental .NET AOT compiler (from Microsoft's NativeAOT project), mixed it with Roslyn (the official C# compiler) and built a standalone compiler/tool. I took out everything that people usually associate with C# (MSBuild, NuGet, the `dotnet` CLI) and left just the bare minimum: language and libraries.
$ echo 'System.Console.WriteLine("Hello world");' >hello.cs
$ bflat build hello.cs
$ ./hello
Hello world
The compiler can also crosscompile - just pass `--os` and `--arch` to specify the architecture.It produces selfcontained native executables starting at ~730 kB for a Hello World referencing System.Console (uncompressed).
The compiler is self-hosted, so hopefully that's a good enough proof that it can already be used to build things.
The compiler comes in a ZIP file that you just extract and put on your PATH. It doesn't depend on anything else (no SDKs, no sysroot, no other tools).
You can target Linux already but there's no Linux version of the compiler itself because of some integration problems I still need to sort our (see Issues in the repo).
Disclaimer: I work at Microsoft, but this project is my freetime activity I whipped out without consulting anyone at work.