#!/bin/bash
# Wrapper script for zig cc that:
# 1. Uses the correct Zig target (aarch64-linux-musl)
# 2. Strips conflicting --target=aarch64-unknown-linux-musl flags from cmake/boring-sys
# 3. Handles both compilation and assembly

args=()
for arg in "$@"; do
    case "$arg" in
        --target=aarch64-unknown-linux-musl) ;; # Strip Rust-style target
        --target=*-unknown-linux-*) ;; # Strip any Rust-style Linux target
        -target) ;; # Skip standalone -target (zig uses different format)
        aarch64-unknown-linux-musl) ;; # Skip if target is passed as separate arg
        cc) ;; # Skip stray 'cc' argument passed by Cargo/build scripts
        *) args+=("$arg") ;;
    esac
done

exec zig cc -target aarch64-linux-musl "${args[@]}"
