Open jeroen opened 10 months ago
Hey! I came to post this question. I suspect there is something that needs to be modified in libR-sys which provides bindings to R's C API. My understanding is that at build time, the OS is determined and the bindings are matched to the ones provided here.
To get webR to build for extendr / rust packages, I suspect that bindings need to be generated for WASM. I'd be happy to lend a hand to get this working / off the ground. CC @cgmossa.
Do you have an idea where to start looking and poking at?
Let's gooooo!!!!! 🚀
The first error you'll encounter after the xz
problem is probably this, as r-wasm's Docker image doesn't install Rust toolchain (yet?):
/bin/bash: line 1: cargo: command not found
It seems they are preparing the mechanism for customizing the build for webR, but It found no clue other than this:
https://github.com/georgestagg/hellorust-wasm/commit/7383d37ee1c28fc3a86cd941aafc9ac563978c20
This is still very experimental because threading and exceptions don't work properly in wasm.
Thanks for the reminder. For exceptions, I think it's rare that Rust catches C++'s exception because R's API is C, so I think it won't be a big problem, but I might be wrong. For threading, I agree it's a problem that we have to wait for wasm to have the spec.
Note that, I already succeeded to compile a toy package with Rust on my local (because, as I described above, their GitHub Action is not ready for Rust) and confirms it can pass values between R and Rust, and handle Rust errors.
> webr::install("savvyExamples", repos = "https://yutannihilation.github.io/savvy-webr-test/repo")
Downloading webR package: savvyExamples
> savvyExamples::to_upper(1)
Error: Unexpected type: Cannot convert double to string
Unfortunately, it freezes when it tries to return a new R object. It's far from a success, but I believe making compilation success is possible at the moment.
> # this freezes
> savvyExamples::to_upper("a")
Some advice for extendr:
wasm32-unknown-emscripten
. You have to fix build.rs
at least.CARGO_PROFILE_RELEASE_PANIC="abort"
, so this probably breaks extendr's error-handling mechanismHere's what I figured out to compile a Rust-powered R package. Hope this helps.
@jeroen
Sorry to bother you. Could you try updating the r-universe-org/build-wasm
image? The r-wasm/webr
image now has the Rust tool chain installed (https://github.com/r-wasm/webr/pull/358), so some of the Rust packages should work.
Sure I triggered a build, it should be live in 5 min: https://github.com/r-universe-org/build-wasm/actions/runs/7972291810/job/21763748288
Thank you so much! I'll check if my package can compile later.
Confirmed now R-universe can build a Rust-powered R package and it works on webR!! 🎉
Thanks!
Thank you!
Note that, I didn't address the xz
problem in question for simplicity because it's avoidable by not using the vendored tar file conditionally. I hope we can improve the setup gradually. Anyway, I think this is a big step.
The xz
problem should (hopefully) go away once https://github.com/r-wasm/webr/issues/327 has been addressed.
There is an issue right now with
xz
being masked on the path by a js lib: https://github.com/r-universe/r-rust/actions/runs/6832942573