compile command creates a self-contained executable that embeds the workerd runtime, your configuration, and all associated worker code and data.
Usage
Arguments
Path to the configuration file. Can be:
- A Cap’n Proto text file (
.capnp) - A binary Cap’n Proto file (with
--binaryflag) -to read from stdin (requires--binary)
Name of the Config constant to use from the config file. Required if the file defines multiple Config constants.For nested constants, use dot notation:
parentScope.constantNameOptions
Configuration parsing
Add a directory to the list of directories searched for non-relative imports (imports starting with
/).Can be specified multiple times.Indicates that the configuration file is an encoded binary Cap’n Proto message rather than text format.
Output options
Only write the encoded binary config to stdout. Do not attach it to an executable.The encoded config can be used as input to the
serve command with the --binary flag.How it works
Thecompile command creates a self-contained binary by:
- Copying the workerd executable to the output
- Appending the compiled configuration and all embedded resources
- Adding metadata to allow the runtime to locate the embedded config
Binary format
The compiled binary has the following structure:Examples
Basic compilation
With import paths
Config-only output
Named constant
Deployment
Compiled binaries are ideal for deployment because:- Self-contained: No external config files needed
- Portable: Single file to deploy
- Immutable: Config cannot be changed without rebuilding
- Simple: Just copy and execute
Overriding embedded config
Even with an embedded config, you can still override certain settings at runtime:Limitations
- The output file must be written to a regular file or a pipe, not to a terminal. The command will refuse to write binary data to a terminal.
- The compiled binary includes the full workerd runtime, so it will be at least as large as the workerd executable itself (typically 50-100 MB).
- On systems with executable permission bits, the output file will automatically be marked as executable if it’s a new regular file.
Exit codes
- 0: Successful compilation
- 1: Configuration error or compilation error
- Other: System-specific error codes