Skip to content

Commit c0f3a1c

Browse files
committed
Merge pull request #9690
f18b966 build: auto-set GitHub runner make job count (iamamyth)
2 parents 34d3e52 + f18b966 commit c0f3a1c

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'set-make-job-count'
2+
description: 'Set the MAKE_JOB_COUNT environment variable to a value suitable for the host runner'
3+
runs:
4+
using: "composite"
5+
steps:
6+
# Each job runner requires 2.25 GiB (i.e. 1024 * 9/4 MiB) memory and
7+
# a dedicated logical CPU core
8+
- name: set-jobs-macOS
9+
if: runner.os == 'macOS'
10+
run: |
11+
echo MAKE_JOB_COUNT=$(expr $(printf '%s\n%s' $(( $(sysctl -n hw.memsize) * 4 / (1073741824 * 9) )) $(sysctl -n hw.logicalcpu) | sort -n | head -n1) '|' 1) >> $GITHUB_ENV
12+
shell: bash
13+
- name: set-jobs-windows
14+
if: runner.os == 'Windows'
15+
run: |
16+
echo MAKE_JOB_COUNT=$(expr $(printf '%s\n%s' $(( $(grep MemTotal: /proc/meminfo | cut -d: -f2 | cut -dk -f1) * 4 / (1048576 * 9) )) $(nproc) | sort -n | head -n1) '|' 1) >> $GITHUB_ENV
17+
shell: msys2 {0}
18+
- name: set-jobs-linux
19+
if: runner.os == 'Linux'
20+
run: |
21+
echo MAKE_JOB_COUNT=$(expr $(printf '%s\n%s' $(( $(grep MemTotal: /proc/meminfo | cut -d: -f2 | cut -dk -f1) * 4 / (1048576 * 9) )) $(nproc) | sort -n | head -n1) '|' 1) >> $GITHUB_ENV
22+
shell: bash

.github/workflows/build.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ on:
1313
# The below variables reduce repetitions across similar targets
1414
env:
1515
REMOVE_BUNDLED_PACKAGES : sudo rm -rf /usr/local
16-
BUILD_DEFAULT_LINUX: |
17-
cmake -S . -B build -D ARCH="default" -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=Release && cmake --build build --parallel 4
16+
BUILD_DEFAULT_LINUX: 'cmake -S . -B build -D ARCH="default" -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=Release && cmake --build build'
1817
APT_INSTALL_LINUX: 'apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler ccache git'
1918
APT_SET_CONF: |
2019
tee -a /etc/apt/apt.conf.d/80-custom << EOF
@@ -42,14 +41,15 @@ jobs:
4241
path: /Users/runner/Library/Caches/ccache
4342
key: ccache-${{ runner.os }}-build-${{ github.sha }}
4443
restore-keys: ccache-${{ runner.os }}-build-
44+
- uses: ./.github/actions/set-make-job-count
4545
- name: install dependencies
4646
run: |
4747
HOMEBREW_NO_AUTO_UPDATE=1 brew install boost hidapi openssl zmq miniupnpc expat libunwind-headers protobuf@21 ccache
4848
brew link protobuf@21 boost
4949
- name: build
5050
run: |
5151
${{env.CCACHE_SETTINGS}}
52-
make -j3
52+
make -j${{env.MAKE_JOB_COUNT}}
5353
5454
build-windows:
5555
name: 'Windows (MSYS2)'
@@ -73,10 +73,11 @@ jobs:
7373
with:
7474
update: true
7575
install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf mingw-w64-x86_64-libusb mingw-w64-x86_64-unbound git pkg-config
76+
- uses: ./.github/actions/set-make-job-count
7677
- name: build
7778
run: |
7879
${{env.CCACHE_SETTINGS}}
79-
make release-static-win64 -j4
80+
make release-static-win64 -j${{env.MAKE_JOB_COUNT}}
8081
8182
build-arch:
8283
name: 'Arch Linux'
@@ -113,8 +114,9 @@ jobs:
113114
- uses: actions/checkout@v4
114115
with:
115116
submodules: recursive
117+
- uses: ./.github/actions/set-make-job-count
116118
- name: build
117-
run: ${{env.BUILD_DEFAULT_LINUX}}
119+
run: ${{env.BUILD_DEFAULT_LINUX}} --parallel ${{env.MAKE_JOB_COUNT}}
118120

119121
# See the OS labels and monitor deprecations here:
120122
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
@@ -141,6 +143,7 @@ jobs:
141143
path: ~/.ccache
142144
key: ccache-${{ runner.os }}-build-${{ matrix.os }}-${{ github.sha }}
143145
restore-keys: ccache-${{ runner.os }}-build-${{ matrix.os }}
146+
- uses: ./.github/actions/set-make-job-count
144147
- name: remove bundled packages
145148
run: ${{env.REMOVE_BUNDLED_PACKAGES}}
146149
- name: set apt conf
@@ -152,7 +155,7 @@ jobs:
152155
- name: build
153156
run: |
154157
${{env.CCACHE_SETTINGS}}
155-
${{env.BUILD_DEFAULT_LINUX}}
158+
${{env.BUILD_DEFAULT_LINUX}} --parallel ${{env.MAKE_JOB_COUNT}}
156159
157160
libwallet-ubuntu:
158161
name: "Ubuntu 20.04 (libwallet)"
@@ -168,6 +171,7 @@ jobs:
168171
path: ~/.ccache
169172
key: ccache-${{ runner.os }}-libwallet-${{ github.sha }}
170173
restore-keys: ccache-${{ runner.os }}-libwallet-
174+
- uses: ./.github/actions/set-make-job-count
171175
- name: remove bundled packages
172176
run: ${{env.REMOVE_BUNDLED_PACKAGES}}
173177
- name: set apt conf
@@ -180,7 +184,7 @@ jobs:
180184
run: |
181185
${{env.CCACHE_SETTINGS}}
182186
cmake .
183-
make wallet_api -j4
187+
make wallet_api -j${{env.MAKE_JOB_COUNT}}
184188
185189
test-ubuntu:
186190
name: "Ubuntu 20.04 (tests)"
@@ -198,6 +202,7 @@ jobs:
198202
path: ~/.ccache
199203
key: ccache-${{ runner.os }}-build-ubuntu-latest-${{ github.sha }}
200204
restore-keys: ccache-${{ runner.os }}-build-ubuntu-latest
205+
- uses: ./.github/actions/set-make-job-count
201206
- name: remove bundled packages
202207
run: ${{env.REMOVE_BUNDLED_PACKAGES}}
203208
- name: set apt conf
@@ -214,7 +219,7 @@ jobs:
214219
DNS_PUBLIC: tcp://9.9.9.9
215220
run: |
216221
${{env.CCACHE_SETTINGS}}
217-
${{env.BUILD_DEFAULT_LINUX}}
222+
${{env.BUILD_DEFAULT_LINUX}} --parallel ${{env.MAKE_JOB_COUNT}}
218223
cmake --build build --target test
219224
220225
# ARCH="default" (not "native") ensures, that a different execution host can execute binaries compiled elsewhere.

.github/workflows/depends.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ jobs:
7979
restore-keys: |
8080
depends-${{ matrix.toolchain.host }}-${{ hashFiles('contrib/depends/packages/*') }}
8181
depends-${{ matrix.toolchain.host }}-
82+
- uses: ./.github/actions/set-make-job-count
8283
- name: set apt conf
8384
run: ${{env.APT_SET_CONF}}
8485
- name: install dependencies
@@ -91,7 +92,7 @@ jobs:
9192
- name: build
9293
run: |
9394
${{env.CCACHE_SETTINGS}}
94-
make depends target=${{ matrix.toolchain.host }} -j4
95+
make depends target=${{ matrix.toolchain.host }} -j${{env.MAKE_JOB_COUNT}}
9596
- uses: actions/upload-artifact@v4
9697
if: ${{ matrix.toolchain.host == 'x86_64-w64-mingw32' || matrix.toolchain.host == 'x86_64-apple-darwin' || matrix.toolchain.host == 'aarch64-apple-darwin' || matrix.toolchain.host == 'x86_64-unknown-linux-gnu' }}
9798
with:

0 commit comments

Comments
 (0)