Developing with Cargo
Pure Cargo workflow for NativeLink contributors who'd rather not run Bazel.
Every NativeLink crate compiles cleanly with plain Cargo. Use this workflow if you want a smaller dev shell, faster incremental builds during iteration, or just don't have Bazel installed.
Prerequisites
- A recent stable Rust toolchain. No
rust-toolchain.tomlis checked in; the minimum isrust-versionin the rootCargo.toml, currently 1.97.1, on edition 2024. - On Linux:
moldis optional and has to be configured by hand; see faster incremental builds.
You do not need protoc. The generated Rust for every proto is
checked into nativelink-proto/genproto/, and nativelink-proto's
[lib] path points straight at it; there is no build script.
First build
git clone https://github.com/TraceMachina/nativelink
cd nativelink
cargo build --workspaceFirst build is a few minutes (dependency compilation); subsequent incremental builds are typically a few seconds.
Common commands
# Build everything.
cargo build --workspace
# Run all tests. `smol` keeps target/ near 1GB instead of ~12GB.
cargo test --all --profile=smol
# Run a specific crate's tests.
cargo test -p nativelink-store
# Run the server.
cargo run -p nativelink -- /path/to/config.json5
# Lint with the workspace lint set from the root Cargo.toml. The Cargo CI
# lane builds and tests with RUSTFLAGS=-Dwarnings; clippy itself runs in CI
# through the Bazel aspect, on the same lint set.
cargo clippy --all-targets -- -D warningsDon't format with stable `cargo fmt`
.rustfmt.toml uses group_imports and imports_granularity, both
nightly-only. Stable cargo fmt silently ignores them and produces
output CI rejects. Run bazel run --config=rustfmt @rules_rust//:rustfmt
instead.
Faster incremental builds
A few flags that help:
-
moldas linker (Linux):# ~/.cargo/config.toml [target.x86_64-unknown-linux-gnu] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=mold"] -
CARGO_TARGET_DIRset to a shared directory across checkouts to reuse incremental artifacts.
Caveats
- Three directories are excluded from the workspace and build on their
own:
nativelink-config/generate-stores-config,nativelink-test/fuzz, andtools/generate-bazel-rc. The LRE flake outputs are Nix, not Cargo. - Regenerating protos goes through Bazel
(
bazel run nativelink-proto:update_protos), not Cargo. - CI runs Bazel, and
bazel testattaches rustfmt and clippy aspects that a Cargo run does not. A greencargo testdoes not guarantee a green CI. Runbazel test //...before submitting.
For the Bazel-based workflow, see Develop with Bazel. For what the test suites contain, see the testing guide.