Scarb handles project compilation, using the Cairo compiler internally, producing the compilation targets requested in the manifest file.
Compilation unit is used during Scarb project compilation, in order to organize compilation process and encapsulate all metadata required for the compilation. Compilation units are compiled separately, one by one. Each compilation unit produces a single compilation target.
Compilation unit structure
Compilation unit points to a single package deemed as main package that is being build, and a single compilation target from that package.
Additionally, a compilation unit encapsulates following compilation metadata:
- packages on which the compilation unit depends, called compilation unit components
- name of the profile used for the compilation (See more on
- compiler configuration parameters (See more on
- conditional compilation attributes that should be enabled (See more on
The compilation unit structure is deemed non-exhaustive, which means that Scarb retains the right to extend it in the future. All software depending on this structure should assume that there more fields will be added.
Compilation units for a project are exposed via Scarb metadata. You can find more information on the exposed compilation unit structure on Scarb metadata documentation page.
Generating compilation units
Compilation units are generated for each compilation target defined for each member package of a resolved Scarb project workspace.
While generating compilation units for a package, Scarb gathers all packages on which the main package depends, including the main package itself, from the resolved workspace. All library packages are passed as compilation unit components. The main package is always the first component of a corresponding compilation unit, while the second is reserved for the Cairo core library. Additionally, the name of the current profile and compiler configuration parameters are collected.
For each manifest defined target of the package, a set of conditional compilation arguments is collected. From the list of components gathered before, compilation targets are extracted. The compilation unit is constructed from the described attributes.
Following diagram describes the process: