|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Build real, self-contained database:// worker artifacts for the host platform. |
| 3 | + |
| 4 | +set -euo pipefail |
| 5 | + |
| 6 | +project_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) |
| 7 | +output_dir=${VGI_DATABASE_WORKER_FIXTURE_DIR:-"${project_dir}/build/database-worker-fixtures"} |
| 8 | +python_dir=${VGI_DATABASE_PYTHON_DIR:-"${HOME}/Development/vgi-python"} |
| 9 | +rust_dir=${VGI_DATABASE_RUST_DIR:-"${HOME}/Development/vgi-rust"} |
| 10 | +open_meteo_dir=${VGI_DATABASE_OPEN_METEO_DIR:-"${HOME}/Development/vgi-open-meteo"} |
| 11 | + |
| 12 | +for command_name in uv bun cargo tar; do |
| 13 | + if ! command -v "${command_name}" >/dev/null 2>&1; then |
| 14 | + echo "database-worker fixtures require ${command_name} on PATH" >&2 |
| 15 | + exit 1 |
| 16 | + fi |
| 17 | +done |
| 18 | +for source_dir in "${python_dir}" "${rust_dir}" "${open_meteo_dir}"; do |
| 19 | + if [[ ! -d "${source_dir}" ]]; then |
| 20 | + echo "database-worker fixture source directory does not exist: ${source_dir}" >&2 |
| 21 | + exit 1 |
| 22 | + fi |
| 23 | +done |
| 24 | + |
| 25 | +mkdir -p "${output_dir}" |
| 26 | +scratch_dir=$(mktemp -d "${TMPDIR:-/tmp}/vgi-database-workers.XXXXXX") |
| 27 | +cleanup() { |
| 28 | + rm -rf "${scratch_dir}" |
| 29 | +} |
| 30 | +trap cleanup EXIT |
| 31 | + |
| 32 | +echo "Building frozen Python worker" |
| 33 | +uv run --project "${python_dir}" --locked --with pyinstaller==6.22.2 \ |
| 34 | + pyinstaller --clean --onefile --name vgi-python-worker \ |
| 35 | + --distpath "${output_dir}" \ |
| 36 | + --workpath "${scratch_dir}/pyinstaller-build" \ |
| 37 | + --specpath "${scratch_dir}/pyinstaller-spec" \ |
| 38 | + "${project_dir}/test/support/database_workers/python_worker.py" |
| 39 | + |
| 40 | +if [[ -n "${VGI_BUN_TARGET:-}" ]]; then |
| 41 | + bun_target=${VGI_BUN_TARGET} |
| 42 | +else |
| 43 | + host_os=$(uname -s) |
| 44 | + host_arch=$(uname -m) |
| 45 | + case "${host_os}/${host_arch}" in |
| 46 | + Darwin/arm64) bun_target=bun-darwin-arm64 ;; |
| 47 | + Darwin/x86_64) bun_target=bun-darwin-x64 ;; |
| 48 | + Linux/aarch64|Linux/arm64) bun_target=bun-linux-arm64 ;; |
| 49 | + Linux/x86_64) bun_target=bun-linux-x64-baseline ;; |
| 50 | + *) |
| 51 | + echo "cannot infer a Bun executable target for ${host_os}/${host_arch}" >&2 |
| 52 | + exit 1 |
| 53 | + ;; |
| 54 | + esac |
| 55 | +fi |
| 56 | + |
| 57 | +echo "Building Open Meteo worker for ${bun_target}" |
| 58 | +( |
| 59 | + cd "${open_meteo_dir}" |
| 60 | + bun install --frozen-lockfile |
| 61 | + bun build src/bin/worker.ts --compile --target="${bun_target}" \ |
| 62 | + --outfile "${output_dir}/vgi-open-meteo" |
| 63 | +) |
| 64 | + |
| 65 | +echo "Building Rust worker" |
| 66 | +if [[ -n "${VGI_RUST_TARGET:-}" ]]; then |
| 67 | + if ! command -v cargo-zigbuild >/dev/null 2>&1; then |
| 68 | + echo "VGI_RUST_TARGET requires cargo-zigbuild on PATH" >&2 |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + ( |
| 72 | + cd "${rust_dir}" |
| 73 | + cargo zigbuild --locked --release --target "${VGI_RUST_TARGET}" -p vgi-example-worker |
| 74 | + ) |
| 75 | + rust_binary="${rust_dir}/target/${VGI_RUST_TARGET}/release/vgi-example-worker" |
| 76 | +else |
| 77 | + ( |
| 78 | + cd "${rust_dir}" |
| 79 | + cargo build --locked --release -p vgi-example-worker |
| 80 | + ) |
| 81 | + rust_binary="${rust_dir}/target/release/vgi-example-worker" |
| 82 | +fi |
| 83 | + |
| 84 | +# Use a multi-file archive for Rust so this lane proves safe tar.gz extraction, |
| 85 | +# relative entrypoint selection, and execution rather than only raw BLOB copies. |
| 86 | +mkdir -p "${scratch_dir}/rust-package/bin" |
| 87 | +install -m 0755 "${rust_binary}" "${scratch_dir}/rust-package/bin/vgi-rust-worker" |
| 88 | +printf '%s\n' "VGI Rust database-worker fixture" > "${scratch_dir}/rust-package/BUILD.txt" |
| 89 | +tar -czf "${output_dir}/vgi-rust-worker.tar.gz" \ |
| 90 | + -C "${scratch_dir}/rust-package" bin BUILD.txt |
| 91 | + |
| 92 | +echo "Built database-worker artifacts in ${output_dir}" |
| 93 | +ls -lh "${output_dir}/vgi-python-worker" \ |
| 94 | + "${output_dir}/vgi-open-meteo" \ |
| 95 | + "${output_dir}/vgi-rust-worker.tar.gz" |
0 commit comments