Bake is a build tool for CakeML projects, designed to help manage dependencies and automate the process of building CakeML codebases. It is especially useful for projects that use EasyBakeCakeML or generate .cml files from other sources.
CakeML lacks a native module or import system, making it difficult to manage large projects with multiple files. Bake introduces a simple dependency annotation system using comments in .cml files, allowing you to specify dependencies and automate the process of merging and building your project.
Each .cml file that depends on other files should have its first line as:
(* deps: <dependencies>+ *)- List dependencies by their base name (no
.cmlextension). - Nested dependencies can be written as
Y/XorY.X(both are equivalent). - Dependencies starting with
@are resolved from the project root; others are resolved relative to the current file. - Dependencies starting with
$are resolved from the stubs directory (provided via--stubs <dir>or theCAKEML_STUBSenvironment variable). This is useful for substituting stub or platform-specific files, such as for testing or platform abstraction.
Examples:
- In
Y/Z.cml,XmeansY/X.cml(relative), while@XmeansX.cmlat the project root. $Test_Stubsin any file will resolve toTest_Stubs.cmlin the stubs directory.
Bake supports three main modes, controlled by the --mode argument:
--mode print: Resolves and prints the full dependency list for a given.cmlfile. Output can be redirected to a file with--out <file>.--mode merge: Resolves dependencies and merges all required.cmlfiles into a single monolithic file (specified by--out <file>).--mode build: Merges dependencies, compiles the result with the CakeML compiler (cake), and then compiles the output to a native executable usingcc.
bake <main.cml> [--mode print|merge|build] [--out <file>] [--stubs <dir>]<main.cml>: The entry point CakeML file.--mode: Selects the operation mode (print,merge, orbuild). Default isbuild.--out <file>: Output file for the merged CakeML code (required formergeandbuild).--stubs <dir>: Optional directory for stub file substitution.
- The tool assumes your C compiler is
cc, the basis file isbasis_ffi.c, and uses the flags-O2 -lm. - There is currently no cleaning functionality.
- The
--outargument specifies the output monolithic CakeML file; inbuildmode, the executable will be named after the output file (without the.cmlextension). - Stub file substitution is supported for files ending in
_Stubs.cmlor_Axioms.cmlvia the--stubsoption or theCAKEML_STUBSenvironment variable. - Logging can be enabled by setting the
DEBUGenvironment variable.
To print dependencies:
bake my_main.cml --mode printTo merge into a single file:
bake my_main.cml --mode merge --out merged.cmlTo build an executable:
bake my_main.cml --mode build --out merged.cmlSee LICENSE for details.