Files
sausage/userland/brush/build.nu
T

45 lines
2.5 KiB
Nu

#!/usr/bin/env nu
# Build the pinned brush source with only its WASI launcher seam replaced.
def copy-if-changed [source: path, destination: path] {
if not ($destination | path exists) or (open --raw $source) != (open --raw $destination) {
cp $source $destination
}
}
def main [] {
let here = $env.FILE_PWD
let source = ($here | path join source)
let revision = '943553433ae04f5b3bd55d2cf207e39eb9ef2af7'
if not ($source | path exists) {
^git clone --no-checkout https://github.com/reubeno/brush $source
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'brush clone failed'} }
^git -C $source checkout $revision
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'brush checkout failed'} }
}
if (^git -C $source rev-parse HEAD | str trim) != $revision { error make {msg: 'unexpected brush revision'} }
let core = ($source | path join brush-core)
copy-if-changed ($here | path join process.rs) ($core | path join src sys wasm process.rs)
copy-if-changed ($here | path join lookup.rs) ($core | path join src sys wasm sausage-lookup.rs)
let fs = ($core | path join src sys wasm fs.rs)
let fs_text = (open --raw $fs)
if not ($fs_text | str contains 'include!("sausage-lookup.rs")') {
$fs_text + "\ninclude!(\"sausage-lookup.rs\");\n" | save --force $fs
}
mkdir ($core | path join sausage-process)
let wit = ($here | path join .. .. host wit | path expand)
copy-if-changed ($wit | path join process.wit) ($core | path join sausage-process process.wit)
mkdir ($core | path join sausage-process deps)
copy-if-changed ($wit | path join deps io.wit) ($core | path join sausage-process deps io.wit)
let manifest = ($core | path join Cargo.toml)
let text = (open --raw $manifest)
let marker = "[target.'cfg(target_family = \"wasm\")'.dependencies]"
if not ($text | str contains 'wit-bindgen =') {
$text | str replace $marker ($marker + "\nwit-bindgen = \"0.46\"") | save -f $manifest
}
copy-if-changed ($here | path join Cargo.lock) ($source | path join Cargo.lock)
$env.SAUSAGE_CWD_INIT = ($here | path join .. cwd-init init.o | path expand)
$env.CARGO_TARGET_WASM32_WASIP2_LINKER = ($here | path join .. cwd-init link.nu | path expand)
$env.CARGO_TARGET_WASM32_WASIP2_RUSTFLAGS = '-C link-arg=sausage-cwd-init'
^cargo build --manifest-path ($source | path join Cargo.toml) -p brush-shell --release --features minimal --no-default-features --target wasm32-wasip2 --locked
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'brush build failed'} }
}