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

args=()
for arg in "$@"; do
    case "$arg" in
        --target=x86_64-unknown-linux-gnu) ;; # Strip Rust-style target
        --target=*-unknown-linux-*) ;; # Strip any Rust-style Linux target
        -target) ;; # Skip standalone -target (zig uses different format)
        x86_64-unknown-linux-gnu) ;; # 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 x86_64-linux-gnu "${args[@]}"
