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
- ResolveIlcPath uses
GetPackageDirectoryto find theruntime.<RID>.Microsoft.DotNet.ILCompilerpackage and setsIlcToolsPath. - WriteIlcRsp creates
$(IlcIntermediateOutputPath)$(AssemblyName).ilc.rsp, gathering patched assemblies from$(IntermediateOutputPath)/cosmos, references fromcosmos/ref, and ILCompiler options such as--runtimeknoband--featureflags. - CheckIlcCache computes one SHA-256 over the input assemblies, the reference assemblies and the response file, and compares it with
.ilc-hashfrom the last compilation. The response file is part of the key on purpose: a feature switch flipped in the kernel's.csprojchanges no assembly, only the--runtimeknobarguments in the response file, and a key over the assemblies alone would keep the object compiled for the old value. - CompileWithIlc executes
ilcwith the generated response file, producing$(AssemblyName).oin$(IlcIntermediateOutputPath), and writes the new hash. When the hash matched, the step is skipped and the log saysILC cache hit. - The native binary is ready for further packaging, such as bootloader integration.
Outputs
- Response file:
$(IntermediateOutputPath)/cosmos/native/$(AssemblyName).ilc.rsplisting inputs, references, and ILCompiler options. - Native object:
$(IntermediateOutputPath)/cosmos/native/$(AssemblyName).oproduced byCompileWithIlcfor 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.