2021-02-14 20:04:54 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"/..
|
|
|
|
|
|
|
|
BINARY="$1"
|
|
|
|
SOURCE="$2"
|
2021-02-15 17:08:18 +00:00
|
|
|
# the rest are NIM_PARAMS
|
2021-02-14 20:04:54 +00:00
|
|
|
shift 2
|
|
|
|
|
2022-11-24 20:56:02 +00:00
|
|
|
NIMC="${NIMC:-nim}"
|
|
|
|
|
2021-02-15 17:08:18 +00:00
|
|
|
# verbosity level
|
|
|
|
[[ -z "$V" ]] && V=0
|
|
|
|
|
2022-02-25 08:19:12 +00:00
|
|
|
# Nim version (formatted as "{MAJOR}{MINOR}").
|
|
|
|
# This weird "sed" invocation is because of macOS.
|
2022-11-24 20:56:02 +00:00
|
|
|
NIM_VERSION=$("$NIMC" --version | head -n1 | sed -E 's/^.* ([0-9])\.([0-9]+).*$/\1\2/')
|
2022-02-25 08:19:12 +00:00
|
|
|
|
|
|
|
# According to old Nim compiler versions, the project name comes from the main
|
|
|
|
# source file, not the output binary.
|
|
|
|
if [[ "${NIM_VERSION}" -ge "16" ]]; then
|
|
|
|
PROJECT_NAME="$(basename ${BINARY%.nim})"
|
|
|
|
else
|
|
|
|
PROJECT_NAME="$(basename ${SOURCE%.nim})"
|
|
|
|
fi
|
2021-02-14 20:04:54 +00:00
|
|
|
|
|
|
|
# The default nimcache dir is "nimcache/release/${PROJECT_NAME}" which doesn't
|
|
|
|
# allow building different binaries from the same main source file, in
|
|
|
|
# parallel.
|
|
|
|
# We can't use '--nimcache:...' here, because the same path is being used by
|
|
|
|
# LTO on macOS, in "config.nims"
|
2022-11-24 20:56:02 +00:00
|
|
|
"$NIMC" c --compileOnly -o:build/${BINARY} "$@" -d:nimCachePathOverride=nimcache/release/${BINARY} "${SOURCE}"
|
2021-02-14 20:04:54 +00:00
|
|
|
build/generate_makefile "nimcache/release/${BINARY}/${PROJECT_NAME}.json" "nimcache/release/${BINARY}/${BINARY}.makefile"
|
2021-11-04 14:35:36 +00:00
|
|
|
# Don't swallow stderr, in case it's important.
|
|
|
|
[[ "$V" == "0" ]] && exec >/dev/null
|
2021-02-14 20:04:54 +00:00
|
|
|
"${MAKE}" -f "nimcache/release/${BINARY}/${BINARY}.makefile" --no-print-directory build
|
|
|
|
|
2021-05-19 06:38:13 +00:00
|
|
|
if uname | grep -qi darwin || [[ -n "${FORCE_DSYMUTIL}" ]]; then
|
|
|
|
[[ -z "${DSYMUTIL}" ]] && DSYMUTIL="dsymutil"
|
2022-02-18 14:30:43 +00:00
|
|
|
# Scary warnings in large volume: https://github.com/status-im/nimbus-eth2/issues/3076
|
|
|
|
"${DSYMUTIL}" build/${BINARY} 2>&1 \
|
|
|
|
| grep -v "failed to insert symbol" \
|
|
|
|
| grep -v "could not find object file symbol for symbol" \
|
|
|
|
|| true
|
2021-05-19 06:38:13 +00:00
|
|
|
fi
|