Files
sausage/userland/preview1.nu
T

30 lines
1.3 KiB
Nu

#!/usr/bin/env nu
# Build pinned Go commands offline and copy the pinned QuickJS release.
def main [bin: path] {
let here = $env.FILE_PWD
let target = $env.CARGO_TARGET_DIR
mkdir $target $bin
for tool in [
{name: awk, source: goawk, package: '.'}
{name: esbuild, source: esbuild, package: './cmd/esbuild'}
] {
let output = ($target | path join $'($tool.name).wasm')
do {
cd ($here | path join $tool.source source)
with-env {GOOS: wasip1, GOARCH: wasm, GOPROXY: off} {
^go build -mod=vendor -trimpath '-ldflags=-s -w' -o $output $tool.package
}
}
if $env.LAST_EXIT_CODE != 0 { error make {msg: $'($tool.name) build failed'} }
^cp --remove-destination $output ($bin | path join $'($tool.name).wasm')
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'preview1 bundle copy failed'} }
}
let qjs = ($here | path join qjs qjs.wasm)
let hash = (open --raw $qjs | hash sha256)
if $hash != '2c218412cb8b17e46ee91bea7556ec38f5b9b6bd6312fddd3ceeed14aa71eaaa' {
error make {msg: 'QuickJS release hash mismatch'}
}
^cp --remove-destination $qjs ($bin | path join qjs.wasm)
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'QuickJS bundle copy failed'} }
}