Skip to content

Commit

Permalink
build: Replace wasm-pack
Browse files Browse the repository at this point in the history
This is the beginning of PRQL#1836, replacing `wasm-pack` with https://crates.io/crates/substrate-wasm-builder. `wasm-pack` has been the source of lots of issues, makes builds slower -- in particular small code changes cause a very long iteration cycle in playground builds -- and is no longer maintanied.

It's a bit harder than I thought:
- We need to create the paths `bundler`, `node`, `web` paths ourselves, replacing [these lines](https://github.com/PRQL/prql/blob/5db61f45ad31ff5673fdfb7890cc3699d47940f9/bindings/prql-js/package.json#L20-L21), by calling `wasm-bindgen debug/wbuild/prql-js/prql_js.wasm --target=...`.
- We probably need some way of getting the `.wasm` file location, by reading `include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));` for the `WASM_BINARY` or `WASM_BINARY_BLOATY` constants. Ideally we'd do this at build time, all in the `build.rs` script; I'm not sure whether that's possible though.
- Possibly I'm figuring too much of this out on my own and it's done elsewhere? The precedent for this approach seems to be blockchain rather than JS applications...
  • Loading branch information
max-sixty committed Jun 20, 2023
1 parent 762b9ef commit 9d9a840
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 2 deletions.
238 changes: 236 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bindings/prql-js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ console_error_panic_hook = {version = "0.1.7", optional = true}
[dev-dependencies]
wasm-bindgen-test = "0.3.30"

[build-dependencies]
substrate-wasm-builder = "10.0.0"

[package.metadata.cargo-udeps.ignore]
development = ["wasm-bindgen-test"]

Expand Down
13 changes: 13 additions & 0 deletions bindings/prql-js/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
{
substrate_wasm_builder::WasmBuilder::new()
// Tell the builder to build the project (crate) this `build.rs` is part of.
.with_current_project()
// Make sure to export the `heap_base` global, this is required by Substrate
.export_heap_base()
// Build the Wasm file so that it imports the memory (need to be provided by at instantiation)
.import_memory()
// Build it.
.build();
}
}
2 changes: 2 additions & 0 deletions bindings/prql-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::str::FromStr;
use prql_compiler::Target;
use wasm_bindgen::prelude::*;

include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

#[wasm_bindgen]
pub fn compile(prql_query: &str, options: Option<CompileOptions>) -> Option<String> {
return_or_throw(
Expand Down

0 comments on commit 9d9a840

Please sign in to comment.