Cosmos.Build.GCC compiles C sources into object files that are linked with the NativeAOT output.
Flow chart
flowchart TD
A[GetGCC] --> B[FindCSourceFilesForGCC]
B --> C[BuildGCC]
C --> D[.o/.obj files under cosmos/cobj]
Parameters
| Name | Description | Default |
|---|---|---|
GCCPath |
Full path or name of the gcc executable. Set by GetGCC per-OS, overridable in your project. |
Unix: gcc; Windows: x86_64-elf-gcc |
GCCProject |
One or more directories to scan (non-recursive) for *.c. Supports arch subfolder override. |
none |
GCCOutputPath |
Directory for compiled object files. | $(IntermediateOutputPath)/cosmos/cobj/ |
GCCCompilerFlags |
Additional compiler flags passed to GCC. | -O2 -fno-stack-protector -nostdinc -fno-builtin plus arch flags |
Notes:
- When
RuntimeIdentifieris set (e.g.,linux-x64),FindCSourceFilesForGCCprefers an architecture subfolder if present (e.g.,<dir>/x64/). - On Windows the default tool is a cross-compiler (
x86_64-elf-gcc); on Unix it isgcc. You can overrideGCCPath.
Tasks
| Task | Description | Depends On |
|---|---|---|
GetGCC |
Resolves GCCPath per OS (Unix: gcc, Windows: x86_64-elf-gcc). |
none |
FindCSourceFilesForGCC |
Cleans @(GCCProject) inputs and applies arch overrides. |
Build |
BuildGCC |
Invokes GCCBuildTask to compile each *.c in every @(GCCProject) directory. |
FindCSourceFilesForGCC; GetGCC |
CleanGCC |
Removes $(IntermediateOutputPath)/cosmos/cobj/. |
Clean |
Detailed workflow
GetGCCsetsGCCPathaccording to the host OS. You can overrideGCCPathin your project file if needed.FindCSourceFilesForGCC:- Removes any nonexistent paths from
@(GCCProject)(emits warnings). - If
RuntimeIdentifieris set and a matching arch subfolder exists (e.g.,x64), the folder is replaced with that subfolder. - Logs the final list of C project directories.
- Removes any nonexistent paths from
BuildGCC:- Ensures
GCCOutputPath($(IntermediateOutputPath)/cosmos/cobj/) exists and cleans stale objects. - For each
@(GCCProject)directory, callsGCCBuildTaskwhich compiles every*.cfile in that directory (non-recursive). - Each file is compiled individually to an object named
<name>-<sha1>.(obj|o)where the hash is derived from file contents; extension is.objon Windows,.oelsewhere.
- Ensures
CleanGCCremoves thecosmos/cobjdirectory duringClean.
Outputs
- Object files in
$(IntermediateOutputPath)/cosmos/cobj/named as<sourceName>-<sha1>.(obj|o).