nixpkgs/pkgs/development/compilers/zig/setup-hook.sh
Anderson Torres a49eb940a2 zig: reword setup hook
- Move the huge comment from setup-hook.sh to hook.nix
- Prefix zig in the echoCmd calls
2023-09-09 15:27:11 +00:00

71 lines
1.6 KiB
Bash

# shellcheck shell=bash disable=SC2154,SC2086
readonly zigDefaultFlagsArray=(@zig_default_flags@)
function zigSetGlobalCacheDir {
ZIG_GLOBAL_CACHE_DIR=$(mktemp -d)
export ZIG_GLOBAL_CACHE_DIR
}
function zigBuildPhase {
runHook preBuild
local flagsArray=(
"${zigDefaultFlagsArray[@]}"
$zigBuildFlags "${zigBuildFlagsArray[@]}"
)
echoCmd 'zig build flags' "${flagsArray[@]}"
zig build "${flagsArray[@]}"
runHook postBuild
}
function zigCheckPhase {
runHook preCheck
local flagsArray=(
"${zigDefaultFlagsArray[@]}"
$zigCheckFlags "${zigCheckFlagsArray[@]}"
)
echoCmd 'zig check flags' "${flagsArray[@]}"
zig build test "${flagsArray[@]}"
runHook postCheck
}
function zigInstallPhase {
runHook preInstall
local flagsArray=(
"${zigDefaultFlagsArray[@]}"
$zigBuildFlags "${zigBuildFlagsArray[@]}"
$zigInstallFlags "${zigInstallFlagsArray[@]}"
)
if [ -z "${dontAddPrefix-}" ]; then
# Zig does not recognize `--prefix=/dir/`, only `--prefix /dir/`
flagsArray+=("${prefixKey:---prefix}" "$prefix")
fi
echoCmd 'zig install flags' "${flagsArray[@]}"
zig build install "${flagsArray[@]}"
runHook postInstall
}
addEnvHooks "$targetOffset" zigSetGlobalCacheDir
if [ -z "${dontUseZigBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=zigBuildPhase
fi
if [ -z "${dontUseZigCheck-}" ] && [ -z "${checkPhase-}" ]; then
checkPhase=zigCheckPhase
fi
if [ -z "${dontUseZigInstall-}" ] && [ -z "${installPhase-}" ]; then
installPhase=zigInstallPhase
fi