-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add initial support for wasm target #92
base: main
Are you sure you want to change the base?
Conversation
Hey and thanks for the MR! Please ping me again next week if I haven't reviewed it before then. |
rrule-wasm/src/lib.rs
Outdated
limit: Limit must be set in order to prevent infinite loops | ||
*/ | ||
#[wasm_bindgen] | ||
pub fn get_all_date_recurrences(rule_set_string: &str, limit: Option<u16>) -> Vec<JsValue> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try to mimic the API for the rrule.js library? I think that would make it much simpler for users to swap out rrule.js
for this wasm library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I think it's a good idea
[lib] | ||
#[cfg(feature = "wasm")] | ||
crate-type = ["cdylib", "rlib"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this also contain the default "lib" crate type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. In my tests, it wasn't necessary. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should contain the default "lib" as well. I will need to read up on this setting more before merging this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fmeringdal setting the Cargo.toml file as:
[lib]
crate-type = ["lib", "cdylib", "rlib"]
Once I run cargo build it's showing the below error:
cargo build 101 err took 6s at 06:42:39
Blocking waiting for file lock on build directory
warning: output filename collision.
The lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)` has the same output filename as the lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)`.
Colliding filename is: /Users/douglasmachado/Documents/Rust/Projects/rust-rrule/target/debug/deps/librrule.rlib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)` has the same output filename as the lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)`.
Colliding filename is: /Users/douglasmachado/Documents/Rust/Projects/rust-rrule/target/debug/librrule.rlib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
thread 'main' panicked at 'assertion failed: mtimes.insert(output.clone(), mtime).is_none()', src/cargo/core/compiler/fingerprint/mod.rs:1096:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
How do you recommend to fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it build with just "lib"? Why was "lib" replaced with ["cdylib", "rlib"]. I am not that familiar with how WASM internals work and don't want to merge anything I don't fully understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming in our context the below command as Rust Build:
cargo build
And the below command as Wasm Build:
wasm-pack build --release --target web --features "wasm"
We can analyze the different outputs:
- Using the below config (Cargo.toml file):
[lib]
crate-type = ["lib"]
1.a) the Rust Build works.
1.b) the Wasm Build fails:
Error: crate-type must be cdylib to compile to wasm32-unknown-unknown. Add the following to your Cargo.toml file:
[lib]
crate-type = ["cdylib", "rlib"]
Caused by: crate-type must be cdylib to compile to wasm32-unknown-unknown. Add the following to your Cargo.toml file:
[lib]
crate-type = ["cdylib", "rlib"]
- Using the below config (Cargo.toml file):
[lib]
crate-type = ["lib", "cdylib", "rlib"]
2.a) the Rust Build and Wasm Build command fail and return the same output:
Blocking waiting for file lock on build directory
warning: output filename collision.
The lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)` has the same output filename as the lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)`.
Colliding filename is: /Users/douglasmachado/Documents/Rust/Projects/rust-rrule/target/debug/deps/librrule.rlib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
warning: output filename collision.
The lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)` has the same output filename as the lib target `rrule` in package `rrule v0.10.0 (/Users/douglasmachado/Documents/Rust/Projects/rust-rrule/rrule)`.
Colliding filename is: /Users/douglasmachado/Documents/Rust/Projects/rust-rrule/target/debug/librrule.rlib
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.
thread 'main' panicked at 'assertion failed: mtimes.insert(output.clone(), mtime).is_none()', src/cargo/core/compiler/fingerprint/mod.rs:1096:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
- Using the below config (Cargo.toml file):
[lib]
crate-type = ["cdylib", "rlib"]
3.a) the Rust Build and Wasm Build command build successfully (the current PR is using this config).
I've found two docs that does not answer this type of problem:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context @dgmachado . I think the wasm build is fine, my main concern is the implications of the Rust build and how it might affect applications relying on this library. Before resolving this discussion I will have to do a deeper dive into WASM myself to understand what is going on and why this is required. Sorry for holding up this PR, but I can't merge anything that I don't fully understand as I have to maintain this.
Great work @dgmachado 💪🏻
|
@antoinepairet There are still some pending threads before this can be merged. We still need to nail down the wasm exported API and figure out what crate types the library should use. Regarding NPM registry; I am not sure exactly how this should best be handled, will think about it 👍 |
This is awesome. I was considering replacing rrule.js with the Napi Wrapper because we were running into performance problems with the JS lib. However, a wasm target would be even better. Generally I think there is high demand for this in the JS community as there’s no good alternative to rrule.js right now. Is there anything I can help to get this over the finish line? |
I agree that this is a useful use-case. I am not yet sure wether this should belong and be maintained in this repository. It seems that a separate repository that specifically focuses on an ergonomic JS API + test sute + docs + up to date deps would be preferable. What are your thoughts? |
I now implemented a WASM wrapper to compare it to the Napi Wrapper mentioned above. Unsurprisingly, the Napi wrapper was faster, but I didn't expect it to be that much faster. Here are some initial benchmarks I ran on my M1 Max:
We primarily use rrules in a nodejs environment so the speed gains of using napi are appealing but I'd be happy to push the WASM wrapper to some separate repo. |
Related issue #53