From 9e2750e836738cdbfcdabbe8c6b0bbd378b0afc9 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Sat, 23 Dec 2023 23:51:10 +0100 Subject: [PATCH] Configures ccache and merges all builds into one PR. Based on https://github.com/kuoruan/libv8/blob/master/.github/workflows/v8-build-test.yml, which might be based on https://joyeecheung.github.io/blog/2021/08/27/binding-v8-on-an-m1-macbook/. --- .github/workflows/v8build.yml | 90 ++++++++++++++++++++++++++++------- deps/build.py | 7 ++- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/.github/workflows/v8build.yml b/.github/workflows/v8build.yml index ef5c2d94..872fd12f 100644 --- a/.github/workflows/v8build.yml +++ b/.github/workflows/v8build.yml @@ -22,31 +22,87 @@ jobs: platform: macos-latest runs-on: ${{ matrix.platform }} steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Restore CCache + uses: actions/cache@v3 with: - submodules: true - fetch-depth: 1 - - name: Update depot_tools fetch config - run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* - shell: bash + path: .ccache + key: ${{ runner.os }}:${{ matrix.os }}:${{ matrix.arch }}:libv8:ccache + restore-keys: | + ${{ runner.os }}:${{ matrix.os }}:${{ matrix.arch }}:libv8:ccache + + - name: Install CCache + if: matrix.platform == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -yq ccache + sudo update-ccache-symlinks + + echo "/usr/lib/ccache" >> "$GITHUB_PATH" + + - name: Install CCache + if: matrix.platform == 'macos-latest' + run: | + brew install ccache + + echo "$(brew --prefix ccache)/libexec" >> "$GITHUB_PATH" + + - name: Configure CCache + run: | + echo "CCACHE_CPP2=yes" >> "$GITHUB_ENV" + echo "CCACHE_SLOPPINESS=time_macros" >> "$GITHUB_ENV" + + ccacheDir="${GITHUB_WORKSPACE}/.ccache" + mkdir -p "$ccacheDir" + + echo "CCACHE_DIR=$ccacheDir" >> "$GITHUB_ENV" + - name: Install g++-aarch64-linux-gnu if: matrix.os == 'linux' && matrix.arch == 'arm64' run: sudo apt update && sudo apt install g++-aarch64-linux-gnu -y + - name: Install setuptools if: matrix.platform == 'macos-latest' run: python3 -m ensurepip --default-pip && python3 -m pip install --upgrade setuptools + + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 1 + + - name: Update depot_tools fetch config + run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* + - name: Build V8 (${{ matrix.os }}) - if: matrix.os == 'linux' - run: cd deps && ./build.py --no-clang --arch ${{ matrix.arch }} --os ${{ matrix.v8os }} - - name: Build V8 (${{ matrix.os }}) - if: matrix.os == 'darwin' || matrix.os == 'android' - run: cd deps && ./build.py --arch ${{ matrix.arch }} --os ${{ matrix.v8os }} + run: cd deps && ./build.py --ccache --arch ${{ matrix.arch }} --os ${{ matrix.v8os }} + + - name: Show CCache Status + run: ccache -s + + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + # The name matches the directory under deps/. + name: ${{ matrix.os }}_${{ matrix.arch }} + if-no-files-found: error + path: deps/${{ matrix.os }}_${{ matrix.arch }}/libv8.a + retention-days: 2 + + commit: + name: Commit Built Artifacts + needs: build + runs-on: ubuntu-latest + steps: + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + path: deps + - name: Create PR uses: peter-evans/create-pull-request@v3 with: - commit-message: Update V8 static library for ${{ matrix.os }} ${{ matrix.arch }} - branch-suffix: random - delete-branch: true - title: V8 static library for ${{ matrix.os }} ${{ matrix.arch }} - body: Auto-generated pull request to build V8 for ${{ matrix.os }} ${{ matrix.arch }} + commit-message: Update compiled V8 libraries + branch-suffix: random + delete-branch: true + title: V8 libraries for all targets + body: Auto-generated pull request of built V8 libraries diff --git a/deps/build.py b/deps/build.py index 1264e3ad..fe8684fe 100755 --- a/deps/build.py +++ b/deps/build.py @@ -12,6 +12,8 @@ parser = argparse.ArgumentParser() parser.add_argument('--debug', dest='debug', action='store_true') +parser.add_argument('--ccache', action='store_true') +parser.add_argument('--clang', dest='clang', action='store_true') parser.add_argument('--no-clang', dest='clang', action='store_false') parser.add_argument('--arch', dest='arch', @@ -24,13 +26,14 @@ dest='os', choices=['android', 'ios', 'linux', 'mac', 'windows'], default=platform.system().lower()) -parser.set_defaults(debug=False, clang=True) +parser.set_defaults(debug=False, ccache=False, clang=None) args = parser.parse_args() deps_path = os.path.dirname(os.path.realpath(__file__)) v8_path = os.path.join(deps_path, "v8") tools_path = os.path.join(deps_path, "depot_tools") is_windows = platform.system().lower() == "windows" +is_clang = args.clang if args.clang is not None else args.os != "linux" def get_custom_deps(): # These deps are unnecessary for building. @@ -143,6 +146,8 @@ def main(): arch = v8_arch() gnargs = gn_args % (is_debug, is_clang, args.os, arch, arch, symbol_level, strip_debug_info) + if args.ccache: + gnargs += 'cc_wrapper = "ccache"\n' gen_args = gnargs.replace('\n', ' ') subprocess.check_call(cmd([gn_path, "gen", build_path, "--args=" + gen_args]),