Files
sausage/userland/bundle.nu
T
surma d44f1d9677 Build separate native and WASI pipelines with shared multicall names
Checkpoint before integration and package validation.

Assisted-by: SurmAgent:unknown [read] [edit] [bash]
2026-11-12 09:36:27 +00:00

68 lines
4.0 KiB
Nu

#!/usr/bin/env nu
# Build the shared tool list incrementally and copy plain sources for world initialization.
def main [destination?: path] {
let here = ($env.FILE_PWD | path expand)
let destination = ($destination | default ($here | path join .. target userland bundle) | path expand)
let bin = ($destination | path join bin)
let object = ($here | path join cwd-init init.o)
let sources = [($here | path join cwd-init init.rs) ($here | path join cwd-init exit.wit) ($here | path join cwd-init build.nu)]
if not ($object | path exists) or ($sources | any {|source| (ls $source | get modified.0) > (ls $object | get modified.0) }) {
^nu ($here | path join cwd-init build.nu)
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'cwd-init build failed'} }
}
let manifest = ($here | path join .. Cargo.toml)
let metadata = (^cargo metadata --manifest-path $manifest --no-deps --format-version 1 | from json)
let tools = (open ($here | path join tools.json))
let packages = ($tools | where package != null | get package | uniq)
let arguments = ($packages | each {|p| ['-p' $p] } | flatten)
do { cd $here; ^cargo build --manifest-path $manifest --release --locked --target wasm32-wasip2 ...$arguments }
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'userland build failed'} }
if ($bin | path exists) { rm --recursive --force $bin }
mkdir $bin
^nu ($here | path join preview1.nu) $bin
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'preview1 build failed'} }
for tool in ($tools | where package != null) {
let source = ($metadata.target_directory | path join wasm32-wasip2 release $'($tool.binary).wasm')
^cp --remove-destination $source ($bin | path join $'($tool.binary).wasm')
if $env.LAST_EXIT_CODE != 0 { error make {msg: $'bundle copy failed: ($tool.binary)'} }
}
for tool in $tools {
for name in $tool.names {
if $name != $tool.binary {
^ln -s $'($tool.binary).wasm' ($bin | path join $'($name).wasm')
if $env.LAST_EXIT_CODE != 0 { error make {msg: $'tool alias failed: ($name).wasm'} }
}
^ln -s $'($tool.binary).wasm' ($bin | path join $name)
if $env.LAST_EXIT_CODE != 0 { error make {msg: $'tool alias failed: ($name)'} }
}
}
let units = ($destination | path join etc systemd system)
mkdir ($units | path join multi-user.target.wants)
let www = ($destination | path join srv www)
mkdir $www
^cp --remove-destination ($here | path join web index.html) ($www | path join index.html)
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'web page copy failed'} }
for file in [credentials.js credentials-view.js] {
^cp --remove-destination ($here | path join web $file) ($www | path join $file)
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'credential UI copy failed'} }
}
^cp --remove-destination ($here | path join web web.service) ($units | path join web.service)
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'web unit copy failed'} }
'' | save --force ($units | path join multi-user.target.wants web.service)
let repo = ($here | path join .. | path expand)
let snapshot = ($destination | path join src sausage)
if ($snapshot | path exists) { rm --recursive --force $snapshot }
mkdir $snapshot
let archive = ($destination | path join source.tar)
^tar --exclude-vcs --exclude-vcs-ignores -cf $archive -C $repo host vfs userland config skills extensions Cargo.toml Cargo.lock flake.nix flake.lock README.md AGENTS.md .gitignore
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'source archive failed'} }
^tar -xf $archive -C $snapshot
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'source extraction failed'} }
rm $archive
let settings = ($destination | path join etc sausage)
mkdir $settings
^cp --remove-destination ($snapshot | path join config config.yaml) ($settings | path join config.yaml)
if $env.LAST_EXIT_CODE != 0 { error make {msg: 'default config copy failed'} }
print $destination
}