NativeLink
Contribute

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.toml is checked in; the minimum is rust-version in the root Cargo.toml, currently 1.97.1, on edition 2024.
  • On Linux: mold is 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 --workspace

First 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 warnings

Faster incremental builds

A few flags that help:

  • mold as linker (Linux):

    # ~/.cargo/config.toml
    [target.x86_64-unknown-linux-gnu]
    linker = "clang"
    rustflags = ["-C", "link-arg=-fuse-ld=mold"]
  • CARGO_TARGET_DIR set 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, and tools/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 test attaches rustfmt and clippy aspects that a Cargo run does not. A green cargo test does not guarantee a green CI. Run bazel test //... before submitting.

For the Bazel-based workflow, see Develop with Bazel. For what the test suites contain, see the testing guide.

FAQ

On this page