From 0857b726cf28ac458f6150aa576f4243975efce1 Mon Sep 17 00:00:00 2001 From: George Harker Date: Mon, 13 Apr 2026 11:49:27 -0700 Subject: [PATCH] feat: add swap-size parameter for Wasm builds that need more memory Some grammars (e.g. tree-sitter-zsh) exceed available memory during Wasm compilation on GitHub Actions runners. Rather than forcing consumers to maintain local copies of these workflows just to insert a swap resize step, expose an optional `swap-size` input on the release and package-npm workflows. The default value `normal` skips the resize entirely, keeping existing behaviour unchanged. Setting it to a size like `64G` allocates that much swap before the Wasm build step. --- .github/workflows/package-npm.yml | 19 +++++++++++++++++++ .github/workflows/release.yml | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/.github/workflows/package-npm.yml b/.github/workflows/package-npm.yml index 29b17d5..4c05915 100644 --- a/.github/workflows/package-npm.yml +++ b/.github/workflows/package-npm.yml @@ -23,6 +23,14 @@ on: description: The tree-sitter ABI version default: 15 type: number + swap-size: + description: > + Resize the runner swap space before the Wasm build. + Set to a size such as "64G" to allocate that much swap, or leave + as "normal" (the default) to skip the resize entirely. + Useful for grammars whose Wasm compilation exceeds available memory. + default: normal + type: string secrets: NODE_AUTH_TOKEN: description: An authentication token for npm @@ -57,6 +65,17 @@ jobs: done < <(jq -r '.grammars[].path // "."' tree-sitter.json) env: TREE_SITTER_ABI_VERSION: ${{inputs.abi-version}} + - name: Increase swap space + if: inputs.swap-size != 'normal' + run: | + sudo swapoff -a + sudo fallocate -l "$SWAP_SIZE" /swapfile + sudo chmod 600 /swapfile + sudo mkswap /swapfile + sudo swapon /swapfile + sudo swapon --show + env: + SWAP_SIZE: ${{inputs.swap-size}} - name: Build Wasm binaries run: |- while read -r grammar_dir; do diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0a7363a..0d4048b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,14 @@ on: description: The tree-sitter ABI version default: 15 type: number + swap-size: + description: > + Resize the runner swap space before the Wasm build. + Set to a size such as "64G" to allocate that much swap, or leave + as "normal" (the default) to skip the resize entirely. + Useful for grammars whose Wasm compilation exceeds available memory. + default: normal + type: string permissions: contents: write @@ -54,6 +62,17 @@ jobs: done < <(jq -r '.grammars[].path // "."' tree-sitter.json) env: TREE_SITTER_ABI_VERSION: ${{inputs.abi-version}} + - name: Increase swap space + if: inputs.swap-size != 'normal' + run: | + sudo swapoff -a + sudo fallocate -l "$SWAP_SIZE" /swapfile + sudo chmod 600 /swapfile + sudo mkswap /swapfile + sudo swapon /swapfile + sudo swapon --show + env: + SWAP_SIZE: ${{inputs.swap-size}} - name: Build Wasm binaries shell: bash run: |-