35 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env nu
# build.nu — run cargo build --release.
# Reads JSON inputs from stdin (linted-code, formatted-code).
# Emits JSON result to stdout.
def main []: nothing -> nothing {
let inputs = ($in | from json)
# Verify upstream capabilities are present
let linted = ($inputs | get "linted-code")
let formatted = ($inputs | get "formatted-code")
if (not ($linted.ok)) {
error make { msg: "linted-code.ok is false — refusing to build" }
}
if (not ($formatted.ok)) {
error make { msg: "formatted-code.ok is false — refusing to build" }
}
let result = (do { ^cargo build --release } | complete)
if ($result.exit_code != 0) {
error make { msg: $"cargo build failed:\n($result.stderr)" }
}
# Locate the produced binary (assumes single binary workspace)
let binary = (
^find target/release -maxdepth 1 -type f -perm /111 -not -name "*.d" -not -name "*.rlib"
| lines
| first
)
let crate_name = ($binary | path basename)
{ "built-artifact": { ok: true, path: $binary, crate_name: $crate_name } } | to json | print
}