From cf5d0d3f8bbdfb97209beb78498029ad940fac08 Mon Sep 17 00:00:00 2001 From: "Rodrigo Q. Saramago" Date: Thu, 24 Nov 2022 21:16:00 +0100 Subject: [PATCH] =?UTF-8?q?Let=20the=20nightlies=20call=20themselves=20'ni?= =?UTF-8?q?ghtly',=20the=20return.=20Co-authored-by:=20Kamil=20=C5=9Aliwak?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/build_emscripten.sh | 9 ++- scripts/ci/build.sh | 9 ++- scripts/ci/build_emscripten.sh | 124 +++++++++++++++++++++------------ 3 files changed, 92 insertions(+), 50 deletions(-) diff --git a/scripts/build_emscripten.sh b/scripts/build_emscripten.sh index abe273ac2..fe830dc58 100755 --- a/scripts/build_emscripten.sh +++ b/scripts/build_emscripten.sh @@ -28,10 +28,9 @@ set -e -if test -z "$1"; then - BUILD_DIR="emscripten_build" -else - BUILD_DIR="$1" +params="" +if (( $# != 0 )); then + params="$(printf "%q " "${@}")" fi # solbuildpackpusher/solidity-buildpack-deps:emscripten-14 @@ -39,4 +38,4 @@ fi # See https://github.blog/2022-04-12-git-security-vulnerability-announced/ docker run -v "$(pwd):/root/project" -w /root/project \ solbuildpackpusher/solidity-buildpack-deps@sha256:f1c13f3450d1f2e53ea18ac1ac1a17e932573cb9a5ccd0fd9ef6dd44f6402fa9 \ - /bin/bash -c "git config --global --add safe.directory /root/project && ./scripts/ci/build_emscripten.sh $BUILD_DIR" + /bin/bash -c "git config --global --add safe.directory /root/project && ./scripts/ci/build_emscripten.sh ${params}" diff --git a/scripts/ci/build.sh b/scripts/ci/build.sh index 87138fb05..d529b03c1 100755 --- a/scripts/ci/build.sh +++ b/scripts/ci/build.sh @@ -2,17 +2,22 @@ set -ex ROOTDIR="$(dirname "$0")/../.." +# shellcheck source=scripts/common.sh +source "${ROOTDIR}/scripts/common.sh" + +prerelease_source="${1:-ci}" + cd "${ROOTDIR}" # shellcheck disable=SC2166 if [ "$CIRCLE_BRANCH" = release -o -n "$CIRCLE_TAG" -o -n "$FORCE_RELEASE" ] then - echo -n "" >prerelease.txt + echo -n >prerelease.txt else # Use last commit date rather than build date to avoid ending up with builds for # different platforms having different version strings (and therefore producing different bytecode) # if the CI is triggered just before midnight. - TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="ci.%cd" >prerelease.txt + TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="${prerelease_source}.%cd" >prerelease.txt fi if [ -n "$CIRCLE_SHA1" ] diff --git a/scripts/ci/build_emscripten.sh b/scripts/ci/build_emscripten.sh index c1e117c6c..04e16293f 100755 --- a/scripts/ci/build_emscripten.sh +++ b/scripts/ci/build_emscripten.sh @@ -34,55 +34,93 @@ set -ev -if test -z "$1"; then - BUILD_DIR="emscripten_build" -else - BUILD_DIR="$1" -fi +SCRIPT_DIR="$(realpath "$(dirname "$0")/..")" +# shellcheck source=scripts/common.sh +source "${SCRIPT_DIR}/common.sh" -WORKSPACE=/root/project +function build() { + local build_dir="$1" + local prerelease_source="${2:-ci}" -cd "$WORKSPACE" + cd /root/project -# shellcheck disable=SC2166 -if [[ "$CIRCLE_BRANCH" = release || -n "$CIRCLE_TAG" || -n "$FORCE_RELEASE" || "$(git tag --points-at HEAD 2>/dev/null)" == v* ]] -then - echo -n >prerelease.txt -else - # Use last commit date rather than build date to avoid ending up with builds for - # different platforms having different version strings (and therefore producing different bytecode) - # if the CI is triggered just before midnight. - TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="ci.%cd" >prerelease.txt -fi -if [ -n "$CIRCLE_SHA1" ] -then - echo -n "$CIRCLE_SHA1" >commit_hash.txt -fi + # shellcheck disable=SC2166 + if [[ "$CIRCLE_BRANCH" = release || -n "$CIRCLE_TAG" || -n "$FORCE_RELEASE" || "$(git tag --points-at HEAD 2>/dev/null)" == v* ]] + then + echo -n >prerelease.txt + else + # Use last commit date rather than build date to avoid ending up with builds for + # different platforms having different version strings (and therefore producing different bytecode) + # if the CI is triggered just before midnight. + TZ=UTC git show --quiet --date="format-local:%Y.%-m.%-d" --format="${prerelease_source}.%cd" >prerelease.txt + fi + if [ -n "$CIRCLE_SHA1" ] + then + echo -n "$CIRCLE_SHA1" >commit_hash.txt + fi -# Disable warnings for unqualified `move()` calls, introduced and enabled by -# default in clang-16 which is what the emscripten docker image uses. -# Additionally, disable the warning for unknown warnings here, as this script is -# also used with earlier clang versions. -# TODO: This can be removed if and when all usages of `move()` in our codebase use the `std::` qualifier. -CMAKE_CXX_FLAGS="-Wno-unqualified-std-cast-call" + # Disable warnings for unqualified `move()` calls, introduced and enabled by + # default in clang-16 which is what the emscripten docker image uses. + # Additionally, disable the warning for unknown warnings here, as this script is + # also used with earlier clang versions. + # TODO: This can be removed if and when all usages of `move()` in our codebase use the `std::` qualifier. + CMAKE_CXX_FLAGS="-Wno-unqualified-std-cast-call" + mkdir -p "$build_dir" + cd "$build_dir" + emcmake cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DBoost_USE_STATIC_LIBS=1 \ + -DBoost_USE_STATIC_RUNTIME=1 \ + -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \ + -DTESTS=0 \ + .. + make soljson -mkdir -p "$BUILD_DIR" -cd "$BUILD_DIR" -emcmake cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DBoost_USE_STATIC_LIBS=1 \ - -DBoost_USE_STATIC_RUNTIME=1 \ - -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" \ - -DTESTS=0 \ - .. -make soljson + cd .. + mkdir -p upload + scripts/ci/pack_soljson.sh "$build_dir/libsolc/soljson.js" "$build_dir/libsolc/soljson.wasm" upload/soljson.js + cp upload/soljson.js ./ -cd .. -mkdir -p upload -scripts/ci/pack_soljson.sh "$BUILD_DIR/libsolc/soljson.js" "$BUILD_DIR/libsolc/soljson.wasm" upload/soljson.js -cp upload/soljson.js ./ + OUTPUT_SIZE=$(ls -la soljson.js) -OUTPUT_SIZE=$(ls -la soljson.js) + echo "Emscripten output size: $OUTPUT_SIZE" +} -echo "Emscripten output size: $OUTPUT_SIZE" +function show_help() { +cat << EOF +Usage: ${0##*/} [-h|--help] [--build-dir DIR] [--prerelease-source prerelease_source] +Build Solidity emscripten binary + -h | --help Display this help message + --build-dir The emscripten build directory + --prerelease-source The prerelease source string. E.g. 'nightly' or 'ci'. +EOF +} + +function main() { + local build_dir="emscripten_build" + local prerelease_source="" + + while (( $# > 0 )); do + case "$1" in + -h|--help) + show_help + exit 0 + ;; + --build-dir) + [[ -n "$2" ]] || fail "Option --build-dir cannot be empty" + build_dir="$2" + shift 2 + ;; + --prerelease-source) + [[ -n "$2" ]] || fail "Option --prerelease-source cannot be empty" + prerelease_source="$2" + shift 2 + ;; + *) fail "Invalid option: $1" ;; + esac + done + build "$build_dir" "$prerelease_source" +} + +main "$@"