Link the inference engine for macOS in a zig container
`docker/macos` builds for aarch64-apple-darwin from Linux with cargo-zigbuild. Zig carries libSystem and the C headers, so tract's SIMD kernels compile and the engine's test binaries and examples link as Mach-O arm64 — the check `cargo check --target` could not do, because tract's build script needs a macOS C compiler. Crates that link an Apple framework (dr-plat's keyring, and so the app) still need the Xcode SDK and fail at the link; macos.md says so.
This commit is contained in:
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run a command inside the DarkRoom macOS link-check container.
|
||||
#
|
||||
# ./docker/macos/build.sh cargo zigbuild --target aarch64-apple-darwin -p dr-inference-engine --all-targets
|
||||
# ./docker/macos/build.sh # interactive shell
|
||||
#
|
||||
# Builds the image on first use; `--rebuild` after editing the Dockerfile.
|
||||
set -euo pipefail
|
||||
|
||||
IMAGE="darkroom-macos:latest"
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "${HERE}/../.." && pwd)"
|
||||
|
||||
if command -v podman >/dev/null 2>&1; then
|
||||
ENGINE=podman
|
||||
elif command -v docker >/dev/null 2>&1; then
|
||||
ENGINE=docker
|
||||
else
|
||||
echo "error: neither podman nor docker found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "${1:-}" == "--rebuild" ]]; then
|
||||
shift
|
||||
"${ENGINE}" build -t "${IMAGE}" "${HERE}"
|
||||
elif ! "${ENGINE}" image inspect "${IMAGE}" >/dev/null 2>&1; then
|
||||
echo "==> building ${IMAGE} (first run; a few minutes)"
|
||||
"${ENGINE}" build -t "${IMAGE}" "${HERE}"
|
||||
fi
|
||||
|
||||
# Registry, target and zig's own cache persist across runs.
|
||||
CACHE="${XDG_CACHE_HOME:-${HOME}/.cache}/darkroom-macos"
|
||||
mkdir -p "${CACHE}/registry" "${CACHE}/target" "${CACHE}/home"
|
||||
|
||||
ARGS=(
|
||||
--rm
|
||||
-v "${REPO}:/work:z"
|
||||
-v "${CACHE}/registry:/opt/cargo/registry:z"
|
||||
-v "${CACHE}/target:/work/target-macos:z"
|
||||
-v "${CACHE}/home:/tmp/home:z"
|
||||
-e HOME=/tmp/home
|
||||
-e CARGO_TARGET_DIR=/work/target-macos
|
||||
-w /work
|
||||
)
|
||||
|
||||
# Capped for the same reason as the Windows image: a cross build otherwise
|
||||
# takes every thread on the host.
|
||||
JOBS="${DARKROOM_BUILD_JOBS:-8}"
|
||||
if [[ "${JOBS}" != "0" ]]; then
|
||||
ARGS+=(--cpus "${JOBS}" -e "CARGO_BUILD_JOBS=${JOBS}")
|
||||
fi
|
||||
|
||||
if [[ "${ENGINE}" == "docker" ]]; then
|
||||
ARGS+=(--user "$(id -u):$(id -g)")
|
||||
fi
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
ARGS+=(-it)
|
||||
set -- /bin/bash
|
||||
fi
|
||||
|
||||
exec "${ENGINE}" run "${ARGS[@]}" "${IMAGE}" "$@"
|
||||
Reference in New Issue
Block a user