r-wasm / rwasm

Build R packages for WebAssembly and create a CRAN-like repo for distribution.
https://r-wasm.github.io/rwasm/
Other
54 stars 4 forks source link

Install the Rust toolchain and target for wasm #20

Closed yutannihilation closed 7 months ago

yutannihilation commented 7 months ago

I noticed R-universe's wasm build installs rustc and cargo if there's the SystemRequirements.

> rwasm::build('./savvyExamples_0.0.1.tar.gz')

> Will download 1 package with unknown size.
> Will install 2 system packages:
+ cargo  - savvyExamples-deps
+ rustc  - savvyExamples-deps

https://github.com/r-universe/yutannihilation/actions/runs/7848104729/job/21418576850#step:5:324

However, the build fails because the cargo is not the supposed one.

...snip...

    cargo +nightly build --lib --release --manifest-path=./rust/Cargo.toml --target-dir ./rust/target --target wasm32-unknown-emscripten -Zbuild-std=panic_abort,std; \
  fi
error: no such command: `+nightly`

    Cargo does not handle `+toolchain` directives.
    Did you mean to invoke `cargo` through `rustup` instead?
make: *** [Makevars:18: rust/target/wasm32-unknown-emscripten/release/libsimple_savvy.a] Error 101

I'm not sure where this should be handled. Options that I came up with are

deps <- pkgdepends::new_pkg_installation_proposal(".", config = list(sysreqs = TRUE, sysreqs_lookup_system = FALSE))
deps$solve()
any(vapply(deps$get_sysreqs(), \(x) "cargo" %in% names(x), logical(1L)))
georgestagg commented 7 months ago

Thanks for investigating all the available options for us, I appreciate it.

Okay, so after re-reading the thread in r-wasm/actions#13 and this one I think updating the base Docker image is the best way to go. It's not ideal with the size increase, but I think once compressed it's not so bad (details below) and it means it won't have to be constantly reinstalled in GHA runs for rust R packages.

Let's install the required rust and cargo in the r-wasm/webr base Dockerfile. Since you have this working already, would you mind opening a PR there adding the required Docker RUN commands?

``` $ docker manifest inspect ghcr.io/r-wasm/webr | grep size "size": 3558, "size": 30438977, "size": 645927155, "size": 497774382, "size": 32, ``` 3558 + 30438977 + 645927155 + 497774382 + 32 = 1.17GB ``` $ docker manifest inspect ghcr.io/yutannihilation/webr-rust:main | grep size "size": 4960, "size": 30439111, "size": 629569132, "size": 509504104, "size": 32, "size": 209537935, ``` 4960 + 30439111 + 629569132 + 509504104 + 32 + 209537935 = 1.38GB
yutannihilation commented 7 months ago

Wow, thank you! Okay, let me try a pull request. Before that I think, I need a bit more struggle: