Example: Cargo project

This example shows a simple project compiling a Cargo project using werk. It showcases depfiles generated by Cargo, and using the same output directory as Cargo for build artifacts.

Cargo.toml:

[package]
name = "test-project"
version = "0.1.0"
edition = "2021"

src/main.rs:

fn main() {
    println!("Hello from Rust!");
}

Werkfile:

default target = "build"
default out-dir = "target"

let cargo = which "cargo"

let profile = "debug"

let cargo-profile = profile | match {
    "debug" => "dev"
    "%" => "%"
}

# This rule matches the output path of Cargo.
build "{profile}/test-project{EXE_SUFFIX}" {
    # This file is implicitly generated by Cargo.
    depfile "{profile}/test-project.d"

    run "cargo build -p test-project --profile={cargo-profile}"
}

task build {
    build "{profile}/test-project{EXE_SUFFIX}"
}