2020-10-15 12:19:41 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-02-02 22:31:01 +00:00
|
|
|
# Copyright (c) 2020-2021 Status Research & Development GmbH. Licensed under
|
|
|
|
# either of:
|
|
|
|
# - Apache License, version 2.0
|
|
|
|
# - MIT license
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
2020-10-15 12:19:41 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
cd /home/user/nimbus-eth2
|
2020-11-07 07:46:53 +00:00
|
|
|
git config --global core.abbrev 8
|
2020-10-15 12:19:41 +00:00
|
|
|
|
2021-01-07 09:19:29 +00:00
|
|
|
if [[ -z "${1}" ]]; then
|
|
|
|
echo "Usage: $(basename ${0}) PLATFORM"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
PLATFORM="${1}"
|
2020-11-20 13:49:49 +00:00
|
|
|
BINARIES="nimbus_beacon_node nimbus_signing_process"
|
2020-11-06 16:26:03 +00:00
|
|
|
|
2021-01-20 18:58:58 +00:00
|
|
|
#- we need to build everything against libraries available inside this container, including the Nim compiler
|
|
|
|
#- we disable the log file and log colours; the user only has to worry about logging stdout now
|
2020-11-06 16:26:03 +00:00
|
|
|
make clean
|
2021-02-02 22:31:01 +00:00
|
|
|
if [[ "${PLATFORM}" == "Windows_amd64" ]]; then
|
|
|
|
# Cross-compilation using the MXE distribution of Mingw-w64
|
|
|
|
export PATH="/usr/lib/mxe/usr/bin:${PATH}"
|
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
USE_LIBBACKTRACE=0 \
|
2021-02-11 19:03:29 +00:00
|
|
|
QUICK_AND_DIRTY_COMPILER=1 \
|
2021-03-10 02:59:19 +00:00
|
|
|
deps-common build/generate_makefile
|
|
|
|
# This can be reduced to `make CC=... ...` when it becomes possible to
|
|
|
|
# replace `CC=gcc` with `CC=$(CC)` in "vendor/nimbus-build-system/makefiles/targets.mk".
|
2021-03-14 03:19:11 +00:00
|
|
|
CC=x86_64-w64-mingw32.static-gcc
|
|
|
|
CXX=x86_64-w64-mingw32.static-g++
|
2021-02-02 22:31:01 +00:00
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
-C vendor/nim-nat-traversal/vendor/miniupnp/miniupnpc \
|
|
|
|
-f Makefile.mingw \
|
2021-03-14 03:19:11 +00:00
|
|
|
CC="${CC}" \
|
2021-02-02 22:31:01 +00:00
|
|
|
libminiupnpc.a &>/dev/null
|
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
-C vendor/nim-nat-traversal/vendor/libnatpmp-upstream \
|
2021-03-14 03:19:11 +00:00
|
|
|
CC="${CC}" \
|
2021-02-02 22:31:01 +00:00
|
|
|
CFLAGS="-Wall -Os -DWIN32 -DNATPMP_STATICLIB -DENABLE_STRNATPMPERR -DNATPMP_MAX_RETRIES=4 ${CFLAGS}" \
|
|
|
|
libnatpmp.a &>/dev/null
|
2021-03-14 03:19:11 +00:00
|
|
|
# We set CXX and add CXXFLAGS for libunwind's C++ code, even though we don't
|
|
|
|
# use those C++ objects. I don't see an easy way of disabling the C++ parts in
|
|
|
|
# libunwind itself.
|
|
|
|
#
|
|
|
|
# "libunwind.a" combines objects produced from C and C++ code. Even though we
|
|
|
|
# don't link any C++-generated objects, the linker still checks them for
|
|
|
|
# undefined symbols, so we're forced to use g++ as a linker wrapper.
|
|
|
|
# For some reason, macOS's Clang doesn't need this trick, nor do native (and
|
|
|
|
# newer) Mingw-w64 toolchains on Windows.
|
2021-02-02 22:31:01 +00:00
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
2021-03-14 03:19:11 +00:00
|
|
|
CC="${CC}" \
|
|
|
|
CXX="${CXX}" \
|
|
|
|
CXXFLAGS="${CXXFLAGS} -D__STDC_FORMAT_MACROS -D_WIN32_WINNT=0x0600" \
|
|
|
|
USE_VENDORED_LIBUNWIND=1 \
|
2021-02-02 22:31:01 +00:00
|
|
|
LOG_LEVEL="TRACE" \
|
2021-03-14 03:19:11 +00:00
|
|
|
NIMFLAGS="-d:disableMarchNative -d:chronicles_sinks=textlines -d:chronicles_colors=none --os:windows --gcc.exe=${CC} --gcc.linkerexe=${CXX} --passL:-static" \
|
2021-02-02 22:31:01 +00:00
|
|
|
${BINARIES}
|
2021-03-10 02:59:19 +00:00
|
|
|
elif [[ "${PLATFORM}" == "Linux_arm32v7" ]]; then
|
|
|
|
CC="arm-linux-gnueabihf-gcc"
|
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
USE_LIBBACKTRACE=0 \
|
|
|
|
QUICK_AND_DIRTY_COMPILER=1 \
|
|
|
|
deps-common build/generate_makefile
|
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
LOG_LEVEL="TRACE" \
|
|
|
|
CC="${CC}" \
|
|
|
|
NIMFLAGS="-d:disableMarchNative -d:chronicles_sinks=textlines -d:chronicles_colors=none --cpu:arm --gcc.exe=${CC} --gcc.linkerexe=${CC}" \
|
|
|
|
PARTIAL_STATIC_LINKING=1 \
|
|
|
|
${BINARIES}
|
|
|
|
elif [[ "${PLATFORM}" == "Linux_arm64v8" ]]; then
|
|
|
|
CC="aarch64-linux-gnu-gcc"
|
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
USE_LIBBACKTRACE=0 \
|
|
|
|
QUICK_AND_DIRTY_COMPILER=1 \
|
|
|
|
deps-common build/generate_makefile
|
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
LOG_LEVEL="TRACE" \
|
|
|
|
CC="${CC}" \
|
|
|
|
NIMFLAGS="-d:disableMarchNative -d:chronicles_sinks=textlines -d:chronicles_colors=none --cpu:arm64 --gcc.exe=${CC} --gcc.linkerexe=${CC}" \
|
|
|
|
PARTIAL_STATIC_LINKING=1 \
|
|
|
|
${BINARIES}
|
2021-02-02 22:31:01 +00:00
|
|
|
else
|
|
|
|
make \
|
|
|
|
-j$(nproc) \
|
|
|
|
LOG_LEVEL="TRACE" \
|
|
|
|
NIMFLAGS="-d:disableMarchNative -d:chronicles_sinks=textlines -d:chronicles_colors=none" \
|
|
|
|
PARTIAL_STATIC_LINKING=1 \
|
2021-02-11 19:03:29 +00:00
|
|
|
QUICK_AND_DIRTY_COMPILER=1 \
|
2021-02-02 22:31:01 +00:00
|
|
|
${BINARIES}
|
|
|
|
fi
|
2020-11-06 16:26:03 +00:00
|
|
|
|
|
|
|
# archive directory (we need the Nim compiler in here)
|
2021-01-07 09:19:29 +00:00
|
|
|
PREFIX="nimbus-eth2_${PLATFORM}_"
|
2020-10-15 12:19:41 +00:00
|
|
|
GIT_COMMIT="$(git rev-parse --short HEAD)"
|
2020-11-06 16:26:03 +00:00
|
|
|
VERSION="$(./env.sh nim --verbosity:0 --hints:off --warnings:off scripts/print_version.nims)"
|
2020-11-07 07:46:53 +00:00
|
|
|
DIR="${PREFIX}${VERSION}_${GIT_COMMIT}"
|
2020-10-15 12:19:41 +00:00
|
|
|
DIST_PATH="dist/${DIR}"
|
|
|
|
# delete old artefacts
|
2020-11-05 19:51:35 +00:00
|
|
|
rm -rf "dist/${PREFIX}"*.tar.gz
|
2020-11-07 07:46:53 +00:00
|
|
|
if [[ -d "${DIST_PATH}" ]]; then
|
|
|
|
rm -rf "${DIST_PATH}"
|
|
|
|
fi
|
2020-11-09 08:12:48 +00:00
|
|
|
|
2020-10-15 12:19:41 +00:00
|
|
|
mkdir -p "${DIST_PATH}"
|
2020-11-07 18:00:31 +00:00
|
|
|
mkdir "${DIST_PATH}/scripts"
|
|
|
|
mkdir "${DIST_PATH}/build"
|
2020-10-15 12:19:41 +00:00
|
|
|
|
2020-11-06 16:26:03 +00:00
|
|
|
# copy and checksum binaries, copy scripts and docs
|
2020-10-15 12:19:41 +00:00
|
|
|
for BINARY in ${BINARIES}; do
|
2021-02-02 22:31:01 +00:00
|
|
|
cp -a "./build/${BINARY}" "${DIST_PATH}/build/"
|
2020-11-07 18:00:31 +00:00
|
|
|
cd "${DIST_PATH}/build"
|
2021-02-02 22:31:01 +00:00
|
|
|
sha512sum "${BINARY}" > "${BINARY}.sha512sum"
|
|
|
|
if [[ "${PLATFORM}" == "Windows_amd64" ]]; then
|
|
|
|
mv "${BINARY}" "${BINARY}.exe"
|
|
|
|
fi
|
2020-10-15 12:19:41 +00:00
|
|
|
cd - >/dev/null
|
|
|
|
done
|
|
|
|
sed -e "s/GIT_COMMIT/${GIT_COMMIT}/" docker/dist/README.md > "${DIST_PATH}/README.md"
|
2021-02-06 20:22:25 +00:00
|
|
|
|
|
|
|
if [[ "${PLATFORM}" == "Linux_amd64" ]]; then
|
|
|
|
sed -i -e 's/^make dist$/make dist-amd64/' "${DIST_PATH}/README.md"
|
|
|
|
elif [[ "${PLATFORM}" == "Linux_arm32v7" ]]; then
|
|
|
|
sed -i -e 's/^make dist$/make dist-arm/' "${DIST_PATH}/README.md"
|
|
|
|
elif [[ "${PLATFORM}" == "Linux_arm64v8" ]]; then
|
|
|
|
sed -i -e 's/^make dist$/make dist-arm64/' "${DIST_PATH}/README.md"
|
|
|
|
elif [[ "${PLATFORM}" == "Windows_amd64" ]]; then
|
|
|
|
sed -i -e 's/^make dist$/make dist-win64/' "${DIST_PATH}/README.md"
|
2021-02-02 22:31:01 +00:00
|
|
|
cp -a docker/dist/README-Windows.md "${DIST_PATH}/"
|
|
|
|
fi
|
2021-02-06 20:22:25 +00:00
|
|
|
|
2020-11-09 08:12:48 +00:00
|
|
|
cp -a scripts/run-beacon-node.sh "${DIST_PATH}/scripts"
|
2020-11-07 18:00:31 +00:00
|
|
|
cp -a ./run-*-beacon-node.sh "${DIST_PATH}/"
|
2020-10-15 12:19:41 +00:00
|
|
|
|
|
|
|
# create the tarball
|
|
|
|
cd dist
|
|
|
|
tar czf "${DIR}.tar.gz" "${DIR}"
|
|
|
|
# don't leave the directory hanging around
|
|
|
|
rm -rf "${DIR}"
|
|
|
|
cd - >/dev/null
|
|
|
|
|