Skip to content

Commit d1eefae

Browse files
committed
Add shim for cargo
1 parent 48f024a commit d1eefae

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

R/build.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ wasm_build <- function(pkg, tarball_path, contrib_bin, compress) {
161161
webr_profile <- system.file("webr-profile", package = "rwasm")
162162
sys_bin <- system.file("bin", package = "rwasm")
163163
webr_env <- c(
164+
paste0("HOST_CARGO"=, Sys.which('cargo')),
164165
paste0("BUILD_PLATFORM=", R.Version()$platform),
165166
paste0("R_PROFILE_USER=", webr_profile),
166167
paste0("R_MAKEVARS_USER=", webr_vars),

inst/bin/cargo

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
set -e
3+
4+
for arg in "$@"; do
5+
case "$arg" in
6+
"--manifest-path="*)
7+
manifest="${arg:16}"
8+
;;
9+
"--target="*)
10+
target="$arg"
11+
;;
12+
esac
13+
done
14+
15+
# Invoke real cargo
16+
if [ -z "${HOST_CARGO}" ]; then
17+
echo "cargo not found"
18+
exit 1
19+
fi
20+
21+
# Make cargo cross-compile by default. Artifacts then land under target/<triple>/
22+
# instead of target/release where package Makevars expect them, so copy them
23+
# back up after the build.
24+
export CARGO_BUILD_TARGET="wasm32-unknown-emscripten"
25+
echo "Cross compiling for $CARGO_BUILD_TARGET..."
26+
${HOST_CARGO} "$@"
27+
28+
if [ "$1" = "build" ] && [ -z "$target" ]; then
29+
echo "Copying $CARGO_BUILD_TARGET artifacts to target dir"
30+
cd "$(dirname ${manifest:-.})/target"
31+
cp -Rf "$CARGO_BUILD_TARGET"/* . || true
32+
fi

0 commit comments

Comments
 (0)