Skip to main content

Rust Builds

Configure how anodizer compiles your Rust binaries

The build stage compiles your Rust crate for each configured target triple.

Minimal config

crates:
  - name: myapp
    path: "."
    builds:
      - binary: myapp

This builds a single binary for the default targets.

Build config fields

FieldTypeDefaultDescription
binarystringName of the binary to build (must match a [[bin]] in Cargo.toml)
targetslistinherited from defaults.targetsTarget triples to compile for
featureslistnoneCargo features to enable
no_default_featuresboolfalseDisable default features
flagslistnoneAdditional flags passed to cargo build, one token per entry (e.g., ["--locked"])
envmapnonePer-target environment variables
copy_fromstringnoneCopies the built binary from another build's binary name in the same crate instead of compiling it
reproducibleboolfalseEnable reproducible build settings
amd64_variantenumdetected from the build envDeclared x86-64 micro-architecture level — exactly one of "v1", "v2", "v3", "v4" (any other value is rejected when the config is parsed, on the crates, workspaces, and defaults.builds axes alike); overrides detection for artifact metadata and derived asset names

Multiple binaries

If your crate produces multiple binaries:

crates:
  - name: myapp
    path: "."
    builds:
      - binary: myapp
      - binary: myapp-cli
        features: ["cli-extras"]

Custom targets

defaults:
  targets:
    - x86_64-unknown-linux-gnu
    - aarch64-unknown-linux-gnu
    - x86_64-apple-darwin
    - aarch64-apple-darwin
    - x86_64-pc-windows-msvc

crates:
  - name: myapp
    builds:
      - binary: myapp
        targets:            # override defaults for this binary
          - x86_64-unknown-linux-gnu
          - aarch64-apple-darwin

Build features

crates:
  - name: myapp
    builds:
      - binary: myapp
        features: ["tls", "compression"]
        no_default_features: true

x86-64 micro-architecture levels

A build tuned for a specific x86-64 level names its assets with that level (myapp_1.0.0_linux_amd64v3.tar.gz for a v3 build; the v1 baseline adds no suffix). anodizer detects the level from the resolved per-target env — RUSTFLAGS or CARGO_TARGET_<TRIPLE>_RUSTFLAGS carrying -Ctarget-cpu=x86-64-v<N> (long --codegen target-cpu= spelling included) — both at build time (artifact metadata) and at config time (the derived asset names behind cargo-binstall pkg_url and the curl | sh installer):

crates:
  - name: myapp
    builds:
      - binary: myapp
        targets: [x86_64-unknown-linux-gnu]
        env:
          x86_64-unknown-linux-gnu:
            RUSTFLAGS: "-Ctarget-cpu=x86-64-v3"   # assets named …_amd64v3.…

When the tuning value is only resolvable at build time (so config-time detection cannot see it), declare the level explicitly — the declaration overrides detection for both the artifact metadata and every derived-name consumer:

crates:
  - name: myapp
    builds:
      - binary: myapp
        targets: [x86_64-unknown-linux-gnu]
        env:
          x86_64-unknown-linux-gnu:
            RUSTFLAGS: "{{ .Env.CI_TUNE_FLAGS }}"   # not renderable at config time
        amd64_variant: "v3"                          # declares what the flags produce

amd64_variant also stamps builder: prebuilt imports (which otherwise carry the v1 baseline — nothing can be detected for an imported binary). It is ignored for non-x86_64 targets.

Full example

defaults:
  targets:
    - x86_64-unknown-linux-gnu
    - aarch64-unknown-linux-gnu
    - x86_64-apple-darwin
    - aarch64-apple-darwin
    - x86_64-pc-windows-msvc
  cross: auto

crates:
  - name: myapp
    path: "."
    builds:
      - binary: myapp
        features: ["production"]
        env:
          x86_64-unknown-linux-gnu:
            CC: "gcc"