diff --git a/.gitignore b/.gitignore index ea8c4bf..d74d08d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +.DS_Store + /target diff --git a/examples/docker-network/scripts/build.sh b/examples/docker-network/scripts/build.sh index d29175d..fc6d8a6 100755 --- a/examples/docker-network/scripts/build.sh +++ b/examples/docker-network/scripts/build.sh @@ -1,5 +1,6 @@ #!/bin/bash # Build the FIPS binary and copy it to the docker build context. +# Supports cross-compilation from macOS to Linux using cargo-zigbuild. set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" @@ -13,11 +14,42 @@ if [ ! -f "$PROJECT_ROOT/Cargo.toml" ]; then exit 1 fi -echo "Building FIPS (release)..." -cargo build --release --manifest-path="$PROJECT_ROOT/Cargo.toml" +# Detect host OS +UNAME_S=$(uname -s) +CARGO_TARGET="x86_64-unknown-linux-musl" -echo "Copying binary to docker context..." -cp "$PROJECT_ROOT/target/release/fips" "$DOCKER_DIR/fips" +# Check for cross-compilation tooling on macOS +if [ "$UNAME_S" = "Darwin" ]; then + echo "Detected macOS host - using cross-compilation for Linux..." + + # Check if cargo-zigbuild is installed + if ! command -v cargo-zigbuild &> /dev/null; then + echo "Error: cargo-zigbuild not found." >&2 + echo "Please install it: cargo install cargo-zigbuild" >&2 + echo "" >&2 + echo "Or install zig directly: brew install zig" >&2 + exit 1 + fi + + # Check if target is installed + if ! rustup target list --installed | grep -q "$CARGO_TARGET"; then + echo "Installing Rust target $CARGO_TARGET..." + rustup target add "$CARGO_TARGET" + fi + + echo "Building FIPS for Linux (release) using cargo-zigbuild..." + cargo zigbuild --release --target "$CARGO_TARGET" --manifest-path="$PROJECT_ROOT/Cargo.toml" + + echo "Copying binary to docker context..." + cp "$PROJECT_ROOT/target/$CARGO_TARGET/release/fips" "$DOCKER_DIR/fips" +else + # Native Linux build + echo "Building FIPS (release)..." + cargo build --release --manifest-path="$PROJECT_ROOT/Cargo.toml" + + echo "Copying binary to docker context..." + cp "$PROJECT_ROOT/target/release/fips" "$DOCKER_DIR/fips" +fi echo "Done. Binary at $DOCKER_DIR/fips" echo ""