Skip to content

Commit 43d72db

Browse files
committed
build-grpcio: limit resource usage
Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
1 parent 87f4791 commit 43d72db

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

.github/workflows/build-grpcio.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,36 @@ jobs:
3333
runs-on: ubuntu-24.04-riscv
3434
strategy:
3535
fail-fast: false
36+
# grpc's C++ core is the expensive part of this build. Limit it to avoid
37+
# runner resource exhaustion.
38+
max-parallel: 4
3639
matrix:
3740
# grpcio doesn't advertise free-threaded support yet
3841
# (src/python/grpcio/python_version.py lists only 3.10-3.14), so
3942
# 3.14t is dropped from the usual default matrix.
4043
# See also: https://github.com/grpc/grpc/issues/38762
4144
python: ["cp312", "cp313", "cp314"]
4245

46+
env:
47+
CCACHE_DIR: ${{ github.workspace }}/.ccache
48+
CCACHE_BASEDIR: "/project"
49+
CCACHE_COMPILERCHECK: "content"
50+
4351
steps:
4452
- name: Checkout grpc v${{ env.GRPCIO_VERSION }}
4553
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
4654
with:
4755
repository: grpc/grpc
4856
ref: v${{ env.GRPCIO_VERSION }}
4957
submodules: true
58+
fetch-depth: 1 # grpc's submodules (boringssl, abseil, re2, ...) are large; skip history
5059
persist-credentials: false
5160

5261
- name: Checkout python-wheels
5362
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
5463
with:
5564
path: python-wheels
65+
fetch-depth: 1
5666
persist-credentials: false
5767

5868
# install_all_python_modules.sh (run below via CIBW_TEST_COMMAND) would
@@ -61,15 +71,32 @@ jobs:
6171
- name: Patch grpc source
6272
run: git apply python-wheels/patches/grpcio/${{ env.GRPCIO_VERSION }}/00*.patch
6373

74+
# The C++ core is identical across cp312/cp313/cp314; share ccache across
75+
# builds assuming that the package version is the same.
76+
- name: Restore compilation cache
77+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
78+
with:
79+
path: ${{ env.CCACHE_DIR }}
80+
key: ccache-wheels-grpcio-v${{ env.GRPCIO_VERSION }}-manylinux_riscv64-${{ matrix.python }}
81+
restore-keys: |
82+
ccache-wheels-grpcio-v${{ env.GRPCIO_VERSION }}-manylinux_riscv64-
83+
6484
- name: Build wheels
6585
uses: pypa/cibuildwheel@294735312765b09d24a2fbec22660ce817587d55 # v4.1.0
6686
env:
6787
CIBW_BUILD: ${{ matrix.python }}-manylinux_riscv64
6888
CIBW_MANYLINUX_RISCV64_IMAGE: ${{ env.MANYLINUX_RISCV64_IMAGE }}
69-
# Enables grpc's optional systemd socket-activation feature (see
70-
# src/python/grpcio/README.rst); needs libsystemd-devel present.
71-
CIBW_ENVIRONMENT: GRPC_PYTHON_BUILD_WITH_SYSTEMD=1
72-
CIBW_BEFORE_ALL: dnf install -y systemd-devel
89+
CIBW_BEFORE_ALL: |
90+
set -eux
91+
CCACHE_VERSION=4.13.6
92+
curl -fsSL https://github.com/ccache/ccache/releases/download/v${CCACHE_VERSION}/ccache-${CCACHE_VERSION}-linux-$(uname -m)-musl-static.tar.gz | \
93+
tar -xvzf - --strip-components 1 -C /usr/local/bin ccache-${CCACHE_VERSION}-linux-$(uname -m)-musl-static/ccache
94+
ccache --version
95+
ccache --zero-stats
96+
CIBW_ENVIRONMENT_PASS_LINUX: >-
97+
CCACHE_BASEDIR
98+
CCACHE_COMPILERCHECK
99+
CIBW_CONTAINER_ENGINE: "docker; create_args: --volume ${{ env.CCACHE_DIR }}:/root/.ccache"
73100
CIBW_BEFORE_BUILD: pip install -r requirements.txt
74101
CIBW_REPAIR_WHEEL_COMMAND: auditwheel repair --strip -w {dest_dir} {wheel}
75102
CIBW_TEST_REQUIRES: setuptools
@@ -78,6 +105,13 @@ jobs:
78105
PIP_NO_BUILD_ISOLATION=0 ./install_all_python_modules.sh &&
79106
cd {project}/src && python python/grpcio_tests/setup.py test_lite
80107
108+
- name: Save compilation cache
109+
if: always() && github.ref == 'refs/heads/main'
110+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
111+
with:
112+
path: ${{ env.CCACHE_DIR }}
113+
key: ccache-wheels-grpcio-v${{ env.GRPCIO_VERSION }}-manylinux_riscv64-${{ matrix.python }}
114+
81115
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
82116
with:
83117
name: grpcio-${{ env.GRPCIO_VERSION }}-${{ matrix.python }}-manylinux_riscv64

0 commit comments

Comments
 (0)