#!/usr/bin/env nu
# builds the C api and runs the go tests that embed hydrant through it.
def main [] {
print "building hydrant-ffi..."
let out = (^cargo build -p hydrant-ffi --message-format json | complete)
if $out.exit_code != 0 {
print $out.stderr
print "=== TEST FAILED ==="
exit 1
}
let lib = (
$out.stdout
| lines
| each {|line| try { $line | from json } catch { null } }
| where {|m| $m != null and $m.reason? == "compiler-artifact" and $m.target?.name? == "hydrant_ffi" }
| get filenames
| flatten
| where {|f| $f | str ends-with ".a" }
| first
)
print $"linking against ($lib)"
let result = (with-env { CGO_ENABLED: "1", CGO_LDFLAGS: $"-L($lib | path dirname)" } {
cd ffi/go
^go test -count=1 -v ./... | complete
})
print $result.stdout
print $result.stderr
if $result.exit_code == 0 {
print "=== TEST PASSED ==="
} else {
print "=== TEST FAILED ==="
exit 1
}
}