Update package. Pack package as nix package
This commit is contained in:
78
nix/bisheng-wrapper.sh
Normal file
78
nix/bisheng-wrapper.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
set -eu -o pipefail
|
||||
|
||||
# Bisheng compiler wrapper - similar to NixOS cc-wrapper
|
||||
# This script injects NIX_CFLAGS_COMPILE and other Nix-managed flags
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# Source flag accumulation from dependencies
|
||||
if [ -z "${NIX_CC_WRAPPER_FLAGS_SET_bisheng:-}" ]; then
|
||||
if [ -f "@out@/nix-support/add-flags.sh" ]; then
|
||||
source @out@/nix-support/add-flags.sh
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build extra flags
|
||||
extraAfter=()
|
||||
extraBefore=()
|
||||
|
||||
# Add sysroot for C standard library headers (critical for bisheng)
|
||||
ASCEND_TOOLKIT_HOME="${ASCEND_TOOLKIT_HOME:-}"
|
||||
if [ -n "$ASCEND_TOOLKIT_HOME" ] && [ -d "$ASCEND_TOOLKIT_HOME/tools/hcc/sysroot" ]; then
|
||||
extraBefore+=("--sysroot=$ASCEND_TOOLKIT_HOME/tools/hcc/sysroot")
|
||||
fi
|
||||
|
||||
# Add NIX_CFLAGS_COMPILE (the main flag we care about)
|
||||
if [ -n "${NIX_CFLAGS_COMPILE_bisheng:-}" ]; then
|
||||
extraAfter+=($NIX_CFLAGS_COMPILE_bisheng)
|
||||
elif [ -n "${NIX_CFLAGS_COMPILE:-}" ]; then
|
||||
extraAfter+=($NIX_CFLAGS_COMPILE)
|
||||
fi
|
||||
|
||||
# Add NIX_CFLAGS_COMPILE_BEFORE if set
|
||||
if [ -n "${NIX_CFLAGS_COMPILE_BEFORE_bisheng:-}" ]; then
|
||||
extraBefore+=($NIX_CFLAGS_COMPILE_BEFORE_bisheng)
|
||||
fi
|
||||
|
||||
# Add linker flags if we're linking
|
||||
if [ -n "${NIX_CFLAGS_LINK_bisheng:-}" ]; then
|
||||
extraAfter+=($NIX_CFLAGS_LINK_bisheng)
|
||||
fi
|
||||
|
||||
# Convert LDFLAGS to -Wl, format
|
||||
if [ -n "${NIX_LDFLAGS_bisheng:-}" ]; then
|
||||
for flag in $NIX_LDFLAGS_bisheng; do
|
||||
extraBefore+=("-Wl,$flag")
|
||||
done
|
||||
fi
|
||||
|
||||
# Source local cflags hook if it exists
|
||||
if [ -f "@out@/nix-support/add-local-cc-cflags-before.sh" ]; then
|
||||
source @out@/nix-support/add-local-cc-cflags-before.sh
|
||||
fi
|
||||
|
||||
# Debug output
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "bisheng wrapper: extra flags before:" >&2
|
||||
printf " %q\n" "${extraBefore[@]}" >&2
|
||||
echo "bisheng wrapper: original flags:" >&2
|
||||
printf " %q\n" "$@" >&2
|
||||
echo "bisheng wrapper: extra flags after:" >&2
|
||||
printf " %q\n" "${extraAfter[@]}" >&2
|
||||
fi
|
||||
|
||||
# Find the real bisheng binary
|
||||
BISHENG_REAL="${BISHENG_REAL:-bisheng.real}"
|
||||
if ! command -v "$BISHENG_REAL" &>/dev/null; then
|
||||
# Try to find bisheng in PATH (should be the real one from toolkit)
|
||||
BISHENG_REAL="$(which bisheng 2>/dev/null || echo "bisheng")"
|
||||
fi
|
||||
|
||||
# Execute the real bisheng compiler with injected flags
|
||||
exec "$BISHENG_REAL" \
|
||||
"${extraBefore[@]+"${extraBefore[@]}"}" \
|
||||
"$@" \
|
||||
"${extraAfter[@]+"${extraAfter[@]}"}"
|
||||
Reference in New Issue
Block a user