Cesium is a fully managed C compiler for CLI platform (.NET).
What? Cesium compiles standard C source code to a .NET assembly. No unmanaged/mixed mode (a-lá C++/CLI) code is generated; everything is fully managed (but may be unsafe).
Why? C programs are very useful in the modern world and solve practical tasks. At the same time, deploying C code alongside .NET code may be tricky (especially if your application supports multiple platforms). Cesium is designed to resolve the problems of C code deployment, and lift it to the managed state (so it is cross-platform in the same way as the underlying CIL code it is compiled to).
Unfortunately, not yet. You won't be able to use Cesium for anything useful today. Probably, you'll be able to start after the next milestone is implemented. Stay tuned!
Currently, Cesium is able to compile a "Hello, world" C23 example to a .NET assembly:
#include <stdio.h>
int main(int argc, char *argv[])
{
puts("Hello, world!");
return 42;
}
The next milestone is #61: sha1collisiondetection, which is 80% complete (note that the progress estimation is preliminary and may be changed in either direction at any moment).
$ dotnet run --project Cesium.Compiler -- <path to the input .c file> --out <path to the output assembly>
For example, this will generate an assembly executable by .NET 6, .NET Framework, or Mono:
$ dotnet run --project Cesium.Compiler -- Cesium.Samples/minimal.c --out out.exe
$ dotnet ./out.exe # run with .NET 6
$ ./out.exe # only on Windows, run with .NET Framework
$ mono ./out.exe # run with Mono
--framework <framework>
: specifies the target framework, defaults toNet
NetFramework
for .NET FrameworkNetStandard
for .NET StandardNet
for .NET 5+
--arch <architecture-set>
: specifies the target architecture set, defaults toDynamic
. Possible values are:Dynamic
(machine-independent, calculates pointer size and structure layout in runtime),Bit32
(for 32-bit architectures),Bit64
(for 64-bit architectures),Wide
(machine-independent, uses 64-bit pointers even on 32-bit architectures).
--modulekind <moduleKind>
: specifies the output module kind; by default, it is autodetected from the output file extensionDll
: gets detected from a.dll
extensionConsole
: gets detected from an.exe
extensionWindows
: doesn't get detected, so it's only possible to select manuallyNetModule
: is a rudiment from Cecil, not supported
- C23 standard compatibility: poor
- Preprocessor: about 30% ready
- Lexer: mostly works, but needs more tests and validation on its compliance
- Parser: supports about 25% of the language syntax
- Compiler
- CIL code generator: basics are ready, new features get added
- PDB support: none
- Standard library: a very few functions are supported
- .NET SDK: none (but planned!)
Have a question? Welcome to the discussions section!
Looking to contribute? Check open issues with the "help-wanted" label. Cesium is a big project which lives thanks to its contributors.
Not sure where to contribute? Check open issues with the "good first issue" label.
Take a look at the contributor guide.
If you're interested in certain project areas, check the per-area issue labels:
area:cil-interop
: issues related to CLI interoparea:compiler
: issues related to the Cesium compiler, type checker, and code analyzerarea:parser
: issues related to C parsingarea:sdk
: issues related to the Cesium .NET SDKarea:standard-support
: issues related to C23 standard supportarea:stdlib
: issues related to the standard library implementation