#!/usr/bin/env sh # Builds the Windows daemon and puts it where the packager expects it. # # Two things make this its own script rather than a line in package.json. # # The packager reads nobilis/target/release/nobilis.exe, but a cross-build # writes to nobilis/target/x86_64-pc-windows-gnu/release/. Nothing connects # those, so `pack:win` would happily bundle whatever .exe happened to be at the # first path - which, on a machine that has been cross-building for days, is # something old. That is the same shape of bug as an AppImage shipping a stale # daemon, and it is worse here: it only shows up as "unknown method" on # somebody else's computer. # # And it has to be a cargo that works, which is not the same as the one named # `cargo` - see find-cargo.sh. set -eu TARGET=x86_64-pc-windows-gnu SRC_DIR="$(cd "$(dirname "$0")/.." && pwd)" MANIFEST="$SRC_DIR/nobilis/Cargo.toml" . "$SRC_DIR/scripts/find-cargo.sh" echo "building the Windows daemon with $CARGO" # Whether this is a release build, decided by moho's checkout - the # submodule's own cannot tell (in CI it is a bare commit, on no branch). The # daemon then reports its version, or "development". NOBILIS_CHANNEL="$(node "$SRC_DIR/scripts/version-label.mjs" --channel)" export NOBILIS_CHANNEL # From inside nobilis/, for its .cargo/config.toml - see build-daemon.sh. cd "$SRC_DIR/nobilis" # --locked: see build-daemon.sh. "$CARGO" build --release --locked --target "$TARGET" --manifest-path "$MANIFEST" BUILT="$SRC_DIR/nobilis/target/$TARGET/release/nobilis.exe" # The Windows build always bundles libopus; see build-daemon.sh for why a kept # target directory can leave it calling itself "unknown". if [ -f "$BUILT" ] && grep -aq 'libopus unknown' "$BUILT"; then echo "the bundled libopus does not know its version - building it again" "$CARGO" clean --release --target "$TARGET" -p libopus_sys --manifest-path "$MANIFEST" "$CARGO" build --release --locked --target "$TARGET" --manifest-path "$MANIFEST" fi WANTED="$SRC_DIR/nobilis/target/release/nobilis.exe" # Not merely "did cargo exit 0": a build that fails after having produced an # executable once leaves the old one in place, and copying that forward is how # a stale daemon gets shipped. [ -f "$BUILT" ] || { echo "no $BUILT - the build did not produce one" >&2; exit 1; } mkdir -p "$(dirname "$WANTED")" cp -f "$BUILT" "$WANTED" echo "daemon -> $WANTED"