SBOMs for Rust
Stable Cargo has no SBOM command yet. sbombox generate uses cargo-cyclonedx if installed, then cdxgen or syft. Commit Cargo.lock so every version is exact.
At a glance
| Package manager | Built-in SBOM command | What sbombox generate runs | Lockfile to commit |
|---|---|---|---|
| Cargo | Nightly only (-Z sbom) | cargo-cyclonedx, then cdxgen or syft | Cargo.lock |
Generate with SBOMBox
curl -fsSL https://sbombox.com/install.sh | sh
sbombox generate -o sbom.json
sbombox score sbom.jsonRun it from the directory that holds Cargo.toml and Cargo.lock. To use the native tool, install it first:
cargo install cargo-cyclonedxTo pin the choice, set SBOMBOX_GENERATOR to one or more generator names, comma-separated. SBOMBox tries them in that order and skips any that are not installed. An unknown name fails with the list of valid names.
SBOMBOX_GENERATOR=syft sbombox generate -o sbom.jsonValid names for Rust: cargo-cyclonedx (alias cargo), cdxgen, syft.
Use cargo-cyclonedx
cargo-cyclonedx writes one SBOM next to each Cargo.toml in the workspace. --override-filename sets a fixed file name.
cargo cyclonedx -f json --spec-version 1.5
# Upload the JSON file it wrote next to Cargo.toml
sbombox push <file> --version v1.4.0--describe binariesdescribes each binary target rather than the crate.--targetlimits the SBOM to one platform; by default it uses the host target.--target allincludes every target.--all-featuresor-Fselect features, which change the dependency set.
Embed dependency data in binaries
cargo-auditable records the dependency list inside the compiled binary. syft can read it, so you can produce an SBOM from a binary you already shipped.
cargo install cargo-auditable
cargo auditable build --release
syft ./target/release/my-app -o cyclonedx-json=sbom.jsonCargo's own SBOM support
Nightly Cargo can write SBOM precursor files with -Z sbom. With sbom = true under [unstable] and [build] in .cargo/config.toml, or CARGO_BUILD_SBOM=true, it writes <artifact>.cargo-sbom.json next to each binary. These are Cargo's own JSON format, not CycloneDX or SPDX, so they need conversion before upload. Stabilising this is an accepted Rust project goal for 2026.
Monorepos and workspaces
- Cargo workspaces share one
Cargo.lock. Runsbombox generatefrom the workspace root. - cargo-cyclonedx writes one SBOM per member. Upload each deployable crate to its own SBOMBox project with
sbombox push FILE --project ID.
Known gaps and how SBOMBox handles them
- Stable Cargo has no SBOM command. SBOMBox uses cargo-cyclonedx when installed, otherwise a universal tool.
- Features change the dependency set. Generate with the same features and target you release, and use
--describe binariesto describe what ships.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
No lockfile for cargo: transitive dependencies may be missing and versions may be guessed. | Cargo.lock not committed | Commit Cargo.lock |
| Dependencies missing for your release platform | SBOM built for the host target | Pass --target with your release triple |
.cargo-sbom.json not accepted by sbombox push | Cargo precursor format, not CycloneDX or SPDX | Use cargo-cyclonedx or syft for the uploaded SBOM |
In CI, run the same commands. See GitHub Actions, GitLab CI, Jenkins, Azure Pipelines, Bitbucket Pipelines or CircleCI, or use the GitHub Action.