C#: 945 kB Go: 2174 kB
Both are EXEs you just copy to the machine, no separate runtime needed, talks directly to the OS.
204 karma · joined January 3, 2020
C#: 945 kB Go: 2174 kB
Both are EXEs you just copy to the machine, no separate runtime needed, talks directly to the OS.
[1] https://learn.microsoft.com/dotnet/core/deploying/native-aot... [2] https://github.com/MichalStrehovsky/sizegame?tab=readme-ov-f... [3] https://learn.microsoft.com/dotnet/core/deploying/native-aot...
The tooling already generates warnings for any spot in the program that uses reflection _in a way that cannot be statically analyzed_. Fixing code to make it work with trimming is equivalent to fixing warnings. Here are a couple case studies: https://devblogs.microsoft.com/dotnet/creating-aot-compatibl...
Don't get me wrong, I like MSBuild and even bflat is built with MSBuild (wrote a custom target to invoke bflat from MSBuild), but sometimes I really just want to write a Makefile and be done with it instead of fiddling with MSBuild targets.
bflat integrates nicely with Make or other build systems - pass `-c` to generate object files (link it later with the commands bflat would use - use `-x` to see the commands), or use `bflat build-il` to create .NET assemblies and pass those as a reference (`-r`) to `bflat build` later.
It's a bunch of work to even get a hobbled version of crosscompilation to macOS running.
The way exceptions are done in .NET is by keeping track of extra metadata to be able to unwind methods (remove them from the execution stack) and execute handlers. That way the overhead of exception handling is close to zero if no exception is ever thrown. This requires quite a bit of infrastructure.
Propagating exceptions as error codes would come with execution time costs even if no exception is thrown and would have to be written from scratch (since .NET doesn't do it this way).
Either approach requires more investment than I'd want to put into it right now.
Apple's platforms are difficult to crosscompile for - most instructions I've seen that need to reach dependencies beyond what libc offers require one to copy files from an Xcode installation and pray one didn't break EULAs. I don't even know where to start if I want to build from Linux or Windows to target macOS without a mac.
Then there's a philosophical issue that I have where Apple essentially would like everyone to pay up if they want to distribute software that targets their platforms (required code signing, etc.), and breaking backwards compat all the time (essentially treating developers like a resource to be exploited). This practice needs to go away. I know bflat not being available for macOS won't change that, but we need to start somewhere...
bflat follows the platform convention that respects this and writes current date/time in the file header by default.
It is also a platform convention to offer options to set these to something stable (e.g. `/Brepro` on lld-link, or `--deterministic` for bflat) if one wants stable output.
bflat triggers a lot of engagement on Twitter and elsewhere because everyone wants to correct it. Couldn't have chosen a better name.
I think at this point https://flattened.net/ is a better introduction to bflat than the repo. The repo also links to it, but wanted to highlight it.
Here's a 11 kB bootable x86-64 version of the game written in C# https://github.com/kant2002/SeeSharpSnake/tree/kant/uefi#run....
There's an accompanying article with a video at the bottom https://codevision.medium.com/running-c-snake-inside-uefi-df....
Yup. There's really not much extra code in bflat compared to what's in the dotnet/runtimelab repo (in the NativeAOT branch). This just packages things differently so that one doesn't need the .NET SDK (plus Windows SDK if targeting Windows). The 100 MB bflat ZIP is all that's needed to target Windows or Linux.
.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.
(It doesn't need a .NET runtime; it's fully self-contained and runs on Windows as a native app.)
I would say the concentration of Czech/Slovak people around .NET at MS is a result of accidents and networking. I got into the team thanks to a friend of a friend who heard I was interested. But yeah, it's a surprising number given the size of the population of Slovakia and Czech republic.
There's a newly opened .NET development center in Prague so the number is likely going to grow (they do hire from all over the world though): https://karelz.github.io/hiring_prague_net/.
I had the weird things lying around from when I did an EFI boot application in C# last year: https://github.com/MichalStrehovsky/zerosharp/tree/master/ef...
I won't lie - being one of the architects of the CoreRT ahead of time compiler helped too :)