Skip to content

Commit

Permalink
Redirect $(WASM)/lib/R/bin JS binaries to use native R (#367)
Browse files Browse the repository at this point in the history
* Redirect $(WASM)/lib/R/bin binaries to native R

The binaries built by Emscripten in $(WASM)/lib/R/bin are JavaScript
output, unable to be run directly by the host machine. Such binaries can
be run using Node, but require some further setup (e.g. relocation of
the required `R.wasm` file).

Since these scrips do not work, Makevars targets relying on executing
R code using `$(R_HOME)/bin/R` fail. The `symbols.rds` target in
`lib/share/make/shlib.mk` is an example.

With this commit, these specific scripts are redirected to use the
version of R compiled for the host machine, working around the issue.

* Update NEWS.md
  • Loading branch information
georgestagg authored Feb 28, 2024
1 parent b1ee419 commit b83a88f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

* Fixed spelling errors in some JavaScript errors thrown by webR.

* The `symbols.rds` make target should now work when building R packages using `rwasm` (r-wasm/rwasm#13).

* Rasters with negative width or height are now drawn mirrored or flipped when using the canvas graphics device (#350).

* Include `cex` parameters when calculating font size in canvas graphics device (#348).
Expand Down
2 changes: 1 addition & 1 deletion R/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ MAKE_WASM_BUILD += R_ENABLE_JIT="false"
MAKE_WASM_BUILD += WEBR_HOST_METHODS="$(R_HOST)/lib/R/library/methods"
MAKE_WASM_BUILD += FORTRAN_WASM_LDADD="$(FORTRAN_WASM_LDADD)"

MAKE_WASM_INSTALL := $(MAKE_WASM)
MAKE_WASM_INSTALL := R_HOST="$(R_HOST)" $(MAKE_WASM)

# Build lazy virtual filesystem, backed by XHR when loaded in browsers
WASM_LAZY_VFS := $(WASM_LAZY_VFS)
Expand Down
7 changes: 6 additions & 1 deletion patches/R-4.3.2/emscripten-makefiles.diff
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Index: R-4.3.0/src/main/Makefile.in
===================================================================
--- R-4.3.0.orig/src/main/Makefile.in
+++ R-4.3.0/src/main/Makefile.in
@@ -149,6 +149,51 @@ $(R_binary): $(R_bin_OBJECTS) $(R_bin_DEPENDENCIES)
@@ -149,6 +149,56 @@ $(R_binary): $(R_bin_OBJECTS) $(R_bin_DEPENDENCIES)
$(R_binary): $(R_bin_OBJECTS) $(R_bin_DEPENDENCIES)
$(MAIN_LINK) -o $@ $(R_bin_OBJECTS) $(R_bin_LDADD)

Expand Down Expand Up @@ -68,6 +68,11 @@ Index: R-4.3.0/src/main/Makefile.in
+# Patch Emscripten library to redirect a warning message to console.warn()
+ @sed -i.bak 's/out("LazyFiles/console.warn("LazyFiles/' $(prefix)/dist/$(R_binary).js
+ @rm $(prefix)/dist/$(R_binary).js.bak
+# Redirect $(WASM)/lib R binaries to $(HOST)/lib R binaries
+ @mv $(prefix)/lib/R/bin/R $(prefix)/lib/R/bin/R.orig
+ @mv $(prefix)/lib/R/bin/Rscript $(prefix)/lib/R/bin/Rscript.orig
+ @ln -s $(R_HOST)/lib/R/bin/R $(prefix)/lib/R/bin/R
+ @ln -s $(R_HOST)/lib/R/bin/Rscript $(prefix)/lib/R/bin/Rscript
+
libR.a: $(OBJECTS) $(STATIC_LIBS)
-@mkdir libs
Expand Down

0 comments on commit b83a88f

Please sign in to comment.