Table of Contents

Overview

Cosmos.ilc.Build integrates the native AOT ILCompiler into the MSBuild pipeline. It consumes patched assemblies emitted by Cosmos.Build.Patcher and transforms them into native object files later linked with platform libraries for CosmosOS.


Flow chart

flowchart TD
    A[ResolveIlcPath] --> B[WriteIlcRsp]
    B --> C[CompileWithIlc]
    C --> D[Native binary]

Parameters

Name Description Default
IlcToolsPath Path to the ilc executable resolved from the Microsoft.DotNet.ILCompiler runtime pack. auto-resolved
IlcIntermediateOutputPath Directory where .ilc.rsp and .o files are written. $(IntermediateOutputPath)/cosmos/native/
IlcSystemModule System module used as ILCompiler entry point. System.Private.CoreLib
UnmanagedEntryPointsAssembly Assemblies whose methods are exported via --generateunmanagedentrypoints. Cosmos.Kernel.Runtime

Tasks

Task Description Depends On
ResolveIlcPath Downloads and locates ILCompiler, setting IlcToolsPath. Build
WriteIlcRsp Produces the ILCompiler response file listing inputs, references, and options. ResolveIlcPath
CheckIlcCache Hashes the inputs, the references and the response file and compares the hash with the one of the last compilation. WriteIlcRsp
CompileWithIlc Runs ilc using the response file to emit a native object file, unless CheckIlcCache found the object up to date. WriteIlcRsp, CheckIlcCache

Detailed workflow

  1. ResolveIlcPath uses GetPackageDirectory to find the runtime.<RID>.Microsoft.DotNet.ILCompiler package and sets IlcToolsPath.
  2. WriteIlcRsp creates $(IlcIntermediateOutputPath)$(AssemblyName).ilc.rsp, gathering patched assemblies from $(IntermediateOutputPath)/cosmos, references from cosmos/ref, and ILCompiler options such as --runtimeknob and --feature flags.
  3. CheckIlcCache computes one SHA-256 over the input assemblies, the reference assemblies and the response file, and compares it with .ilc-hash from the last compilation. The response file is part of the key on purpose: a feature switch flipped in the kernel's .csproj changes no assembly, only the --runtimeknob arguments in the response file, and a key over the assemblies alone would keep the object compiled for the old value.
  4. CompileWithIlc executes ilc with the generated response file, producing $(AssemblyName).o in $(IlcIntermediateOutputPath), and writes the new hash. When the hash matched, the step is skipped and the log says ILC cache hit.
  5. The native binary is ready for further packaging, such as bootloader integration.

Outputs

  • Response file: $(IntermediateOutputPath)/cosmos/native/$(AssemblyName).ilc.rsp listing inputs, references, and ILCompiler options.
  • Native object: $(IntermediateOutputPath)/cosmos/native/$(AssemblyName).o produced by CompileWithIlc for linking.
  • Cache key: $(IntermediateOutputPath)/cosmos/native/.ilc-hash, the hash of the inputs the object was compiled from.

Notes:

  • Reference assemblies resolved by ILC are located under $(IntermediateOutputPath)/cosmos/ref/ and come from the Patcher step.