From 3d10ae3ee3bc827a3f70f6da0fca3d7ca66b1512 Mon Sep 17 00:00:00 2001 From: Powei Feng Date: Wed, 7 May 2025 12:39:11 -0700 Subject: [PATCH] github: more build file refactoring (#8678) - Move emscripten download into its own script - Refactor the common "CI choice" prompt into its own file. - Move the content of `build/common/ci-common.sh` to the "CI choice" script. - Mention the get-emscripten.sh script in BUILDING.md --- .github/actions/dep-versions/action.yml | 2 +- .github/actions/web-prereq/action.yml | 16 +++++++++++++ .github/workflows/presubmit.yml | 1 + .github/workflows/release.yml | 1 + .github/workflows/web-continuous.yml | 1 + BUILDING.md | 2 ++ build/android/build.sh | 29 +---------------------- build/common/build-common.sh | 15 ++++++++++++ build/common/ci-check.sh | 19 +++++++++++++++ build/common/ci-common.sh | 5 ---- build/common/get-emscripten.sh | 22 ++++++++++++++++++ build/common/versions | 3 ++- build/ios/build.sh | 26 +-------------------- build/linux/build.sh | 31 ++----------------------- build/mac/build.sh | 27 ++------------------- build/web/build.sh | 26 +-------------------- build/web/ci-common.sh | 11 --------- 17 files changed, 87 insertions(+), 150 deletions(-) create mode 100644 .github/actions/web-prereq/action.yml create mode 100644 build/common/ci-check.sh delete mode 100755 build/common/ci-common.sh create mode 100755 build/common/get-emscripten.sh delete mode 100755 build/web/ci-common.sh diff --git a/.github/actions/dep-versions/action.yml b/.github/actions/dep-versions/action.yml index dc2b48b59c..bdd2e32a76 100644 --- a/.github/actions/dep-versions/action.yml +++ b/.github/actions/dep-versions/action.yml @@ -3,5 +3,5 @@ runs: using: "composite" steps: - name: Set up dependency versions - shell: bash + shell: bash run: cat ./build/common/versions >> $GITHUB_ENV diff --git a/.github/actions/web-prereq/action.yml b/.github/actions/web-prereq/action.yml new file mode 100644 index 0000000000..d239dea0f1 --- /dev/null +++ b/.github/actions/web-prereq/action.yml @@ -0,0 +1,16 @@ +name: 'Web Preqrequisites' +runs: + using: "composite" + steps: + - uses: ./.github/actions/dep-versions + - name: Cache EMSDK + id: emsdk-cache + uses: actions/cache@v4 # Use a specific version + with: + path: emsdk + key: ${{ runner.os }}-emsdk-${{ env.GITHUB_EMSDK_VERSION }} + - name: Install Web Prerequisites + shell: bash + run: | + bash ./build/common/get-emscripten.sh + echo "EMSDK=$PWD/emsdk" >> $GITHUB_ENV diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index ca4b3e2a89..42d2af00a9 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -96,6 +96,7 @@ jobs: with: fetch-depth: 0 - uses: ./.github/actions/linux-prereq + - uses: ./.github/actions/web-prereq - name: Run build script run: | cd build/web && printf "y" | ./build.sh presubmit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8ed2148880..d1b2fba3bb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -118,6 +118,7 @@ jobs: with: ref: ${{ steps.git_ref.outputs.ref }} - uses: ./.github/actions/linux-prereq + - uses: ./.github/actions/web-prereq - name: Run build script env: TAG: ${{ steps.git_ref.outputs.tag }} diff --git a/.github/workflows/web-continuous.yml b/.github/workflows/web-continuous.yml index 74aa57de5c..180f1a26f5 100644 --- a/.github/workflows/web-continuous.yml +++ b/.github/workflows/web-continuous.yml @@ -17,6 +17,7 @@ jobs: with: fetch-depth: 0 - uses: ./.github/actions/linux-prereq + - uses: ./.github/actions/web-prereq - name: Run build script run: | cd build/web && printf "y" | ./build.sh continuous diff --git a/BUILDING.md b/BUILDING.md index 167e1736ed..24614ccf46 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -363,6 +363,8 @@ python ./emsdk.py activate latest source ./emsdk_env.sh ``` +Alternatively, you can try running the script `build/common/get-emscripten.sh`. + After this you can invoke the [easy build](#easy-build) script as follows: ```shell diff --git a/build/android/build.sh b/build/android/build.sh index da673271e7..2fab3f833f 100755 --- a/build/android/build.sh +++ b/build/android/build.sh @@ -1,28 +1,6 @@ #!/bin/bash -# Usage: the first argument selects the build type: -# - release, to build release only -# - debug, to build debug only -# - continuous, to build release and debug -# - presubmit, for presubmit builds -# -# The default is release - -echo "This script is intended to run in a CI environment and may modify your current environment." -echo "Please refer to BUILDING.md for more information." - -read -r -p "Do you wish to proceed (y/n)? " choice -case "${choice}" in - y|Y) - echo "Build will proceed..." - ;; - n|N) - exit 0 - ;; - *) - exit 0 - ;; -esac +source `dirname $0`/../common/ci-check.sh set -e set -x @@ -30,11 +8,6 @@ set -x UNAME=`echo $(uname)` LC_UNAME=`echo $UNAME | tr '[:upper:]' '[:lower:]'` -# build-common.sh will generate the following variables: -# $GENERATE_ARCHIVES -# $BUILD_DEBUG -# $BUILD_RELEASE -source `dirname $0`/../common/ci-common.sh source `dirname $0`/../common/build-common.sh if [[ "$GITHUB_WORKFLOW" ]]; then diff --git a/build/common/build-common.sh b/build/common/build-common.sh index 79c2231115..df4094add9 100755 --- a/build/common/build-common.sh +++ b/build/common/build-common.sh @@ -1,5 +1,20 @@ #!/bin/bash +# build-common.sh will generate the following variables: +# $GENERATE_ARCHIVES +# $BUILD_DEBUG +# $BUILD_RELEASE + +# Typically a build script (build.sh) would source this script. For example, +# source `dirname $0`/../common/build-common.sh + +# Usage: the first argument selects the build type: +# - release, to build release only +# - debug, to build debug only +# - continuous, to build release and debug +# - presubmit, for presubmit builds +# +# The default is release if [[ ! "$TARGET" ]]; then if [[ "$1" ]]; then TARGET=$1 diff --git a/build/common/ci-check.sh b/build/common/ci-check.sh new file mode 100644 index 0000000000..022d1523e0 --- /dev/null +++ b/build/common/ci-check.sh @@ -0,0 +1,19 @@ +echo "This script is intended to run in a CI environment and may modify your current environment." +echo "Please refer to BUILDING.md for more information." + +read -r -p "Do you wish to proceed (y/n)? " choice +case "${choice}" in + y|Y) + echo "Build will proceed..." + ;; + n|N) + exit 0 + ;; + *) + exit 0 + ;; +esac + +if [[ "$GITHUB_WORKFLOW" ]]; then + echo "Running workflow $GITHUB_WORKFLOW (event: $GITHUB_EVENT_NAME, action: $GITHUB_ACTION)" +fi diff --git a/build/common/ci-common.sh b/build/common/ci-common.sh deleted file mode 100755 index 2b66ec0375..0000000000 --- a/build/common/ci-common.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -if [[ "$GITHUB_WORKFLOW" ]]; then - echo "Running workflow $GITHUB_WORKFLOW (event: $GITHUB_EVENT_NAME, action: $GITHUB_ACTION)" -fi diff --git a/build/common/get-emscripten.sh b/build/common/get-emscripten.sh new file mode 100755 index 0000000000..ec16d3c144 --- /dev/null +++ b/build/common/get-emscripten.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +if [ -d "./emsdk" ]; then + echo "emsdk folder found. Assume emsdk has been installed." + cd emsdk + ./emsdk activate latest + source ./emsdk_env.sh + export EMSDK="$PWD" + cd .. + exit 0 +fi + +# Install emscripten. +EMSDK_VERSION=${GITHUB_EMSDK_VERSION-3.1.60} +curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/${EMSDK_VERSION}.zip > emsdk.zip +unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk +./emsdk install latest +./emsdk activate latest +source ./emsdk_env.sh + +export EMSDK="$PWD" +cd .. diff --git a/build/common/versions b/build/common/versions index 49749b5231..bc836873e8 100644 --- a/build/common/versions +++ b/build/common/versions @@ -3,4 +3,5 @@ GITHUB_CMAKE_VERSION=3.19.5 GITHUB_NINJA_VERSION=1.10.2 GITHUB_MESA_VERSION=24.2.1 GITHUB_LLVM_VERSION=16 -GITHUB_NDK_VERSION=27.0.11718014 \ No newline at end of file +GITHUB_NDK_VERSION=27.0.11718014 +GITHUB_EMSDK_VERSION=3.1.60 \ No newline at end of file diff --git a/build/ios/build.sh b/build/ios/build.sh index e43ddbb12b..b9940a6ead 100755 --- a/build/ios/build.sh +++ b/build/ios/build.sh @@ -1,35 +1,11 @@ #!/bin/bash -# Usage: the first argument selects the build type: -# - release, to build release only -# - debug, to build debug only -# - continuous, to build release and debug -# - presubmit, for presubmit builds -# -# The default is release - -echo "This script is intended to run in a CI environment and may modify your current environment." -echo "Please refer to BUILDING.md for more information." - -read -r -p "Do you wish to proceed (y/n)? " choice -case "${choice}" in - y|Y) - echo "Build will proceed..." - ;; - n|N) - exit 0 - ;; - *) - exit 0 - ;; -esac +source `dirname $0`/../common/ci-check.sh set -e set -x -source `dirname $0`/../common/ci-common.sh source `dirname $0`/../common/build-common.sh - pushd `dirname $0`/../.. > /dev/null # If we're generating an archive for release or continuous builds, then we'll also build for the diff --git a/build/linux/build.sh b/build/linux/build.sh index 021800ad13..06a64afdde 100755 --- a/build/linux/build.sh +++ b/build/linux/build.sh @@ -1,38 +1,11 @@ #!/bin/bash -# Usage: the first argument selects the build type: -# - release, to build release only -# - debug, to build debug only -# - continuous, to build release and debug -# - presubmit, for presubmit builds -# -# The default is release - -echo "This script is intended to run in a CI environment and may modify your current environment." -echo "Please refer to BUILDING.md for more information." - -read -r -p "Do you wish to proceed (y/n)? " choice -case "${choice}" in - y|Y) - echo "Build will proceed..." - ;; - n|N) - exit 0 - ;; - *) - exit 0 - ;; -esac +source `dirname $0`/../common/ci-check.sh set -e set -x -# build-common.sh will generate the following variables: -# $GENERATE_ARCHIVES -# $BUILD_DEBUG -# $BUILD_RELEASE -source `dirname $0`/../common/ci-common.sh source `dirname $0`/../common/build-common.sh - pushd `dirname $0`/../.. > /dev/null + ./build.sh -c $RUN_TESTS $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE diff --git a/build/mac/build.sh b/build/mac/build.sh index 388316c10d..06a64afdde 100755 --- a/build/mac/build.sh +++ b/build/mac/build.sh @@ -1,34 +1,11 @@ #!/bin/bash -# Usage: the first argument selects the build type: -# - release, to build release only -# - debug, to build debug only -# - continuous, to build release and debug -# - presubmit, for presubmit builds -# -# The default is release - -echo "This script is intended to run in a CI environment and may modify your current environment." -echo "Please refer to BUILDING.md for more information." - -read -r -p "Do you wish to proceed (y/n)? " choice -case "${choice}" in - y|Y) - echo "Build will proceed..." - ;; - n|N) - exit 0 - ;; - *) - exit 0 - ;; -esac +source `dirname $0`/../common/ci-check.sh set -e set -x -source `dirname $0`/../common/ci-common.sh source `dirname $0`/../common/build-common.sh - pushd `dirname $0`/../.. > /dev/null + ./build.sh -c $RUN_TESTS $GENERATE_ARCHIVES $BUILD_DEBUG $BUILD_RELEASE diff --git a/build/web/build.sh b/build/web/build.sh index 624c091d53..dc038b7581 100755 --- a/build/web/build.sh +++ b/build/web/build.sh @@ -1,34 +1,10 @@ #!/bin/bash -# Usage: the first argument selects the build type: -# - release, to build release only -# - debug, to build debug only -# - continuous, to build release and debug -# - presubmit, for presubmit builds -# -# The default is release - -echo "This script is intended to run in a CI environment and may modify your current environment." -echo "Please refer to BUILDING.md for more information." - -read -r -p "Do you wish to proceed (y/n)? " choice -case "${choice}" in - y|Y) - echo "Build will proceed..." - ;; - n|N) - exit 0 - ;; - *) - exit 0 - ;; -esac +source `dirname $0`/../common/ci-check.sh set -e set -x -source `dirname $0`/../common/ci-common.sh -source `dirname $0`/ci-common.sh source `dirname $0`/../common/build-common.sh pushd `dirname $0`/../.. > /dev/null diff --git a/build/web/ci-common.sh b/build/web/ci-common.sh deleted file mode 100755 index 1a5a19a4b1..0000000000 --- a/build/web/ci-common.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# Install emscripten. -curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.60.zip > emsdk.zip -unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk -./emsdk install latest -./emsdk activate latest -source ./emsdk_env.sh - -export EMSDK="$PWD" -cd ..