fix(deps): build tree-sitter from source on linux-arm64 / Node ≥22#206
Conversation
tree-sitter@0.21.x ships no linux-arm64 prebuild and tree-sitter-typescript@0.23.x ships a mislabeled (x86-64) one, so on arm64 both must be compiled from source. Under Node >=22 that compile requires C++20, which tree-sitter's binding.gyp doesn't request, so a bare `npm install` hard-fails on arm64. - Move tree-sitter + tree-sitter-typescript to optionalDependencies so the expected arm64 build failure no longer aborts the whole install. - Add scripts/ensure-tree-sitter.mjs, a postinstall heal that compiles the bindings from source with CXXFLAGS=-std=c++20 when the shipped binaries fail to load. It removes the absent/wrong-arch prebuilds and rebuilds via node-gyp-build (build/Release is preferred at load time). No-op where prebuilds work (x64/darwin/CI); non-fatal with no toolchain. - Add `rebuild:native` script as a manual escape hatch.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR introduces an automatic native bindings recovery system for tree-sitter. A new CLI script verifies that tree-sitter and tree-sitter-typescript native modules load correctly, and if they fail to load, it automatically rebuilds them from source with proper C++ toolchain configuration. The script is wired into the npm install and build pipeline via package.json hooks. ChangesNative bindings verification and recovery
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage ReportNo Generated for commit 8c80b0a. |
Problem
A bare
npm installhard-fails on linux-arm64 under Node ≥22:Root cause (verified on this repo's pinned versions):
tree-sitter@0.21.xships nolinux-arm64prebuild → it always compiles from source on arm64.tree-sitter-typescript@0.23.xships alinux-arm64prebuild that is actually a mislabeled x86-64 binary (filereportsx86-64), so it can't bedlopen'd on arm64 → also needs a source build.tree-sitter@0.21'sbinding.gypdoesn't request it → the source compile fails.Bumping out of this isn't possible: the latest
tree-sitter-typescript(0.23.2) peer-pinstree-sitter: ^0.21.0, so core can't move to 0.22+ without orphaning the grammar.Fix
tree-sitter+tree-sitter-typescripttooptionalDependencies— the expected arm64 build failure is then tolerated instead of aborting the whole install, so apostinstallstep can heal it.scripts/ensure-tree-sitter.mjs(wired aspostinstall): if the bindings fail to load, it re-fetches any dropped package, removes the absent/wrong-arch prebuilds, and recompiles from source withCXXFLAGS=-std=c++20.node-gyp-buildloadsbuild/Releaseahead ofprebuilds/, so the freshly compiled aarch64 binary always wins.npm run rebuild:native— manual escape hatch.Testing (linux-arm64, Node 24)
rm -rf node_modules && npm install→ completes (no longer aborts); heal logsOK — bindings compiled from source and loadable..nodefiles verified ARM aarch64;node-gyp-buildresolves tobuild/Release, not the bad prebuild; real TS parse works.Unknown env config "build-from-source"warning.Note (out of scope)
The committed
package-lock.jsonalready has pre-existing drift unrelated to this change —npm cifails onmaintoday withMissing: @emnapi/runtime/Missing: pgunder both npm 10 and npm 11 (the lockfile was written by an older npm). This PR keeps the lockfile delta minimal (only thetree-sitterreclassification) and does not attempt to fix that drift.Summary by CodeRabbit
Release Notes