#!/usr/bin/env nu # Build independent commands and plain source files. World creation initializes their repository. def main [destination?: path] { let here = $env.FILE_PWD 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 packages = ($metadata.packages | where {|p| $p.id in $metadata.workspace_members and ($p.manifest_path | str starts-with $here) and not ($p.manifest_path | str starts-with ($here | path join brush source)) }) let arguments = ($packages | where {|p| $p.targets | any {|t| 'bin' in $t.kind } } | each {|p| ['-p' $p.name] } | 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'} } ^nu ($here | path join brush build.nu) if $env.LAST_EXIT_CODE != 0 { error make {msg: 'brush build failed'} } mkdir $bin ^nu ($here | path join preview1.nu) $bin if $env.LAST_EXIT_CODE != 0 { error make {msg: 'preview1 build failed'} } for package in $packages { 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 { ^cp --remove-destination $source ($bin | path join $'($name).wasm') if $env.LAST_EXIT_CODE != 0 { error make {msg: $'bundle copy failed: ($name)'} } } } } let brush = ($metadata.target_directory | path join wasm32-wasip2 release brush.wasm) for name in [sh bash] { ^cp --remove-destination $brush ($bin | path join $'($name).wasm') if $env.LAST_EXIT_CODE != 0 { error make {msg: 'brush copy failed'} } } let units = ($destination | path join etc systemd system) mkdir ($units | path join multi-user.target.wants) ^cp --remove-destination ($here | path join chat chat.service) ($units | path join chat.service) if $env.LAST_EXIT_CODE != 0 { error make {msg: 'chat unit copy failed'} } '' | save --force ($units | path join multi-user.target.wants chat.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) ^git -C $repo archive --output $archive HEAD 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 }