#!/usr/bin/env bash # The hub's deploy of midas (hub.conf's `midas` target), on whichever node is # free: the binary for the hub's machine and this container (x86_64 Linux, # glibc 2.35, the vps's) and the one the Mac nodes install, into out/. # # On the vps (x86_64 Linux) the Mac's is cross-built, linked against the # framework stubs in node/macos/stubs; on a Mac node (macOS, arm64) it is # native and the Linux one is cross-built with zig instead. set -euo pipefail T=${CARGO_TARGET_DIR:-target} # zig and cargo-zigbuild: from PATH, or unpacked in ~/opt as deploy.sh finds them. for d in "$HOME"/opt/zig-*/ "$HOME/opt/cargo-zigbuild/bin"; do [ -d "$d" ] && PATH=$PATH:${d%/}; done # A node without them fetches them once: the Mac nodes' image has no zig, and a node # rebuilt from it starts without. if ! command -v zig >/dev/null; then z=zig-$(uname -m | sed s/arm64/aarch64/)-$(uname -s | tr A-Z a-z | sed s/darwin/macos/)-0.14.1 mkdir -p "$HOME/opt" && curl -fsSL "https://ziglang.org/download/0.14.1/$z.tar.xz" | tar xJ -C "$HOME/opt" PATH=$PATH:$HOME/opt/$z fi command -v cargo-zigbuild >/dev/null || cargo install cargo-zigbuild --locked --quiet # build.rs embeds the page from web/dist. (cd web && bun install --frozen-lockfile && bun run build) case "$(uname -s)" in Darwin) rustup target add --toolchain stable x86_64-unknown-linux-gnu >/dev/null cargo build --release --quiet --target aarch64-apple-darwin cargo zigbuild --release --quiet --target x86_64-unknown-linux-gnu.2.35 ;; *) rustup target add --toolchain stable aarch64-apple-darwin >/dev/null cargo zigbuild --release --quiet --target x86_64-unknown-linux-gnu.2.35 CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS="-C link-arg=-F$PWD/node/macos/stubs" \ cargo zigbuild --release --quiet --target aarch64-apple-darwin ;; esac mkdir -p out cp "$T/x86_64-unknown-linux-gnu/release/midas" out/midas cp "$T/aarch64-apple-darwin/release/midas" out/midas-macos-aarch64