default target = "build"

config profile = "debug"

# Pick cflags based on the build profile
let cflags = profile | match {
    "debug" => ["-O0"]
    "release" => ["-O3"]
    "asan-address" => ["-O1", "--sanitize=address"]
    "%" => ""
}

build "brainz-c3" {
    from glob "c3/*.c3"
    run "c3c compile {cflags*} <in*> -o <out>"
}

build "testrun" {
    from glob "c3*.c3"
    # Compiles and runs, ok for now because running tests is fast
    run "c3c compile-test --no-run <in*> -o <out>"
}

task build {
    build "brainz-c3"
}

task test {
    let test_exe = "testrun"
    build test_exe
    run "<test_exe>"
}

# `werk test -Dturnt-args=-v`
# --save
# --diff
let turnt-args = []
task turnt {
    build "brainz-c3"
    let test_inputs = glob "tests/*.brainz"
    run "turnt {turnt-args*} <test_inputs*>"
}
