simplify zig script

This commit is contained in:
DubbleClick 2025-07-01 14:12:51 +07:00
parent 9c7e2171f6
commit ba7f994a71

View File

@ -34,52 +34,17 @@ while [[ $# -gt 0 ]]; do
esac
done
SPC_TARGET_WAS_SET=1
if [ -z "${SPC_TARGET+x}" ]; then
SPC_TARGET_WAS_SET=0
output=$(zig cc -target ${SPC_TARGET} -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1)
status=$?
if [ $status -eq 0 ]; then
echo "$output"
exit 0
fi
UNAME_M="$(uname -m)"
UNAME_S="$(uname -s)"
case "$UNAME_M" in
x86_64) ARCH="x86_64" ;;
aarch64|arm64) ARCH="aarch64" ;;
*) echo "Unsupported architecture: $UNAME_M" >&2; exit 1 ;;
esac
case "$UNAME_S" in
Linux) OS="linux" ;;
Darwin) OS="macos" ;;
*) echo "Unsupported OS: $UNAME_S" >&2; exit 1 ;;
esac
SPC_TARGET="${SPC_TARGET:-$ARCH-$OS}"
if [ "$SPC_LIBC" = "glibc" ]; then
SPC_LIBC="gnu"
fi
if [ "$SPC_TARGET_WAS_SET" -eq 0 ] && [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then
exec zig cc ${COMPILER_EXTRA} "${PARSED_ARGS[@]}"
elif [ -z "$SPC_LIBC" ] && [ -z "$SPC_LIBC_VERSION" ]; then
exec zig cc -target "${SPC_TARGET}" ${COMPILER_EXTRA} "${PARSED_ARGS[@]}"
if echo "$output" | grep -q "version '.*' in target triple"; then
echo "$output" | grep -v "version '.*' in target triple"
exit 0
else
TARGET="${SPC_TARGET}-${SPC_LIBC}"
[ -n "$SPC_LIBC_VERSION" ] && TARGET="${TARGET}.${SPC_LIBC_VERSION}"
output=$(zig cc -target ${TARGET} -lstdc++ ${COMPILER_EXTRA} "${PARSED_ARGS[@]}" 2>&1)
status=$?
if [ $status -eq 0 ]; then
echo "$output"
exit 0
fi
if echo "$output" | grep -q "version '.*' in target triple"; then
echo "$output" | grep -v "version '.*' in target triple"
exit 0
else
exec zig cc -target ${TARGET} ${COMPILER_EXTRA} "${PARSED_ARGS[@]}"
fi
exec zig cc -target ${SPC_TARGET} ${COMPILER_EXTRA} "${PARSED_ARGS[@]}"
fi