ops/build.sh 1.9 KiB 53 lines Raw
1 #!/bin/sh2 # Build the engine and every standalone bundle into one target directory.3 #4 # The root workspace holds `crates/`; each bundle is its own workspace (D19).5 # This script is the one place that builds both, so the deploy file can name a6 # single `bin_dir` and the image can copy one tree. It is a convenience, not a7 # workspace: no bundle is a root member, and a bundle changes its own lock file.8 set -eu9 10 root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)11 profile=${1:-release}12 case "$profile" in13     debug) release="" ;;14     release) release="--release" ;;15     *)16         echo "usage: ops/build.sh [debug|release]" >&217         exit 218         ;;19 esac20 21 target=${CARGO_TARGET_DIR:-$root/target}22 case "$target" in23     /*) ;;24     *) target=$root/$target ;;25 esac26 CARGO_TARGET_DIR=$target27 export CARGO_TARGET_DIR28 29 cd "$root"30 cargo build $release --workspace31 32 # A bundle id is a path, but Cargo names are XID identifiers. A model id such as33 # `example-1.0` keeps its dotted bundle name and uses `_` in its package and binary34 # target. The deploy rule still resolves `inf3r-<id>` with `/` replaced by `-`,35 # so stage the compiled binary under that one name after the bundle build. A36 # bundle whose package and id already agree is untouched.37 cargo_name() {38     printf '%s' "$1" | LC_ALL=C tr -c 'A-Za-z0-9_-' '_' | tr -d '\n'39 }40 for manifest in plugins/*/*/Cargo.toml; do41     cargo build $release --manifest-path "$manifest"42 43     dir=${manifest%/Cargo.toml}44     bundle=${dir#plugins/}45     expected=$target/$profile/inf3r-$(printf '%s' "$bundle" | tr '/' '-')46     model=${bundle%%/*}47     target_name=${bundle#*/}48     built=$target/$profile/inf3r-$(cargo_name "$model")-$(cargo_name "$target_name")49     if [ -x "$built" ] && [ "$built" != "$expected" ]; then50         cp "$built" "$expected"51     fi52 done53 printf 'build: %s\n' "${target#"$root"/}/$( [ "$profile" = release ] && printf release || printf debug )"