Skip to content

Add shim for cargo#60

Merged
georgestagg merged 2 commits into
r-wasm:mainfrom
jeroen:cargo-shim
Jun 23, 2026
Merged

Add shim for cargo#60
georgestagg merged 2 commits into
r-wasm:mainfrom
jeroen:cargo-shim

Conversation

@jeroen

@jeroen jeroen commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

I have been testing this for a while on r-universe, and it works well.

We add a shim that makes cargo target wasm32-unknown-emscripten by default. Therefore R packages do not need any special casing to support wasm, they just need to invoke the default toolchains in the same way as they do for CC and CXX, etc.

The only thing that makes this a bit tricky: when cross compiling, cargo writes binaries by default to a subdirectory of the output path. So to make the R packages work without changes as they would for a native build, the shim copies the binaries to one directory up, where they would appear normally.

@jeroen jeroen force-pushed the cargo-shim branch 3 times, most recently from d1eefae to ac00000 Compare June 16, 2026 14:09
@georgestagg

Copy link
Copy Markdown
Member

It's minor, since we control the Docker image, but for native runners can we add a check in the shim that the CARGO_BUILD_TARGET architecture is available and prompt to run rustup target add wasm32-unknown-emscripten if it is not?

@jeroen

jeroen commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

It is a bit tricky because the way to check this depends on how rust was installed. If the system has rustup we could look at rustup target list --installed. But if you installed rust via your OS package manager (brew, apt) it is different. I'm not even sure if there is a way to install additional targets on the latter.

One thing we could do is that if rustup exists, we run the check. Or maybe it would be easier that if rustup exists, we run rustup target add wasm32-unknown-emscripten in the shim (it is a no-op if already installed). This way users don't have to run custom commands or steps when building on e.g. CI.

@georgestagg

Copy link
Copy Markdown
Member

Gotcha. Okay, let's gate it behind existence of rustup. I don't mind if we show a message asking for the target to be added, or we just go ahead and do it -- I'll leave the choice to you.

@georgestagg georgestagg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me!

@georgestagg georgestagg merged commit 9d0130d into r-wasm:main Jun 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants