Auto-build WASM packages on npm install via prepare hook#304
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks! |
|
While the change itself is okay, it's worth noting that this prepare script used to be there before. It was removed deliberately in commit 2fbde38. We should avoid changing this back and forth repeatedly. AFAIUI there are two setups Spark is trying to accommodate: building/developing the project itself and using a specific commit of Spark as dependency in a project. The former requires the user to build the wasm projects. In this case having it part of the In practice people that wanted to test the latest commits ran into issues because they didn't have a Rust toolchain setup. Arguably this negates the convenience of providing pre-built bundles. |
|
@mrxz that totally makes sense. In that case, we should just revert, and update the README, no? |
|
@dmarcos @mrxz a build system that updated to the latest version hit an issue with this recently - Since we now require rust/rustup to be installed in order to Is there any way you guys can think of that we can improve how we do things to both have pre-builds that are easy to link to, and have developer install+build be simple? I agree with @mrxz that we shouldn't be changing this back and forth, but is the current state the lesser of two evils? What if we improved the README/docs to highlight the need to run build:wasm? What if the Rust packages were pre-built somehow in the repo, is this possible at all? |
The main reason we have pre-built versions in the repo is for people to easily use/test the latest commits. Most people don't have the Rust toolchain setup when they attempt this. From that point of view I'd consider not using the That just leaves us with the challenge of how to improve the developer install+build experience. Updating the README to make this step clearer/explicit is the easiest and might already be enough. On top of that we could look into a mechanism similar to the "no local assets directory" message we show in the |
After cloning the repo and running
npm install, thenpm run buildcommand fails with this error:(fresh clone on osx with cargo 1.94.1 and npm 11.8.0)
The error message suggests a Vite/Rollup config issue, but the real problem is that the
spark-rsandspark-worker-rsWASM packages haven't been built yet. Theirpkg/directories are gitignored (correctly), but nothing in the standard setup flow builds them automatically. You have to know to runnpm run build:wasmfirst, which is only mentioned in the README's build instructions in passing.Fix
This PR sets the
preparescript inpackage.jsontonpm run build:wasm. Thepreparehook runs automatically afternpm install, so the WASM packages are built before anything else needs them. This meansnpm install && npm run buildjust works out of the box for new contributors.The WASM build is only triggered by
npm install— not on everynpm run build— so there's no performance cost during normal development iteration.Verification
rust/spark-rs/pkgandrust/spark-worker-rs/pkgnpm install— verify WASM packages are built automaticallynpm run build— verify it completes successfully