Skip to content

feat: add swap-size parameter for Wasm builds that need more memory#64

Open
georgeharker wants to merge 1 commit into
tree-sitter:mainfrom
georgeharker:add-swap-size-parameter
Open

feat: add swap-size parameter for Wasm builds that need more memory#64
georgeharker wants to merge 1 commit into
tree-sitter:mainfrom
georgeharker:add-swap-size-parameter

Conversation

@georgeharker

Copy link
Copy Markdown

Some grammars (e.g. tree-sitter-zsh) exceed available memory during Wasm compilation on GitHub Actions runners. Currently consumers work around this by maintaining local copies of release.yml and package-npm.yml with a swap resize step injected before the Wasm build — which means tracking upstream changes manually.

This PR adds an optional swap-size input to both workflows:

  • Default: normal — skips the resize entirely; no behaviour change for existing consumers.
  • Set to e.g. 64G — allocates that much swap before the Wasm build step.

Usage

# release.yml
jobs:
  release:
    uses: tree-sitter/workflows/.github/workflows/release.yml@main
    with:
      swap-size: 64G

# publish.yml
jobs:
  npm:
    uses: tree-sitter/workflows/.github/workflows/package-npm.yml@main
    with:
      swap-size: 64G

Changes

  • .github/workflows/release.yml - New swap-size input; conditional "Increase swap space" step before "Build Wasm binaries"
  • .github/workflows/package-npm.yml - Same — swap-size input and conditional swap step in the build_wasm job

Why not just fix the compiler?

This may become unnecessary if upstream changes decrease appetite for memory for wasm compiles. It's also likely that grammar optimization may help. However, this allows folks with issues to keep using the official treesitter workflows rather than having to copy and modify them.

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.

@ObserverOfTime ObserverOfTime left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options should also be added to the readme.

Comment on lines +27 to +32
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
description: Increase the runner swap size for the Wasm build.
default: ""

env:
TREE_SITTER_ABI_VERSION: ${{inputs.abi-version}}
- name: Increase swap space
if: inputs.swap-size != 'normal'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if: inputs.swap-size != 'normal'
if: inputs.swap-size != ''

Comment on lines +17 to +24
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
description: Increase the runner swap size for the Wasm build.
default: ""

env:
TREE_SITTER_ABI_VERSION: ${{inputs.abi-version}}
- name: Increase swap space
if: inputs.swap-size != 'normal'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if: inputs.swap-size != 'normal'
if: inputs.swap-size != ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants