25 lines
1.2 KiB
Bash
Executable File
25 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# usage: scripts/build.sh <nim-os> <nim-cpu> <zig-target> <output>
|
|
# e.g. scripts/build.sh windows amd64 x86_64-windows-gnu dist/sirmem-windows-x86_64.exe
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
os=$1 cpu=$2 target=$3 out=$4
|
|
mkdir -p "$(dirname "$out")"
|
|
export ZIG_TARGET=$target
|
|
# Notes from trial and error with zig 0.16: --opt:size breaks linking (empty undefined
|
|
# symbols); -d:useMalloc is needed on linux-musl; aarch64-linux needs --tlsEmulation:on
|
|
# (TLS relocs fail to link otherwise) but x86_64-linux fails *with* it.
|
|
extra=()
|
|
if [ "$os" = linux ] && [ "$cpu" = arm64 ]; then extra+=(--tlsEmulation:on); fi
|
|
# zig cc 0.16 sporadically fails to link aarch64-linux ("undefined symbol:" with an empty
|
|
# name, also seen as CacheCheckFailed); a retry succeeds, so retry up to 5 times.
|
|
for attempt in 1 2 3 4 5; do
|
|
rm -rf "nimcache/$target"
|
|
if nim c -d:release -d:strip -d:useMalloc --parallelBuild:1 --hints:off \
|
|
"${extra[@]}" --os:"$os" --cpu:"$cpu" \
|
|
--cc:clang --clang.exe:"$PWD/scripts/zigcc" --clang.linkerexe:"$PWD/scripts/zigcc" \
|
|
--nimcache:"nimcache/$target" -o:"$out" src/sirmem.nim ; then exit 0; fi
|
|
echo "build attempt $attempt failed, retrying" >&2
|
|
done
|
|
exit 1
|