Skip to content

ForNeVeR/Cesium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cesium Status Enfer

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).

Implementation Status

TL;DR: is it ready for use?

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!

Sneak Peek

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).

Installation

Cesium consists of different components, which could be installed separately.

Project Templates

Install the templates:

$ dotnet new install Cesium.Templates

Then use:

$ dotnet new cesiumapp
$ dotnet new cesiumlib

The cesiumapp template will create a new application (executable), cesiumlib will create a library (a non-executable assembly).

Both templates integrate with MSBuild and are buildable using dotnet build. This is possible thanks to the Cesium SDK. Speaking of which…

Cesium SDK

To start working on a new project using Cesium.SDK, write a .ceproj file:

<Project Sdk="Cesium.Sdk/[version]">
    <PropertyGroup>
        <TargetFramework>[tfm]</TargetFramework>
        <OutputType>Exe</OutputType>
    </PropertyGroup>
</Project>

Replace [version] with the Cesium SDK version you want to use, and [tfm] with the target framework of your program (e.g. net6.0).

And add a program.c file (or any other .c and .h files) to the same folder.

This is essentially the same as what's contained in the corresponding project template.

Then, build your project via

$ dotnet build

And run it via

$ dotnet run

Compiler

If you want to install the compiler separately from the SDK, you have two options:

  1. Install the compiler as a .NET global tool:

    $ dotnet tool install --global Cesium.Compiler
    $ Cesium.Compiler --help

    (See the arguments and how to run the compiler below.)

  2. Install a self-contained version of Cesium for your platform: download the corresponding Cesium.Compiler.Bundle.<platform>.zip from the releases page. Unpack and then use the Cesium.Compiler(.exe) executable file.

    These platform-specific bundles provide self-contained executables for all the supported platforms, so they don't have a dependency on .NET runtime installed in the target environment.

Packages

Package Link
Cesium.Compiler.Bundle Cesium.Compiler.Bundle
Cesium.Compiler Cesium.Compiler
Cesium.Runtime Cesium.Runtime
Cesium.Sdk Cesium.Sdk
Cesium.Templates Cesium.Templates

Compiler Usage

$ Cesium.Compiler <list of the input files> --out <path to the output assembly> [optional parameters go here]

For run from sources, use dotnet run --project Cesium.Compiler in the repository root directory, followed by -- and the same arguments.

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

As inputs, Cesium accepts its own internal .obj file format produced by the -c option (see below), or standard C source files (normally kept with .c file extension, but anything else than .obj will be treated as C anyway).

Optional Parameters

  • --framework <framework>: specifies the target framework, defaults to Net
    • NetFramework for .NET Framework
    • NetStandard for .NET Standard
    • Net for .NET 5+
  • --arch <architecture-set>: specifies the target architecture set, defaults to Dynamic. 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 extension
    • Dll: gets detected from a .dll extension
    • Console: gets detected from an .exe extension
    • Windows: doesn't get detected, so it's only possible to select manually
    • NetModule: is a rudiment from Cecil, not supported
  • -c: will produce a JSON-based object file imitation in the output file. This mode is supposed to be used when using Cesium compiler as a C compiler for an existing toolset.

Implementation Dashboard

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:

Documentation

License

The project's sources, except the project templates, are distributed under the terms of the MIT license.

The project templates (from the directory Cesium.Templates) are distributed under the terms of the CC-0 license.

The license indication in the project's sources is compliant with the REUSE specification v3.3.

About

C compiler for the CLI platform

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors 30

Languages