Melange includes a built-inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/chainguard-dev/melange/llms.txt
Use this file to discover all available pages before exploring further.
cargo/build pipeline that compiles Rust packages using cargo auditable build. Unlike a plain cargo build, the auditable variant embeds a compressed JSON dependency tree directly into the binary’s own linker section. This means every produced binary carries a machine-readable record of every crate it was compiled from, enabling vulnerability scanners to identify affected packages without access to the original build environment.
How cargo/build works
Under the hood the pipeline:
- Changes into the directory specified by
modroot(default: the workspace root). - Runs
cargo auditable build --target-dir target <opts> [--jobs N]with any extrarustflagsset viaRUSTFLAGS. - Copies the built binary from the output directory (
target/releaseby default) to the APK staging directory at${{targets.contextdir}}/<prefix>/<install-dir>/.
cargo-auditable and rust to be available in the build environment. Declare them in your environment.contents.packages list.
Inputs
| Input | Default | Required | Description |
|---|---|---|---|
output | — | — | Output binary filename. When set, only this binary is installed. When unset, all files in output-dir are installed. |
opts | --release | — | Options passed directly to cargo auditable build |
modroot | . | — | Top-level directory of the Rust package (where Cargo.toml lives). The pipeline cds here before building. |
rustflags | "" | — | Flags passed to every compiler invocation via RUSTFLAGS. Whitespace-separated. |
prefix | usr | — | Installation prefix inside the APK |
install-dir | bin | — | Directory under prefix where binaries are installed |
output-dir | target/release | — | Directory where built binaries are found after compilation |
jobs | (CPU count) | — | Override the number of parallel compilation jobs |
The
output input is optional. When left empty, every file in output-dir is installed to install-dir. Specify output when you want to install only a single named binary.Example: building eza
The following example from examples/cargo-build.yaml builds eza, a modern replacement for ls, from a pinned git tag:
Auditable build metadata
Thecargo auditable build command embeds a JSON dependency tree in the .cargo_audit linker section of each produced ELF binary. The embedded data follows the cargo-auditable format and includes:
- The name and version of every crate linked into the binary
- Whether each crate came from
crates.io, a git source, or a local path
cargo audit and Grype can read this metadata directly from the binary, enabling software composition analysis (SCA) without a separate SBOM file.
Parallel compilation jobs
By default, Cargo uses all available CPU cores. Inside a build container the available core count may be lower than the host. Setjobs: explicitly to avoid resource contention on shared build infrastructure:
Passing extra compiler flags
Userustflags: to inject flags that apply to every compiler invocation Cargo performs. This is equivalent to setting the RUSTFLAGS environment variable:
Building from a subdirectory
For Cargo workspaces or multi-crate repositories where the target package lives in a subdirectory, setmodroot::
Selecting a build profile
Theopts: input is forwarded verbatim to cargo auditable build. To build with a custom profile instead of --release, override this input:
