Skip to content

Commit 5b4cbbf

Browse files
authored
ci(release): add swap and a job cap to the Linux dist wheel builds (#1402)
Linux dist builds of the native crates lost their hosted runner with a shutdown signal while the largest single-unit crates compiled together. Add 16 GB of host swap, which the manylinux container shares, compile at most three crates at a time, and report sampled peak memory and swap use after the build. Other platforms, release-profile builds and the dist profile are unchanged.
1 parent c642221 commit 5b4cbbf

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

‎.github/workflows/build-distributions.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ jobs:
141141
run: |
142142
npm ci
143143
npm run build
144+
# In a Linux dist build the largest single-unit crates compile at the same time and can use
145+
# more memory than the hosted runner has; the runner is then lost without a build error.
146+
# Swap on the host, which the manylinux container shares, absorbs that peak, the builds below
147+
# compile at most three crates at a time, and the sampled memory use is reported afterwards.
148+
- name: Add swap for the Linux dist build
149+
if: inputs.prebuilt-run-id == '' && runner.os == 'Linux' && inputs.cargo-profile == 'dist'
150+
run: |
151+
free -m
152+
avail="$(df -BG --output=avail /mnt 2>/dev/null | tail -n 1 | tr -dc '0-9')"
153+
swap_dir=/mnt
154+
if [[ -z "${avail}" || "${avail}" -lt 24 ]]; then
155+
swap_dir=""
156+
fi
157+
swapfile="${swap_dir}/sqlbuild-dist.swap"
158+
sudo fallocate -l 16G "${swapfile}"
159+
sudo chmod 600 "${swapfile}"
160+
sudo mkswap "${swapfile}" > /dev/null
161+
sudo swapon "${swapfile}"
162+
free -m
163+
( while :; do
164+
free -m | awk '/^Mem:/ { ram = $3 } /^Swap:/ { swap = $3 } END { print ram, swap }'
165+
sleep 5
166+
done ) > "${RUNNER_TEMP}/dist-memory.log" 2>&1 &
144167
# maturin-action downloads maturin from GitHub releases, which can fail on its own. Each
145168
# build retries once; macOS and Windows then fall back to the same maturin from PyPI. Linux
146169
# builds need the action's manylinux container, so they have no fallback.
@@ -154,6 +177,7 @@ jobs:
154177
args: >-
155178
--profile ${{ inputs.cargo-profile }} --out dist --features extension-module
156179
${{ matrix.platform.name == 'linux-x86_64' && '--timings' || '' }}
180+
${{ runner.os == 'Linux' && inputs.cargo-profile == 'dist' && '--jobs 3' || '' }}
157181
target: ${{ matrix.platform.target }}
158182
manylinux: auto
159183
- id: extension-retry
@@ -167,6 +191,7 @@ jobs:
167191
args: >-
168192
--profile ${{ inputs.cargo-profile }} --out dist --features extension-module
169193
${{ matrix.platform.name == 'linux-x86_64' && '--timings' || '' }}
194+
${{ runner.os == 'Linux' && inputs.cargo-profile == 'dist' && '--jobs 3' || '' }}
170195
target: ${{ matrix.platform.target }}
171196
manylinux: auto
172197
- name: Build the extension with maturin from PyPI
@@ -197,6 +222,7 @@ jobs:
197222
args: >-
198223
--profile ${{ inputs.cargo-profile }} --out dist --manifest-path crates/sqlbuild-cli/Cargo.toml --features ui
199224
${{ matrix.platform.name == 'linux-x86_64' && '--timings' || '' }}
225+
${{ runner.os == 'Linux' && inputs.cargo-profile == 'dist' && '--jobs 3' || '' }}
200226
target: ${{ matrix.platform.target }}
201227
manylinux: auto
202228
- id: cli-retry
@@ -214,6 +240,7 @@ jobs:
214240
args: >-
215241
--profile ${{ inputs.cargo-profile }} --out dist --manifest-path crates/sqlbuild-cli/Cargo.toml --features ui
216242
${{ matrix.platform.name == 'linux-x86_64' && '--timings' || '' }}
243+
${{ runner.os == 'Linux' && inputs.cargo-profile == 'dist' && '--jobs 3' || '' }}
217244
target: ${{ matrix.platform.target }}
218245
manylinux: auto
219246
- name: Build sqb with maturin from PyPI
@@ -230,6 +257,16 @@ jobs:
230257
--profile ${{ inputs.cargo-profile }} --out dist --manifest-path crates/sqlbuild-cli/Cargo.toml --features ui
231258
TARGET: ${{ matrix.platform.target }}
232259
run: scripts/maturin_from_pypi.sh build ${MATURIN_ARGS}
260+
- name: Report memory use of the Linux dist build
261+
if: >-
262+
always() && inputs.prebuilt-run-id == '' && runner.os == 'Linux'
263+
&& inputs.cargo-profile == 'dist'
264+
run: |
265+
free -m
266+
grep -E '^pswp(in|out) ' /proc/vmstat
267+
awk '{ if ($1 > ram) ram = $1; if ($2 > swap) swap = $2; if ($1 + $2 > both) both = $1 + $2 }
268+
END { printf "Peak used memory: RAM %d MiB, swap %d MiB, together %d MiB\n", ram, swap, both }' \
269+
"${RUNNER_TEMP}/dist-memory.log" | tee -a "${GITHUB_STEP_SUMMARY}"
233270
- name: Upload the cargo build timing reports
234271
if: inputs.prebuilt-run-id == '' && matrix.platform.name == 'linux-x86_64'
235272
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)