- innesco-protocol: ECS wire protocol client (port of ecs/protocol.py) - innesco-decoding: 13-byte frame decoder (port of csrc/decoding.c), golden tests mirror tests/test_decode_golden.py (14/14 green) - innesco-cli: ping / decode subcommands - scripts/build-arm64.sh: rootless cross build for AMD Kria K26 (aarch64 via cargo-zigbuild + zig, musl static default) - zero external dependencies (std only)
90 lines
3.2 KiB
Bash
Executable File
90 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Cross-compile innesco-rs for aarch64 (deployment target: AMD Kria K26 SOM,
|
|
# quad Cortex-A53 on Zynq UltraScale+ MPSoC, Ubuntu 22.04 on the board).
|
|
#
|
|
# No root and no Docker needed: uses cargo-zigbuild + the ziglang pip package
|
|
# as the cross linker (glibc OR static musl). First-time setup is automated:
|
|
# - rustup target add aarch64-unknown-linux-{musl,gnu}
|
|
# - python3 venv with `ziglang` (wrapper script `zig` exposed on PATH)
|
|
# - cargo install cargo-zigbuild
|
|
#
|
|
# Usage: scripts/build-arm64.sh [--musl|--gnu] [--host] [--run-tests]
|
|
# --musl static binary, no glibc dependency (default, recommended for Kria)
|
|
# --gnu dynamic binary against aarch64 glibc (matches board's Ubuntu 22.04)
|
|
# --host also build for the host (x86_64) in release mode
|
|
# --run-tests run the test suite for the host target before cross-building
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$ROOT"
|
|
|
|
MODE=gnu
|
|
HOST=0
|
|
RUN_TESTS=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--musl) MODE=musl ;;
|
|
--gnu) MODE=gnu ;;
|
|
--host) HOST=1 ;;
|
|
--run-tests) RUN_TESTS=1 ;;
|
|
*) echo "unknown option: $arg (use --musl|--gnu|--host|--run-tests)" >&2; exit 2 ;;
|
|
esac
|
|
done
|
|
|
|
TARGET="aarch64-unknown-linux-${MODE}"
|
|
DIST="$ROOT/dist/aarch64-${MODE}"
|
|
export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-/tmp/innesco-rs-target}"
|
|
|
|
# --- toolchain bootstrap (idempotent, no root) --------------------------------
|
|
if ! command -v rustup >/dev/null 2>&1; then
|
|
# shellcheck disable=SC1091
|
|
source "$HOME/.cargo/env" 2>/dev/null || {
|
|
echo "rustup not found: install with 'curl https://sh.rustup.rs | sh'" >&2; exit 1; }
|
|
fi
|
|
rustup target add "$TARGET" >/dev/null
|
|
|
|
ZIG_VENV="${INNESCO_RS_ZIG_VENV:-/tmp/venvs/zig}"
|
|
if [ ! -x "$ZIG_VENV/bin/python" ]; then
|
|
echo "== setting up zig venv in $ZIG_VENV (one-time)"
|
|
PYTHON="${INNESCO_RS_PYTHON:-python3}"
|
|
"$PYTHON" -m venv "$ZIG_VENV"
|
|
"$ZIG_VENV/bin/pip" -q install ziglang
|
|
fi
|
|
ZIG_BIN="$ZIG_VENV/zigbin"
|
|
if [ ! -x "$ZIG_BIN/zig" ]; then
|
|
echo "== creating zig wrapper in $ZIG_BIN (one-time)"
|
|
mkdir -p "$ZIG_BIN"
|
|
printf '#!/bin/sh\nexec %q -m ziglang "$@"\n' "$ZIG_VENV/bin/python" > "$ZIG_BIN/zig"
|
|
chmod +x "$ZIG_BIN/zig"
|
|
fi
|
|
export PATH="$ZIG_BIN:$PATH"
|
|
command -v cargo-zigbuild >/dev/null 2>&1 || cargo install cargo-zigbuild
|
|
|
|
# --- build --------------------------------------------------------------------
|
|
if [ "$RUN_TESTS" = 1 ]; then
|
|
echo "== running test suite (host target)"
|
|
cargo test --workspace
|
|
fi
|
|
|
|
echo "== cross-compiling for $TARGET"
|
|
if [ "$HOST" = 1 ]; then
|
|
cargo zigbuild --release --workspace --target "$TARGET" --target host
|
|
else
|
|
cargo zigbuild --release --workspace --target "$TARGET"
|
|
fi
|
|
|
|
mkdir -p "$DIST"
|
|
BIN="$CARGO_TARGET_DIR/$TARGET/release/innesco-cli"
|
|
cp "$BIN" "$DIST/innesco-cli"
|
|
chmod +x "$DIST/innesco-cli"
|
|
|
|
echo "== artifact:"
|
|
file "$DIST/innesco-cli" 2>/dev/null || true
|
|
ls -lh "$DIST/innesco-cli"
|
|
if command -v aarch64-linux-gnu-readelf >/dev/null 2>&1; then
|
|
aarch64-linux-gnu-readelf -h "$DIST/innesco-cli" | grep -E "Class|Machine" || true
|
|
elif command -v readelf >/dev/null 2>&1; then
|
|
readelf -h "$DIST/innesco-cli" | grep -E "Class|Machine" || true
|
|
fi
|
|
echo "== done: $DIST/innesco-cli"
|