#!/usr/bin/env bash # Build only MeshPort's application-mode SDK; no VPN or internet proxy engine. set -euo pipefail repo="$(cd "$(dirname "$0")/.." && pwd)" mesh="${MT_MESHPORT_ROOT:-$repo/third_party/meshport}" platform="${1:-macos}" export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$repo/build/meshport-runtime}" command -v cargo >/dev/null || { echo "Rust 1.95+ is required (cargo not found)" >&2; exit 1; } cd "$mesh" if [ "$platform" = android ]; then sdk="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}" ndk="${ANDROID_NDK_ROOT:-${ANDROID_NDK_HOME:-}}" if [ -z "$ndk" ]; then ndk="$sdk/ndk/$(ls "$sdk/ndk" | sort -V | tail -1)"; fi tools="$ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin" export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$tools/aarch64-linux-android24-clang" export CC_aarch64_linux_android="$CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER" export AR_aarch64_linux_android="$tools/llvm-ar" export CARGO_TARGET_AARCH64_LINUX_ANDROID_RUSTFLAGS='-C link-arg=-Wl,-z,max-page-size=16384' exec cargo build --manifest-path "$repo/src/meshport/runtime/Cargo.toml" --target aarch64-linux-android --release --locked elif [ "$platform" = macos ]; then exec cargo build --manifest-path "$repo/src/meshport/runtime/Cargo.toml" --release --locked fi printf 'usage: %s [macos|android]\n' "$0" >&2 exit 2