Cosmos.Build.Asm compiles handwritten assembly sources into object files that are linked with the NativeAOT output. Both x64 and ARM64 targets use the clang integrated assembler on GAS-syntax .s files.
Flow chart
flowchart TD
A[GetAsmTool] --> B[FindAsmSourceFiles]
B --> C[BuildAsm]
C --> D[.obj files under cosmos/asm]
Parameters
| Name | Description | Default |
|---|---|---|
AsmToolPath |
Full path to the clang executable. Auto-detected by GetAsmTool if not set. |
Resolved via ResolveCosmosToolTask (system PATH + Cosmos tools bundle) |
AsmSearchPath |
One or more directories to scan (non-recursive) for *.s. |
none |
AsmFiles |
Explicit list of *.s files to compile (added to scan results). |
none |
AsmOutputPath |
Directory for compiled object files. | $(IntermediateOutputPath)/cosmos/asm/ |
Notes:
- When
RuntimeIdentifieris set (e.g.,linux-x64),FindAsmSourceFileswill prefer an architecture subfolder if present (e.g.,<searchDir>/x64/). - The target triple is selected by
AsmBuildTaskfromTargetArchitecture:x86_64-elffor x64 andaarch64-none-elffor ARM64.
Tasks
| Task | Description | Depends On |
|---|---|---|
GetAsmTool |
Resolves AsmToolPath to the clang binary via ResolveCosmosToolTask. |
none |
FindAsmSourceFiles |
Cleans inputs, applies arch overrides, and discovers *.s under AsmSearchPath. |
Build |
BuildAsm |
Invokes AsmBuildTask for each file with --target=<triple> -c, writing to AsmOutputPath. |
FindAsmSourceFiles; GetAsmTool |
CleanAsm |
Removes $(IntermediateOutputPath)/cosmos/asm/. |
Clean |
Detailed Workflow
GetAsmToolresolvesAsmToolPathto aclangbinary (override / system / Cosmos tools bundle).FindAsmSourceFiles:- Removes any nonexistent entries from
AsmSearchPathandAsmFiles(emits warnings). - If
RuntimeIdentifieris set, replaces anyAsmSearchPaththat contains a matching arch subfolder with that subfolder (e.g.,x64). - Builds a non-recursive search pattern
%(AsmSearchPath.FullPath)/*.sand adds results toAsmFiles(deduplicated).
- Removes any nonexistent entries from
BuildAsmcalls theAsmBuildTaskfor each file:- Computes a SHA1 of the source and emits
<name>-<sha1>.objintoAsmOutputPath. - Executes
clang --target=<x86_64-elf|aarch64-none-elf> -c -o <output.obj> <input.s>.
- Computes a SHA1 of the source and emits
CleanAsmdeletes thecosmos/asmintermediate folder duringClean.
Outputs
- Object files in
$(IntermediateOutputPath)/cosmos/asm/named as<sourceName>-<sha1>.objwhere<sha1>is the content hash of the source. This guarantees deterministic, cache-friendly names across builds.