#!/usr/bin/env nu # Build every workspace CLI and assemble the read-only /bin bundle. def main [destination?: path] { let here = $env.FILE_PWD let destination = ($destination | default ($here | path join .. target userland bin) | path expand) 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 metadata = (do { cd $here; ^cargo metadata --no-deps --format-version 1 } | from json) do { cd $here; ^cargo build --workspace --release --locked } if $env.LAST_EXIT_CODE != 0 { error make {msg: 'userland build failed'} } ^nu ($here | path join brush build.nu) if $env.LAST_EXIT_CODE != 0 { error make {msg: 'brush build failed'} } mkdir $destination for package in ($metadata.packages | where {|p| $p.id in $metadata.workspace_members }) { let tools = ($package.manifest_path | path dirname | path join tools.txt) for binary in ($package.targets | where {|t| 'bin' in $t.kind }) { let source = ($metadata.target_directory | path join wasm32-wasip2 release $'($binary.name).wasm') let names = if ($tools | path exists) { open --raw $tools | lines | where {|s| ($s | str trim) != '' } } else { [$binary.name] } for name in $names { ^ln -f $source ($destination | path join $name) if $env.LAST_EXIT_CODE != 0 { error make {msg: $'bundle link failed: ($name)'} } } } } let brush_metadata = (^cargo metadata --manifest-path ($here | path join brush source Cargo.toml) --no-deps --format-version 1 | from json) let brush = ($brush_metadata.target_directory | path join wasm32-wasip2 release brush.wasm) for name in [sh bash] { ^ln -f $brush ($destination | path join $name) if $env.LAST_EXIT_CODE != 0 { error make {msg: 'brush link failed'} } } print $destination }