一款名为 bflat 的 C# 编译器分叉项目在 Hacker News 上展示,该项目允许开发者在不依赖 .NET 运行时和垃圾回收器(GC)的情况下编译 C# 代码,生成小型的原生程序 1。该工具保留了 C# 的语法、类型检查、泛型、接口、记录元组及 Lambda 表达式等核心特性,但移除了 GC、异常捕获、反射和异步支持 1。
在内存管理方面,开发者需通过内存竞技场(Arenas)手动管理内存生命周期,错误则通过 Union 返回 1。编译后的程序可在 Linux (x64/arm64)、macOS (Apple Silicon)、Windows (x64)、WebAssembly (WASI) 以及 DOS (386) 等多种平台上运行 1。由于体积显著减小,Hello World 程序在 Windows x64 上大小约为 10.7 KB (10752 bytes),在 Linux 上约为 39.8 KB (39848 bytes) 1。此外,该编译器遵循 C# 15 的新内存安全规则进行编译 1。
A fork of the bflat C# compiler has been introduced that allows developers to compile C# code into small native programs without relying on the .NET runtime or a garbage collector (GC) 1. This tool retains core language features such as syntax, type checking, generics, interfaces, record tuples, and lambda expressions while stripping away heavy runtime components 1. Specifically, it removes support for GC, exception handling, reflection, and asynchronous operations, requiring developers to manage memory lifecycles manually through arenas and handle errors via unions 1. The compilation process adheres to the new memory safety rules defined in C# 15 1.
The resulting binaries are significantly smaller than traditional .NET applications, with a Hello World program weighing approximately 10.7 KB (10,752 bytes) on Windows x64 and about 39.8 KB (39,848 bytes) on Linux 1. These compiled programs can run across a diverse range of platforms, including Linux (x64/arm64), macOS (Apple Silicon), Windows (x64), WebAssembly (WASI), and even DOS (386) 1.
评论
还没有评论,欢迎留下第一条。