From 88cc9ef6a66ba46c694a980bac1551d3eb98aa08 Mon Sep 17 00:00:00 2001 From: George Stagg Date: Mon, 11 Nov 2024 14:07:39 +0000 Subject: [PATCH] R 4.4.2 (#498) * Update Dockerfile * Update to R 4.4.2 --- Dockerfile | 10 +- R/Makefile | 253 +++++++++--------- R/R-VERSION | 2 +- packages/Makefile | 3 +- .../R-4.4.1/emscripten-disable-bcEval.diff | 53 ---- .../emscripten-fix-blas-dlsym-search.diff | 21 -- patches/R-4.4.1/emscripten-includes.diff | 15 -- patches/R-4.4.1/emscripten-makefiles.diff | 80 ------ .../emscripten-avoid-testing-issues.diff | 90 +++---- .../emscripten-configure.diff | 15 +- .../emscripten-dataviewer.diff | 6 +- .../emscripten-input.diff | 35 +-- .../emscripten-jumpctxt.diff | 6 +- .../emscripten-lazyload.diff | 60 ++--- .../emscripten-r-home-stderr.diff | 6 +- .../emscripten-sigsuspend.diff} | 6 +- .../emscripten-system.diff} | 16 +- .../emscripten-xhr-download.diff | 6 +- .../fix-sink-release.diff | 6 +- .../flang-avoid-maxloc.diff | 0 .../fontconfig-typeof.diff | 6 +- patches/{R-4.4.1 => R-4.4.2}/series | 14 +- src/tests/packages/webr.test.ts | 12 +- src/webR/emscripten.ts | 2 +- src/webR/webr-worker.ts | 11 +- 25 files changed, 270 insertions(+), 464 deletions(-) delete mode 100644 patches/R-4.4.1/emscripten-disable-bcEval.diff delete mode 100644 patches/R-4.4.1/emscripten-fix-blas-dlsym-search.diff delete mode 100644 patches/R-4.4.1/emscripten-includes.diff delete mode 100644 patches/R-4.4.1/emscripten-makefiles.diff rename patches/{R-4.4.1 => R-4.4.2}/emscripten-avoid-testing-issues.diff (79%) rename patches/{R-4.4.1 => R-4.4.2}/emscripten-configure.diff (89%) rename patches/{R-4.4.1 => R-4.4.2}/emscripten-dataviewer.diff (91%) rename patches/{R-4.4.1 => R-4.4.2}/emscripten-input.diff (63%) rename patches/{R-4.4.1 => R-4.4.2}/emscripten-jumpctxt.diff (74%) rename patches/{R-4.4.1 => R-4.4.2}/emscripten-lazyload.diff (88%) rename patches/{R-4.4.1 => R-4.4.2}/emscripten-r-home-stderr.diff (77%) rename patches/{R-4.4.1/emscripten-unimplmented.diff => R-4.4.2/emscripten-sigsuspend.diff} (82%) rename patches/{R-4.4.1/emscripten-disable-system.diff => R-4.4.2/emscripten-system.diff} (84%) rename patches/{R-4.4.1 => R-4.4.2}/emscripten-xhr-download.diff (99%) rename patches/{R-4.4.1 => R-4.4.2}/fix-sink-release.diff (77%) rename patches/{R-4.4.1 => R-4.4.2}/flang-avoid-maxloc.diff (100%) rename patches/{R-4.4.1 => R-4.4.2}/fontconfig-typeof.diff (80%) rename patches/{R-4.4.1 => R-4.4.2}/series (61%) diff --git a/Dockerfile b/Dockerfile index 501e4ca8..7f30612a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ARG BASE=ghcr.io/r-wasm/flang-wasm:main -FROM $BASE as webr +FROM $BASE AS webr # Setup environment for Emscripten ENV PATH="/opt/emsdk:/opt/emsdk/upstream/emscripten:${PATH}" @@ -12,7 +12,7 @@ ENV EMFC="/opt/flang/host/bin/flang-new" # # Installing this makes sure the toolchain installed in the later step is used # instead of the one that the distro (Ubuntu) provides. -FROM webr as deb_build +FROM webr AS deb_build RUN mkdir /opt/fake_rust/ && \ apt-get update && \ apt-get install -y equivs lsb-release &&\ @@ -25,7 +25,7 @@ RUN mkdir /opt/fake_rust/ && \ mv rustc_99.0_all.deb cargo_99.0_all.deb /opt/fake_rust/ # Step 2: Do the necessary setups -FROM webr as scratch +FROM webr AS webr_scratch # Install nodejs RUN apt-get update && \ apt-get install nodejs npm -y @@ -67,7 +67,7 @@ RUN curl -L https://rig.r-pkg.org/deb/rig.gpg -o /etc/apt/trusted.gpg.d/rig.gpg # Because $HOME gets masked by GHA with the host $HOME ENV R_LIBS_USER=/opt/R/current/lib/R/site-library # Don't install pak. Rig installs it into the user lib, but we want it in the system lib -RUN rig add 4.4.1 --without-pak +RUN rig add 4.4.2 --without-pak # Install pak and rwasm into the system lib RUN /opt/R/current/bin/R -q -e 'install.packages("pak", lib = .Library)' RUN /opt/R/current/bin/R -q -e 'pak::pak("r-wasm/rwasm", lib = .Library)' @@ -99,7 +99,7 @@ RUN sed -i.bak 's|#define TYPEOF|#define FT_TYPEOF|g' /opt/emsdk/upstream/emscri # Step 3: Squash docker image layers FROM webr -COPY --from=scratch / / +COPY --from=webr_scratch / / ENV PATH="/usr/local/cargo/bin:${PATH}" ENV RUSTUP_HOME=/usr/local/rustup ENV CARGO_HOME=/usr/local/cargo diff --git a/R/Makefile b/R/Makefile index fa02973e..861a091a 100644 --- a/R/Makefile +++ b/R/Makefile @@ -8,9 +8,6 @@ TOOLS = $(WEBR_ROOT)/tools HOST = $(WEBR_ROOT)/host WASM = $(WEBR_ROOT)/wasm -# This is symlinked at configure-time -include $(TOOLS)/fortran.mk - R_VERSION = $(shell cat R-VERSION) export R_VERSION @@ -20,35 +17,15 @@ R_URL = https://cran.rstudio.com/src/base/R-4/R-$(R_VERSION).tar.gz R_HOST = $(HOST)/R-$(R_VERSION) R_WASM = $(WASM)/R-$(R_VERSION) +R_WASM_TMP := $(R_WASM)/tmp # Configure your local environment in this file -include ~/.webr-config.mk export WEBR_REPO export WEBR_LIB +NPROCS ?= 1 WASM_OPT ?= -Oz -WASM_OPT_LDADD ?= $(WASM_OPT) -WASM_OPT_LDADD += -s DECLARE_ASM_MODULE_EXPORTS=0 - -WASM_CPPFLAGS := $(WASM_CPPFLAGS) -WASM_CPPFLAGS += -fwasm-exceptions -WASM_CPPFLAGS += -s SUPPORT_LONGJMP=wasm - -WASM_CFLAGS := $(WASM_CFLAGS) -WASM_CFLAGS += $(WASM_OPT) -WASM_CFLAGS += -fPIC - -WASM_FFLAGS := $(WASM_FFLAGS) -WASM_FFLAGS += --target=wasm32-unknown-emscripten -WASM_FFLAGS += -O2 -WASM_FFLAGS += -fPIC - -WASM_LDFLAGS := $(WASM_LDFLAGS) -WASM_LDFLAGS += -fwasm-exceptions -WASM_LDFLAGS += -s SUPPORT_LONGJMP=wasm - -.PHONY: all -all: R .PHONY: R R: $(BUILD)/state/R-$(R_VERSION)/r-stage2 @@ -66,11 +43,11 @@ $(BUILD)/state/R-$(R_VERSION)/r-patched: $(R_TARBALL) mkdir -p $(BUILD)/state/R-$(R_VERSION) touch $@ +# Stage 1: Build a native version of R so we can compile the default packages STAGE1_CC ?= clang STAGE1_CXX ?= clang++ STAGE1_FC ?= gfortran -# Stage 1: Build a native version of R so we can compile the default packages $(BUILD)/state/R-$(R_VERSION)/r-stage1-configured: $(BUILD)/state/R-$(R_VERSION)/r-patched @mkdir -p $(R_SOURCE)/build-stage1/doc # Workaround for the lack of LaTeX packages @@ -80,7 +57,6 @@ $(BUILD)/state/R-$(R_VERSION)/r-stage1-configured: $(BUILD)/state/R-$(R_VERSION) FC="$(STAGE1_FC)" \ CXX="$(STAGE1_CXX)" \ CC="$(STAGE1_CC)" \ - FC="$(STAGE1_FC)" \ CPPFLAGS="$(STAGE1_CPPFLAGS)" \ CFLAGS="$(STAGE1_CFLAGS)" \ LDFLAGS="$(STAGE1_LDFLAGS)" \ @@ -103,26 +79,40 @@ $(BUILD)/state/R-$(R_VERSION)/r-stage1-configured: $(BUILD)/state/R-$(R_VERSION) $(BUILD)/state/R-$(R_VERSION)/r-stage1: $(BUILD)/state/R-$(R_VERSION)/r-stage1-configured cd $(R_SOURCE)/build-stage1 && \ - $(MAKE) R && \ + $(MAKE) -j $(NPROCS) R && \ $(MAKE) install touch $@ +# Stage 2: Reconfigure and build for wasm32-unknown-emscripten target +STAGE2_BUILD = $(R_SOURCE)/build + STAGE2_CPPFLAGS := $(STAGE2_CPPFLAGS) -STAGE2_CPPFLAGS += $(WASM_CPPFLAGS) STAGE2_CPPFLAGS += -I$(WASM)/include -STAGE2_CPPFLAGS += -DEXPEL_OLD_TO_NEW=1 +STAGE2_CPPFLAGS += -s WASM_BIGINT +STAGE2_CPPFLAGS += -fwasm-exceptions +STAGE2_CPPFLAGS += -s SUPPORT_LONGJMP=wasm STAGE2_CPPFLAGS += -s USE_BZIP2=1 STAGE2_CPPFLAGS += -s USE_ZLIB=1 STAGE2_CPPFLAGS += -s USE_FREETYPE=1 STAGE2_CFLAGS := $(STAGE2_CFLAGS) -STAGE2_CFLAGS += $(WASM_CFLAGS) -STAGE2_CFLAGS += $(STAGE2_CPPFLAGS) +STAGE2_CFLAGS += $(WASM_OPT) +STAGE2_CFLAGS += -fPIC STAGE2_LDFLAGS := $(STAGE2_LDFLAGS) -STAGE2_LDFLAGS += $(WASM_LDFLAGS) +STAGE2_LDFLAGS += $(WASM_OPT) STAGE2_LDFLAGS += -L$(WASM)/lib -STAGE2_LDFLAGS +=-s USE_FREETYPE=1 +STAGE2_LDFLAGS += -sWASM_BIGINT +STAGE2_LDFLAGS += -fwasm-exceptions +STAGE2_LDFLAGS += -s SUPPORT_LONGJMP=wasm + +STAGE2_FFLAGS := $(STAGE2_FFLAGS) +STAGE2_FFLAGS += --target=wasm32-unknown-emscripten +STAGE2_FFLAGS += -O2 +STAGE2_FFLAGS += -fPIC + +# This is symlinked at configure-time +include $(TOOLS)/fortran.mk EXPORTED_RUNTIME_METHODS=[$\ 'ENV',$\ @@ -138,23 +128,27 @@ EXPORTED_RUNTIME_METHODS=[$\ 'setValue'$\ ] -MAIN_LDFLAGS = -s MAIN_MODULE=1 -MAIN_LDFLAGS += -s WASM=1 -MAIN_LDFLAGS += -s WASM_BIGINT +MAIN_LDFLAGS := -s MAIN_MODULE=1 MAIN_LDFLAGS += -s ALLOW_MEMORY_GROWTH=1 MAIN_LDFLAGS += -s STACK_SIZE=1MB -MAIN_LDFLAGS += -s EXIT_RUNTIME=1 +MAIN_LDFLAGS += -s DECLARE_ASM_MODULE_EXPORTS=0 MAIN_LDFLAGS += -s ERROR_ON_UNDEFINED_SYMBOLS=0 MAIN_LDFLAGS += -s EXPORTED_RUNTIME_METHODS=$(EXPORTED_RUNTIME_METHODS) MAIN_LDFLAGS += -s FETCH=1 MAIN_LDFLAGS += -lworkerfs.js -lnodefs.js -lidbfs.js -MAIN_LDFLAGS += $(FORTRAN_WASM_LDADD) -MAIN_LDFLAGS += $(WASM_OPT_LDADD) -SHLIB_LDFLAGS = -s SIDE_MODULE=1 -SHLIB_LDFLAGS += -s WASM_BIGINT $(WASM_OPT_LDADD) +MAIN_LDFLAGS_ADD := --embed-file "$(R_WASM_TMP)/lib@/usr/lib" +MAIN_LDFLAGS_ADD += --use-preload-plugins + +ifdef WEBR_REPO +MAIN_LDFLAGS_ADD += --preload-file "${WEBR_REPO}@/repo" +endif +ifdef WEBR_LIB +MAIN_LDFLAGS_ADD += --preload-file "${WEBR_LIB}@/usr/lib/R/library" +endif + +SHLIB_LDFLAGS := -s SIDE_MODULE=1 -# Stage 2: Reconfigure and build for wasm32-unknown-emscripten target $(BUILD)/state/R-$(R_VERSION)/r-stage2-configured: $(BUILD)/state/R-$(R_VERSION)/r-patched $(FORTRAN_WASM_LIB) @mkdir -p $(R_SOURCE)/build @cp $(TOOLS)/shims/pkg-config $(HOST)/bin/pkg-config @@ -169,47 +163,75 @@ $(BUILD)/state/R-$(R_VERSION)/r-stage2-configured: $(BUILD)/state/R-$(R_VERSION) CFLAGS="$(STAGE2_CFLAGS)" \ LDFLAGS="$(STAGE2_LDFLAGS)" \ LIBnn="lib" \ - FFLAGS="$(WASM_FFLAGS)" \ - FPICFLAGS="-fPIC" \ + FFLAGS="$(STAGE2_FFLAGS)" \ + FCLIBS="$(FORTRAN_WASM_LDADD)" \ FC="$(EMFC)" \ emconfigure ../configure \ + ac_cv_have_decl_sigaltstack=no \ + ac_cv_have_decl_wcsftime=no \ + ac_cv_have_decl_getrusage=no \ + ac_cv_have_decl_getrlimit=no \ + ac_cv_have_decl_umask=no \ + r_cv_search_pthread_kill=no \ --prefix="$(R_WASM)" \ --with-x=no \ --with-readline=no \ + --with-libdeflate-compression=no \ --with-static-cairo=yes \ --disable-openmp \ --with-recommended-packages=no \ --enable-R-profiling=no \ --with-pcre2 \ --disable-nls \ - --enable-byte-compiled-packages=no \ --enable-static=yes \ --host=wasm32-unknown-emscripten \ --with-internal-tzcode -# Disable umask which doesn't work well within Emscripten. Fixes -# permission issues when extracting tarballs. - sed -i.bak '/D\["HAVE_UMASK"\]/d' $(R_SOURCE)/build/config.status -# Disable some unsupported features when running under Emscripten - sed -i.bak '/D\["HAVE_WCSFTIME"\]/d' $(R_SOURCE)/build/config.status - sed -i.bak '/D\["HAVE_SIGALTSTACK"\]/d' $(R_SOURCE)/build/config.status - sed -i.bak '/D\["HAVE_GETRUSAGE"\]/d' $(R_SOURCE)/build/config.status - sed -i.bak '/D\["HAVE_GETRLIMIT"\]/d' $(R_SOURCE)/build/config.status - rm $(R_SOURCE)/build/config.status.bak - cd $(R_SOURCE)/build && ./config.status touch $@ -STAGE2_BUILD = $(R_SOURCE)/build - MAKE_WASM := $(MAKE) +MAKE_WASM += MAIN_LDFLAGS="$(MAIN_LDFLAGS) $(MAIN_LDFLAGS_ADD)" MAKE_WASM += R_EXE="$(R_HOST)/bin/R --vanilla --no-echo" +MAKE_WASM += R_INSTALL_LIBRARY="$(STAGE2_BUILD)/library" +MAKE_WASM += R_ENABLE_JIT="false" +MAKE_WASM += WEBR_HOST_METHODS="$(R_HOST)/lib/R/library/methods" + +$(BUILD)/state/R-$(R_VERSION)/r-stage2: $(BUILD)/state/R-$(R_VERSION)/r-stage1 $(BUILD)/state/R-$(R_VERSION)/r-stage2-configured +# Ensure that at least one file exists for embedding at /usr/lib + @mkdir -p "$(R_WASM_TMP)/lib/R/etc" + @touch "$(R_WASM_TMP)/lib/R/etc/Renviron" + cd $(WEBR_ROOT)/packages && \ + $(MAKE_WASM) clean && $(MAKE_WASM) all +# Remove repeated link flags, leads to duplicate symbol error with Emscripten + sed -i.bak -e ':m' -e 's/-lz//2' -e 't m' -e ':n' -e 's/-lpng16//2' -e 't n' \ + $(R_SOURCE)/build/src/library/grDevices/src/cairo/Makefile + rm $(R_SOURCE)/build/src/library/grDevices/src/cairo/Makefile.bak + cd $(STAGE2_BUILD) && $(MAKE_WASM) -j $(NPROCS) R + mkdir -p $(R_SOURCE)/build/doc + cd $(R_SOURCE)/build/doc && touch NEWS.pdf R.1 Rscript.1 + cd $(R_SOURCE)/build && $(MAKE_WASM) -j $(NPROCS) docs + cd $(R_SOURCE)/build && $(MAKE_WASM) install +# Redirect $(WASM)/lib R binaries to $(HOST)/lib R binaries + @mv $(R_WASM)/lib/R/bin/R $(R_WASM)/lib/R/bin/R.orig + @mv $(R_WASM)/lib/R/bin/Rscript $(R_WASM)/lib/R/bin/Rscript.orig + @cp $(R_HOST)/lib/R/bin/R $(R_WASM)/lib/R/bin/R + @cp $(R_HOST)/lib/R/bin/Rscript $(R_WASM)/lib/R/bin/Rscript + @touch $@ -MAKE_WASM_BUILD := $(MAKE_WASM) -MAKE_WASM_BUILD += R_INSTALL_LIBRARY="$(STAGE2_BUILD)/library" -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)" +.PHONY: Rprofile +Rprofile: $(BUILD)/state/R-$(R_VERSION)/r-stage2 + mkdir -p "$(R_WASM)/lib/R/etc/" + echo "options(expressions=400)" > "$(R_WASM)/lib/R/etc/Rprofile.site" + echo "options(bitmapType='cairo')" >> "$(R_WASM)/lib/R/etc/Rprofile.site" -MAKE_WASM_INSTALL := R_HOST="$(R_HOST)" $(MAKE_WASM) +.PHONY: install +install: + @mkdir -p $(DIST) + $(MAKE) vfs + @cp "$(R_SOURCE)/build/src/main/R.wasm" "$(DIST)/R.wasm" + @cat $(R_WASM)/pre.js $(R_SOURCE)/build/src/main/R.bin > $(DIST)/R.bin.js +# Patch Emscripten library to redirect a warning message to console.warn() + @sed -i.bak 's/out("LazyFiles/console.warn("LazyFiles/' $(DIST)/R.bin.js + @rm $(DIST)/R.bin.js.bak # Build lazy virtual filesystem, backed by XHR when loaded in browsers WASM_LAZY_VFS := $(WASM_LAZY_VFS) @@ -230,70 +252,47 @@ WASM_LAZY_VFS += $(foreach pkg,$(PKG_DEFS),$(foreach dir,$(PKG_DIRS),\ # Include extra directories registered by wasm libraries include $(WEBR_ROOT)/libs/recipes/**/targets.mk -export VFSDIR = $(R_WASM)/dist/vfs -export LZFS = $(R_HOST)/bin/Rscript $(TOOLS)/lzfs.R -export WASM_LAZY_VFS - -$(BUILD)/state/R-$(R_VERSION)/r-stage2: $(BUILD)/state/R-$(R_VERSION)/r-stage1 $(BUILD)/state/R-$(R_VERSION)/r-stage2-configured - cd $(WEBR_ROOT)/packages && \ - $(MAKE_WASM) clean && $(MAKE_WASM) all -# Remove repeated link flags, leads to duplicate symbol error with Emscripten - sed -i.bak -e ':m' -e 's/-lz//2' -e 't m' -e ':n' -e 's/-lpng16//2' -e 't n' \ - $(R_SOURCE)/build/src/library/grDevices/src/cairo/Makefile - rm $(R_SOURCE)/build/src/library/grDevices/src/cairo/Makefile.bak - cd $(STAGE2_BUILD) && \ - $(MAKE_WASM_BUILD) R - touch $@ - -.PHONY: Rprofile -Rprofile: $(BUILD)/state/R-$(R_VERSION)/r-stage2 - mkdir -p "$(R_WASM)/lib/R/etc/" - echo "options(expressions=400)" > "$(R_WASM)/lib/R/etc/Rprofile.site" - echo "options(bitmapType='cairo')" >> "$(R_WASM)/lib/R/etc/Rprofile.site" - -.PHONY: install -install: install-tests Rprofile - mkdir -p $(R_SOURCE)/build/doc - cd $(R_SOURCE)/build/doc && touch NEWS.pdf R.1 Rscript.1 - cd $(R_SOURCE)/build && \ - $(MAKE_WASM_INSTALL) install-wasm - cp -r "$(R_WASM)/dist/." $(DIST) -.PHONY: install-tests -install-tests: $(BUILD)/state/R-$(R_VERSION)/r-stage2 - cd $(R_SOURCE)/build && \ - $(MAKE_WASM_BUILD) docs && \ - $(MAKE_WASM_INSTALL) install-tests - -.PHONY: rebuild-extra-pkgs -rebuild-extra-pkgs: $(BUILD)/state/R-$(R_VERSION)/r-stage2 - rm -f $(BUILD)/state/R-$(R_VERSION)/r-stage2 - cd $(WEBR_ROOT)/packages && \ - $(MAKE_WASM) clean && $(MAKE_WASM) all - cd $(STAGE2_BUILD)/src/main && \ - $(MAKE_WASM_INSTALL) install-wasm - cp -r "$(R_WASM)/dist/." $(DIST) - -.PHONY: rebuild-core -rebuild-core: $(BUILD)/state/R-$(R_VERSION)/r-stage2 - rm -f $(BUILD)/state/R-$(R_VERSION)/r-stage2 - cd $(STAGE2_BUILD)/src/unix && \ - $(MAKE_WASM_BUILD) - cd $(STAGE2_BUILD)/src/main && \ - $(MAKE_WASM_BUILD) R && \ - $(MAKE_WASM_INSTALL) install-wasm - cp -r "$(R_WASM)/dist/." $(DIST) - -.PHONY: rebuild-modules -rebuild-modules: $(BUILD)/state/R-$(R_VERSION)/r-stage2 - rm -f $(BUILD)/state/R-$(R_VERSION)/r-stage2 - cd $(STAGE2_BUILD)/src/modules && \ - $(MAKE_WASM_BUILD) && \ - $(MAKE_WASM_BUILD) install - cd $(STAGE2_BUILD)/src/main && \ - $(MAKE_WASM_BUILD) R && \ - $(MAKE_WASM_INSTALL) install-wasm - cp -r "$(R_WASM)/dist/." $(DIST) +.PHONY: vfs +vfs: Rprofile + @rm -rf "$(R_WASM_TMP)" && mkdir -p "$(R_WASM_TMP)/lib/R/" + @cp -a "$(R_WASM)/lib/R/library" "$(R_WASM_TMP)/lib/R/" + @cp -a "$(R_WASM)/lib/R/etc" "$(R_WASM_TMP)/lib/R/" + @cp -a "$(R_WASM)/lib/R/modules" "$(R_WASM_TMP)/lib/R/" + @rm -r "$(R_WASM_TMP)/lib/R/library/translations" + @rm -r "$(R_WASM_TMP)/lib/R/library/tcltk" + @rm -r "$(R_WASM_TMP)/lib/R/library/parallel" + @rm -rf "$(R_WASM_TMP)/lib/R/library/grDevices/libs/cairo.so" + @find "$(R_WASM_TMP)/lib/R" -type d -name 'afm' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'demo' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'enc' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'doc' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'fonts' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'help' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'html' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'misc' -exec rm -r "{}" + + @find "$(R_WASM_TMP)/lib/R" -type d -name 'tests' -exec rm -r "{}" + + @cp "$(R_WASM)/lib/R/lib/libRblas.so" "$(DIST)/libRblas.so" + @cp "$(R_WASM)/lib/R/lib/libRlapack.so" "$(DIST)/libRlapack.so" + @echo "Building lazy virtual filesystem:" + $(R_HOST)/bin/Rscript $(TOOLS)/lzfs.R -v -d $(DIST)/vfs -u vfs \ + $(WASM_LAZY_VFS) -o $(R_WASM)/pre.js + @echo "Embedding base virtual filesystem:" + @rm -f "$(R_SOURCE)/build/src/main/R.bin" + cd $(STAGE2_BUILD)/src/main && $(MAKE_WASM) R + +.PHONY: rebuild-extra-pkgs rebuild-core rebuild-modules +rebuild-extra-pkgs: + $(MAKE) R + $(MAKE) install + +rebuild-core: + cd $(STAGE2_BUILD)/src/unix && $(MAKE_WASM) + $(MAKE) install + +rebuild-modules: + cd $(STAGE2_BUILD)/src/modules && $(MAKE_WASM) + $(MAKE) install .PHONY: clean clean: diff --git a/R/R-VERSION b/R/R-VERSION index cca25a93..1d068c6e 100644 --- a/R/R-VERSION +++ b/R/R-VERSION @@ -1 +1 @@ -4.4.1 +4.4.2 diff --git a/packages/Makefile b/packages/Makefile index 2177e568..fab60b6f 100644 --- a/packages/Makefile +++ b/packages/Makefile @@ -27,8 +27,7 @@ $(R_WASM_LIB)/%: $(PKG_SRCS) $(R_HOST_EXE) CMD INSTALL --library="$(R_WASM_LIB)" $(notdir $@) \ --no-docs \ --no-test-load \ - --no-staged-install \ - --no-byte-compile + --no-staged-install clean: rm -rf $(PKG_PATHS) diff --git a/patches/R-4.4.1/emscripten-disable-bcEval.diff b/patches/R-4.4.1/emscripten-disable-bcEval.diff deleted file mode 100644 index 9d27c6d3..00000000 --- a/patches/R-4.4.1/emscripten-disable-bcEval.diff +++ /dev/null @@ -1,53 +0,0 @@ -Index: R-4.4.0/src/main/eval.c -=================================================================== ---- R-4.4.0.orig/src/main/eval.c -+++ R-4.4.0/src/main/eval.c -@@ -2350,6 +2350,7 @@ static R_INLINE SEXP R_execClosure(SEXP call, SEXP new - begincontext(&cntxt, CTXT_RETURN, call, newrho, sysparent, arglist, op); - - body = BODY(op); -+ #ifndef __EMSCRIPTEN__ - if (R_CheckJIT(op)) { - int old_enabled = R_jit_enabled; - R_jit_enabled = 0; -@@ -2357,6 +2358,7 @@ static R_INLINE SEXP R_execClosure(SEXP call, SEXP new - body = BODY(op); - R_jit_enabled = old_enabled; - } -+ #endif - - /* Get the srcref record from the closure object. The old srcref was - saved in cntxt. */ -@@ -4555,6 +4557,10 @@ static SEXP R_ConstantsRegistry = NULL; - instead of a weak reference, stays in the list forever, and is a GC root.*/ - static SEXP R_ConstantsRegistry = NULL; - -+#ifdef __EMSCRIPTEN__ -+#define NO_THREADED_CODE -+#endif -+ - #if defined(__GNUC__) && ! defined(BC_PROFILING) && (! defined(NO_THREADED_CODE)) - # define THREADED_CODE - #endif -@@ -7504,6 +7510,13 @@ static SEXP bcEval_loop(struct bcEval_locals *); - ! RSTEP(fun) && ! RDEBUG(rho) && \ - R_GlobalContext->callflag != CTXT_GENERIC) - -+#ifdef __EMSCRIPTEN__ -+/* Disable bytecode machine, significantly reduces Wasm binary size */ -+static inline SEXP bcEval(SEXP body, SEXP rho) -+{ -+ return eval(bytecodeExpr(body), rho); -+} -+#else - static SEXP bcEval_loop(struct bcEval_locals *); - - static SEXP bcEval(SEXP body, SEXP rho) -@@ -8723,6 +8736,7 @@ static SEXP bcEval_loop(struct bcEval_locals *ploc) - LASTOP; - } - } -+#endif - - #ifdef THREADED_CODE - static void bcEval_init(void) { diff --git a/patches/R-4.4.1/emscripten-fix-blas-dlsym-search.diff b/patches/R-4.4.1/emscripten-fix-blas-dlsym-search.diff deleted file mode 100644 index 83035c3b..00000000 --- a/patches/R-4.4.1/emscripten-fix-blas-dlsym-search.diff +++ /dev/null @@ -1,21 +0,0 @@ -Index: R-4.4.0/src/main/platform.c -=================================================================== ---- R-4.4.0.orig/src/main/platform.c -+++ R-4.4.0/src/main/platform.c -@@ -3675,11 +3675,16 @@ do_eSoftVersion(SEXP call, SEXP op, SEXP args, SEXP rh - and heuristics, and depends on implementation details - of dynamic linkers. - */ -+ -+#ifdef __EMSCRIPTEN__ -+ char *dgemm_name = "_dgemm_"; -+#else - #ifdef HAVE_F77_UNDERSCORE - char *dgemm_name = "dgemm_"; - #else - char *dgemm_name = "dgemm"; - #endif -+#endif - - Rboolean ok = TRUE; - diff --git a/patches/R-4.4.1/emscripten-includes.diff b/patches/R-4.4.1/emscripten-includes.diff deleted file mode 100644 index fe09d73e..00000000 --- a/patches/R-4.4.1/emscripten-includes.diff +++ /dev/null @@ -1,15 +0,0 @@ -Index: R-4.4.0/src/unix/sys-std.c -=================================================================== ---- R-4.4.0.orig/src/unix/sys-std.c -+++ R-4.4.0/src/unix/sys-std.c -@@ -57,6 +57,10 @@ - - #ifdef HAVE_UNISTD_H - # include /* for unlink */ -+#endif -+ -+#ifdef __EMSCRIPTEN__ -+#include /* for isspace */ - #endif - - extern SA_TYPE SaveAction; diff --git a/patches/R-4.4.1/emscripten-makefiles.diff b/patches/R-4.4.1/emscripten-makefiles.diff deleted file mode 100644 index 4ed71270..00000000 --- a/patches/R-4.4.1/emscripten-makefiles.diff +++ /dev/null @@ -1,80 +0,0 @@ -Index: R-4.4.0/Makefile.in -=================================================================== ---- R-4.4.0.orig/Makefile.in -+++ R-4.4.0/Makefile.in -@@ -91,6 +91,13 @@ javaconf: R - javaconf: R - @$(MAKE) stamp-java - -+install-wasm: -+ @mkdir -p "$(prefix)/lib/R/doc/html" -+ @for d in $(SUBDIRS); do \ -+ (cd $${d} && $(MAKE) install) \ -+ done -+ -@(cd share && $(MAKE) install-zoneinfo) -+ -@(cd src/main && $(MAKE) $@) - - install install-strip: installdirs svnonly - @for d in $(SUBDIRS); do \ -Index: R-4.4.0/src/main/Makefile.in -=================================================================== ---- R-4.4.0.orig/src/main/Makefile.in -+++ R-4.4.0/src/main/Makefile.in -@@ -148,7 +148,57 @@ $(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) -+ -+MAIN_WEBR_LDADD = --use-preload-plugins -+MAIN_WEBR_LDADD += --embed-file "$(prefix)/tmp/lib@/usr/lib" -+MAIN_WEBR_LDADD += --extern-pre-js $(prefix)/pre.js -+ -+ifdef WEBR_REPO -+MAIN_WEBR_LDADD += --preload-file "$(WEBR_REPO)@/repo" -+endif -+ -+ifdef WEBR_LIB -+MAIN_WEBR_LDADD += --preload-file "${WEBR_LIB}@/usr/lib/R/library" -+endif -+ -+$(R_binary).js: $(R_bin_OBJECTS) $(R_bin_DEPENDENCIES) -+ @rm -rf "$(prefix)/tmp" && mkdir -p "$(prefix)/tmp/lib/R/" -+ @cp -a "$(prefix)/lib/R/library" "$(prefix)/tmp/lib/R/" -+ @cp -a "$(prefix)/lib/R/etc" "$(prefix)/tmp/lib/R/" -+ @cp -a "$(prefix)/lib/R/modules" "$(prefix)/tmp/lib/R/" -+ @rm -r "$(prefix)/tmp/lib/R/library/translations" -+ @rm -r "$(prefix)/tmp/lib/R/library/tcltk" -+ @rm -r "$(prefix)/tmp/lib/R/library/parallel" -+ @rm -rf "$(prefix)/tmp/lib/R/library/grDevices/libs/cairo.so" -+ @find "$(prefix)/tmp/lib/R" -type d -name 'afm' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'demo' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'enc' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'doc' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'fonts' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'help' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'html' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'misc' -exec rm -r "{}" + -+ @find "$(prefix)/tmp/lib/R" -type d -name 'tests' -exec rm -r "{}" + -+ $(MAIN_LINK) $(MAIN_WEBR_LDADD) \ -+ -o $(prefix)/dist/$(R_binary).js \ -+ $(R_bin_OBJECTS) -lRlapack $(FORTRAN_WASM_LDADD) $(R_bin_LDADD) - -+install-wasm: $(R_bin_DEPENDENCIES) -+ @$(MKINSTALLDIRS) "$(prefix)/dist" -+ @cp "$(Rexeclibdir)/libRblas.so" "$(prefix)/dist/libRblas.so" -+ @cp "$(Rexeclibdir)/libRlapack.so" "$(prefix)/dist/libRlapack.so" -+ @echo "Building virtual filesystem:" -+ @$(LZFS) -v -d $(VFSDIR) -u vfs $(WASM_LAZY_VFS) -o $(prefix)/pre.js -+ @$(MAKE) $(R_binary).js -+# 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 - @(cd libs; for l in $(STATIC_LIBS); do $(AR) -x ../$$l; done) diff --git a/patches/R-4.4.1/emscripten-avoid-testing-issues.diff b/patches/R-4.4.2/emscripten-avoid-testing-issues.diff similarity index 79% rename from patches/R-4.4.1/emscripten-avoid-testing-issues.diff rename to patches/R-4.4.2/emscripten-avoid-testing-issues.diff index 408ad0c8..fd098366 100644 --- a/patches/R-4.4.1/emscripten-avoid-testing-issues.diff +++ b/patches/R-4.4.2/emscripten-avoid-testing-issues.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/library/base/man/stopifnot.Rd +Index: R-4.4.2/src/library/base/man/stopifnot.Rd =================================================================== ---- R-4.4.0.orig/src/library/base/man/stopifnot.Rd -+++ R-4.4.0/src/library/base/man/stopifnot.Rd +--- R-4.4.2.orig/src/library/base/man/stopifnot.Rd ++++ R-4.4.2/src/library/base/man/stopifnot.Rd @@ -138,6 +138,7 @@ warnifnot <- stopifnot ; N <- length(bdy <- body(warni ##' warnifnot(): a "only-warning" version of stopifnot() @@ -18,10 +18,10 @@ Index: R-4.4.0/src/library/base/man/stopifnot.Rd \keyword{environment} \keyword{programming} \keyword{error} -Index: R-4.4.0/src/library/base/man/validUTF8.Rd +Index: R-4.4.2/src/library/base/man/validUTF8.Rd =================================================================== ---- R-4.4.0.orig/src/library/base/man/validUTF8.Rd -+++ R-4.4.0/src/library/base/man/validUTF8.Rd +--- R-4.4.2.orig/src/library/base/man/validUTF8.Rd ++++ R-4.4.2/src/library/base/man/validUTF8.Rd @@ -60,6 +60,7 @@ validEnc(x) # typically the last, x[10], is invalid Encoding(x) <-"UTF-8" validEnc(x) # typically the last, x[10], is invalid @@ -35,10 +35,10 @@ Index: R-4.4.0/src/library/base/man/validUTF8.Rd validEnc(G)) # typically TRUE } +} -Index: R-4.4.0/src/library/base/man/warnings.Rd +Index: R-4.4.2/src/library/base/man/warnings.Rd =================================================================== ---- R-4.4.0.orig/src/library/base/man/warnings.Rd -+++ R-4.4.0/src/library/base/man/warnings.Rd +--- R-4.4.2.orig/src/library/base/man/warnings.Rd ++++ R-4.4.2/src/library/base/man/warnings.Rd @@ -93,7 +93,7 @@ summary(warnings()) ## Often the most useful way to look at many warnings: @@ -48,10 +48,10 @@ Index: R-4.4.0/src/library/base/man/warnings.Rd ww <- warnings() uw <- unique(ww) sw <- summary(ww) -Index: R-4.4.0/src/library/utils/man/news.Rd +Index: R-4.4.2/src/library/utils/man/news.Rd =================================================================== ---- R-4.4.0.orig/src/library/utils/man/news.Rd -+++ R-4.4.0/src/library/utils/man/news.Rd +--- R-4.4.2.orig/src/library/utils/man/news.Rd ++++ R-4.4.2/src/library/utils/man/news.Rd @@ -138,6 +138,7 @@ news(query, package = "R", lib.loc = NULL, format = NU } @@ -65,10 +65,10 @@ Index: R-4.4.0/src/library/utils/man/news.Rd } } +} -Index: R-4.4.0/src/library/utils/tests/Sweave-tst.R +Index: R-4.4.2/src/library/utils/tests/Sweave-tst.R =================================================================== ---- R-4.4.0.orig/src/library/utils/tests/Sweave-tst.R -+++ R-4.4.0/src/library/utils/tests/Sweave-tst.R +--- R-4.4.2.orig/src/library/utils/tests/Sweave-tst.R ++++ R-4.4.2/src/library/utils/tests/Sweave-tst.R @@ -15,7 +15,7 @@ # https://www.R-project.org/Licenses/ @@ -83,10 +83,10 @@ Index: R-4.4.0/src/library/utils/tests/Sweave-tst.R cat('Time elapsed: ', proc.time() - .proctime00,'\n') +} -Index: R-4.4.0/src/library/methods/tests/envRefClass.R +Index: R-4.4.2/src/library/methods/tests/envRefClass.R =================================================================== ---- R-4.4.0.orig/src/library/methods/tests/envRefClass.R -+++ R-4.4.0/src/library/methods/tests/envRefClass.R +--- R-4.4.2.orig/src/library/methods/tests/envRefClass.R ++++ R-4.4.2/src/library/methods/tests/envRefClass.R @@ -4,7 +4,7 @@ rp ## show() failed .. rc <- getClass("refClass") rp <- rc@prototype @@ -96,10 +96,10 @@ Index: R-4.4.0/src/library/methods/tests/envRefClass.R (ner <- new("envRefClass")) # show() failed stopifnot(all.equal(rp,rp), all.equal(ner,ner)) be <- baseenv() -Index: R-4.4.0/src/library/methods/tests/nextWithDots.R +Index: R-4.4.2/src/library/methods/tests/nextWithDots.R =================================================================== ---- R-4.4.0.orig/src/library/methods/tests/nextWithDots.R -+++ R-4.4.0/src/library/methods/tests/nextWithDots.R +--- R-4.4.2.orig/src/library/methods/tests/nextWithDots.R ++++ R-4.4.2/src/library/methods/tests/nextWithDots.R @@ -1,9 +1,10 @@ setClass("A") -setClass("B", contains = c("array", "A")) @@ -122,10 +122,10 @@ Index: R-4.4.0/src/library/methods/tests/nextWithDots.R +removeClass("C"); removeClass("BB"); removeClass("A") removeGeneric("withDots") rm(a, bb, a2) -Index: R-4.4.0/src/library/compiler/tests/basics.R +Index: R-4.4.2/src/library/compiler/tests/basics.R =================================================================== ---- R-4.4.0.orig/src/library/compiler/tests/basics.R -+++ R-4.4.0/src/library/compiler/tests/basics.R +--- R-4.4.2.orig/src/library/compiler/tests/basics.R ++++ R-4.4.2/src/library/compiler/tests/basics.R @@ -90,7 +90,7 @@ stopifnot(identical(p, pp)) h <- ls(compiler:::inlineHandlers, all.names = TRUE) p <- sub("package:", "", sapply(h, find)) @@ -135,10 +135,10 @@ Index: R-4.4.0/src/library/compiler/tests/basics.R ## Check assumption about simple .Internals -Index: R-4.4.0/src/library/grDevices/tests/saved-recordPlot.R +Index: R-4.4.2/src/library/grDevices/tests/saved-recordPlot.R =================================================================== ---- R-4.4.0.orig/src/library/grDevices/tests/saved-recordPlot.R -+++ R-4.4.0/src/library/grDevices/tests/saved-recordPlot.R +--- R-4.4.2.orig/src/library/grDevices/tests/saved-recordPlot.R ++++ R-4.4.2/src/library/grDevices/tests/saved-recordPlot.R @@ -3,6 +3,7 @@ ## Subject: [Rd] recordPlot/replayPlot not working with saveRDS/readRDS ## Date: Mon, 2 Apr 2018 12:23:06 -0500 @@ -152,10 +152,10 @@ Index: R-4.4.0/src/library/grDevices/tests/saved-recordPlot.R identical(tt[[1]], tt[[2]]), identical(tt[[3]], tt[[2]])) +} -Index: R-4.4.0/src/library/grDevices/tests/encodings.R +Index: R-4.4.2/src/library/grDevices/tests/encodings.R =================================================================== ---- R-4.4.0.orig/src/library/grDevices/tests/encodings.R -+++ R-4.4.0/src/library/grDevices/tests/encodings.R +--- R-4.4.2.orig/src/library/grDevices/tests/encodings.R ++++ R-4.4.2/src/library/grDevices/tests/encodings.R @@ -12,6 +12,7 @@ musl <- grepl("musl", R.version$os) q("no") } @@ -192,10 +192,10 @@ Index: R-4.4.0/src/library/grDevices/tests/encodings.R #} ## Now with --as-cran settings in recent R, only. -Index: R-4.4.0/src/library/grDevices/tests/encodings2.R +Index: R-4.4.2/src/library/grDevices/tests/encodings2.R =================================================================== ---- R-4.4.0.orig/src/library/grDevices/tests/encodings2.R -+++ R-4.4.0/src/library/grDevices/tests/encodings2.R +--- R-4.4.2.orig/src/library/grDevices/tests/encodings2.R ++++ R-4.4.2/src/library/grDevices/tests/encodings2.R @@ -15,11 +15,12 @@ pdfenc <- c("ISOLatin1", "ISOLatin2", "ISOLatin7", "IS q("no") } @@ -226,10 +226,10 @@ Index: R-4.4.0/src/library/grDevices/tests/encodings2.R } dev.off() +} -Index: R-4.4.0/src/library/grDevices/tests/urw-fonts.R +Index: R-4.4.2/src/library/grDevices/tests/urw-fonts.R =================================================================== ---- R-4.4.0.orig/src/library/grDevices/tests/urw-fonts.R -+++ R-4.4.0/src/library/grDevices/tests/urw-fonts.R +--- R-4.4.2.orig/src/library/grDevices/tests/urw-fonts.R ++++ R-4.4.2/src/library/grDevices/tests/urw-fonts.R @@ -59,7 +59,8 @@ for(i in seq_along(pdfenc)) { try(do_one(pdfenc[i], enc[i], i >= 7)) dev.off() @@ -250,10 +250,10 @@ Index: R-4.4.0/src/library/grDevices/tests/urw-fonts.R unlink(f) } } -Index: R-4.4.0/src/library/grDevices/tests/zzcheck-encodings.R +Index: R-4.4.2/src/library/grDevices/tests/zzcheck-encodings.R =================================================================== ---- R-4.4.0.orig/src/library/grDevices/tests/zzcheck-encodings.R -+++ R-4.4.0/src/library/grDevices/tests/zzcheck-encodings.R +--- R-4.4.2.orig/src/library/grDevices/tests/zzcheck-encodings.R ++++ R-4.4.2/src/library/grDevices/tests/zzcheck-encodings.R @@ -1,5 +1,8 @@ ### Optonally compare encodings results with the ref directories @@ -268,10 +268,10 @@ Index: R-4.4.0/src/library/grDevices/tests/zzcheck-encodings.R if(cnt) stop("Differences found") +} -Index: R-4.4.0/src/library/base/man/source.Rd +Index: R-4.4.2/src/library/base/man/source.Rd =================================================================== ---- R-4.4.0.orig/src/library/base/man/source.Rd -+++ R-4.4.0/src/library/base/man/source.Rd +--- R-4.4.2.orig/src/library/base/man/source.Rd ++++ R-4.4.2/src/library/base/man/source.Rd @@ -213,6 +213,9 @@ withAutoprint({ formals(sourceDir); body(sourceDir) }, max.deparse.length = 20, verbose = TRUE) %% --> tests in ../../../../tests/eval-etc.R @@ -290,10 +290,10 @@ Index: R-4.4.0/src/library/base/man/source.Rd \keyword{file} \keyword{programming} \keyword{connection} -Index: R-4.4.0/src/library/grDevices/tests/encodings3.R +Index: R-4.4.2/src/library/grDevices/tests/encodings3.R =================================================================== ---- R-4.4.0.orig/src/library/grDevices/tests/encodings3.R -+++ R-4.4.0/src/library/grDevices/tests/encodings3.R +--- R-4.4.2.orig/src/library/grDevices/tests/encodings3.R ++++ R-4.4.2/src/library/grDevices/tests/encodings3.R @@ -50,6 +50,9 @@ if(!capabilities("cairo")) q("no") text(0.5+seq_along(four), 4, four) dev.off() diff --git a/patches/R-4.4.1/emscripten-configure.diff b/patches/R-4.4.2/emscripten-configure.diff similarity index 89% rename from patches/R-4.4.1/emscripten-configure.diff rename to patches/R-4.4.2/emscripten-configure.diff index c91edf35..d828ebc1 100644 --- a/patches/R-4.4.1/emscripten-configure.diff +++ b/patches/R-4.4.2/emscripten-configure.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/configure +Index: R-4.4.2/configure =================================================================== ---- R-4.4.0.orig/configure -+++ R-4.4.0/configure +--- R-4.4.2.orig/configure ++++ R-4.4.2/configure @@ -15089,7 +15089,7 @@ _LT_EOF archive_expsym_cmds='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; @@ -56,15 +56,6 @@ Index: R-4.4.0/configure version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no -@@ -43517,7 +43517,7 @@ case "${host_os}" in - ## flags to all (C, C++ and Fortran) compiler flags. - - case "${host_os}" in -- mingw*|windows*|winnt|msys) -+ mingw*|windows*|winnt|msys|emscripten*) - ;; - *) - r_save_CFLAGS=${CFLAGS} @@ -53146,6 +53146,11 @@ fi ## libcurl diff --git a/patches/R-4.4.1/emscripten-dataviewer.diff b/patches/R-4.4.2/emscripten-dataviewer.diff similarity index 91% rename from patches/R-4.4.1/emscripten-dataviewer.diff rename to patches/R-4.4.2/emscripten-dataviewer.diff index 59312e61..3e118512 100644 --- a/patches/R-4.4.1/emscripten-dataviewer.diff +++ b/patches/R-4.4.2/emscripten-dataviewer.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/unix/system.c +Index: R-4.4.2/src/unix/system.c =================================================================== ---- R-4.4.0.orig/src/unix/system.c -+++ R-4.4.0/src/unix/system.c +--- R-4.4.2.orig/src/unix/system.c ++++ R-4.4.2/src/unix/system.c @@ -115,7 +115,24 @@ void R_FlushConsole(void) { } #endif diff --git a/patches/R-4.4.1/emscripten-input.diff b/patches/R-4.4.2/emscripten-input.diff similarity index 63% rename from patches/R-4.4.1/emscripten-input.diff rename to patches/R-4.4.2/emscripten-input.diff index c6b4cd9c..365bd9b7 100644 --- a/patches/R-4.4.1/emscripten-input.diff +++ b/patches/R-4.4.2/emscripten-input.diff @@ -1,23 +1,15 @@ -Index: R-4.4.0/src/unix/sys-std.c +Index: R-4.4.2/src/unix/sys-std.c =================================================================== ---- R-4.4.0.orig/src/unix/sys-std.c -+++ R-4.4.0/src/unix/sys-std.c -@@ -61,6 +61,7 @@ - - #ifdef __EMSCRIPTEN__ - #include /* for isspace */ -+#include "Parse.h" - #endif - - extern SA_TYPE SaveAction; -@@ -327,8 +328,17 @@ void (* R_PolledEvents)(void) = nop; +--- R-4.4.2.orig/src/unix/sys-std.c ++++ R-4.4.2/src/unix/sys-std.c +@@ -323,8 +323,17 @@ void (* R_PolledEvents)(void) = nop; static void nop(void){} +#ifdef __EMSCRIPTEN__ +#include +static void handleEvents(void){ -+ EM_ASM(globalThis.Module.webr.handleEvents()); ++ EM_ASM(globalThis.Module.webr.handleEvents()); +} +void (* R_PolledEvents)(void) = handleEvents; +int R_wait_usec = 100000; @@ -28,12 +20,12 @@ Index: R-4.4.0/src/unix/sys-std.c /* For X11 devices */ void (* Rg_PolledEvents)(void) = nop; -@@ -1051,8 +1061,12 @@ Rstd_ReadConsole(const char *prompt, unsigned char *bu +@@ -1051,8 +1060,12 @@ Rstd_ReadConsole(const char *prompt, unsigned char *bu else #endif /* HAVE_LIBREADLINE */ { +#ifdef __EMSCRIPTEN__ -+ EM_ASM(globalThis.Module.setPrompt(UTF8ToString($0)), prompt); ++ EM_ASM(globalThis.Module.webr.setPrompt(UTF8ToString($0)), prompt); +#else fputs(prompt, stdout); fflush(stdout); @@ -41,16 +33,11 @@ Index: R-4.4.0/src/unix/sys-std.c } if(R_InputHandlers == NULL) -@@ -1110,10 +1124,25 @@ Rstd_ReadConsole(const char *prompt, unsigned char *bu +@@ -1110,10 +1123,20 @@ Rstd_ReadConsole(const char *prompt, unsigned char *bu else #endif /* HAVE_LIBREADLINE */ { +#ifdef __EMSCRIPTEN__ -+ static int initialised = 0; -+ if (!initialised) { -+ EM_ASM(globalThis.Module.webr.resolveInit()); -+ initialised = 1; -+ } + const char* input = (const char*) EM_ASM_INT(return globalThis.Module.webr.readConsole()); + if (input) { + strncpy((char*) buf, input, len); @@ -67,10 +54,10 @@ Index: R-4.4.0/src/unix/sys-std.c } } } -Index: R-4.4.0/src/main/main.c +Index: R-4.4.2/src/main/main.c =================================================================== ---- R-4.4.0.orig/src/main/main.c -+++ R-4.4.0/src/main/main.c +--- R-4.4.2.orig/src/main/main.c ++++ R-4.4.2/src/main/main.c @@ -321,7 +321,7 @@ static unsigned char DLLbuf[CONSOLE_BUFFER_SIZE+1], *D } diff --git a/patches/R-4.4.1/emscripten-jumpctxt.diff b/patches/R-4.4.2/emscripten-jumpctxt.diff similarity index 74% rename from patches/R-4.4.1/emscripten-jumpctxt.diff rename to patches/R-4.4.2/emscripten-jumpctxt.diff index 72b1e59b..230e267f 100644 --- a/patches/R-4.4.1/emscripten-jumpctxt.diff +++ b/patches/R-4.4.2/emscripten-jumpctxt.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/main/errors.c +Index: R-4.4.2/src/main/errors.c =================================================================== ---- R-4.4.0.orig/src/main/errors.c -+++ R-4.4.0/src/main/errors.c +--- R-4.4.2.orig/src/main/errors.c ++++ R-4.4.2/src/main/errors.c @@ -1078,7 +1078,7 @@ static void jump_to_top_ex(Rboolean traceback, } } diff --git a/patches/R-4.4.1/emscripten-lazyload.diff b/patches/R-4.4.2/emscripten-lazyload.diff similarity index 88% rename from patches/R-4.4.1/emscripten-lazyload.diff rename to patches/R-4.4.2/emscripten-lazyload.diff index cb84af52..beaf55d4 100644 --- a/patches/R-4.4.1/emscripten-lazyload.diff +++ b/patches/R-4.4.2/emscripten-lazyload.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/library/datasets/Makefile.in +Index: R-4.4.2/src/library/datasets/Makefile.in =================================================================== ---- R-4.4.0.orig/src/library/datasets/Makefile.in -+++ R-4.4.0/src/library/datasets/Makefile.in +--- R-4.4.2.orig/src/library/datasets/Makefile.in ++++ R-4.4.2/src/library/datasets/Makefile.in @@ -26,7 +26,7 @@ all: Makefile DESCRIPTION $(INSTALL_DATA) $${f} $(top_builddir)/library/$(pkg)/data; \ done @@ -11,10 +11,10 @@ Index: R-4.4.0/src/library/datasets/Makefile.in R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE) > /dev/null @$(INSTALL_DATA) $(srcdir)/data/morley.tab \ $(top_builddir)/library/$(pkg)/data -Index: R-4.4.0/Makeconf.in +Index: R-4.4.2/Makeconf.in =================================================================== ---- R-4.4.0.orig/Makeconf.in -+++ R-4.4.0/Makeconf.in +--- R-4.4.2.orig/Makeconf.in ++++ R-4.4.2/Makeconf.in @@ -164,3 +164,13 @@ Rexecmodulesdir = $(rhome)/modules$(R_ARCH) ## switching to automake. ## @@ -29,10 +29,10 @@ Index: R-4.4.0/Makeconf.in + LIB_LOC_ARG = lib.loc = \"$(R_INSTALL_LIBRARY)\" + TARGET_LIB_LOC_ARG = target.lib.loc = \"$(R_INSTALL_LIBRARY)\" +endif -Index: R-4.4.0/share/make/basepkg.mk +Index: R-4.4.2/share/make/basepkg.mk =================================================================== ---- R-4.4.0.orig/share/make/basepkg.mk -+++ R-4.4.0/share/make/basepkg.mk +--- R-4.4.2.orig/share/make/basepkg.mk ++++ R-4.4.2/share/make/basepkg.mk @@ -127,7 +127,7 @@ mklazy: ## only used if byte-compilation is disabled mklazy: @@ -42,10 +42,10 @@ Index: R-4.4.0/share/make/basepkg.mk R_DEFAULT_PACKAGES=$(DEFPKGS) LC_ALL=C $(R_EXE) > /dev/null mklazycomp: $(top_builddir)/library/$(pkg)/R/$(pkg).rdb -Index: R-4.4.0/share/make/lazycomp.mk +Index: R-4.4.2/share/make/lazycomp.mk =================================================================== ---- R-4.4.0.orig/share/make/lazycomp.mk -+++ R-4.4.0/share/make/lazycomp.mk +--- R-4.4.2.orig/share/make/lazycomp.mk ++++ R-4.4.2/share/make/lazycomp.mk @@ -7,11 +7,11 @@ $(top_builddir)/library/$(pkg)/R/$(pkg).rdb: all.R $(top_builddir)/library/$(pkg)/R/$(pkg).rdb: all.R @$(INSTALL_DATA) all.R $(top_builddir)/library/$(pkg)/R/$(pkg) @@ -60,10 +60,10 @@ Index: R-4.4.0/share/make/lazycomp.mk _R_COMPILE_PKGS_=1 R_COMPILER_SUPPRESS_ALL=1 \ R_DEFAULT_PACKAGES=$(DEFPKGS) LC_ALL=C $(R_EXE) > /dev/null; \ fi -Index: R-4.4.0/src/library/methods/Makefile.in +Index: R-4.4.2/src/library/methods/Makefile.in =================================================================== ---- R-4.4.0.orig/src/library/methods/Makefile.in -+++ R-4.4.0/src/library/methods/Makefile.in +--- R-4.4.2.orig/src/library/methods/Makefile.in ++++ R-4.4.2/src/library/methods/Makefile.in @@ -37,6 +37,9 @@ RfilesLazy: $(top_builddir)/library/$(pkg)/R/$(pkg).rd RfilesLazy: $(top_builddir)/library/$(pkg)/R/$(pkg).rdb @@ -98,10 +98,10 @@ Index: R-4.4.0/src/library/methods/Makefile.in ## not supported Rsimple: -Index: R-4.4.0/src/library/methods/R/zzz.R +Index: R-4.4.2/src/library/methods/R/zzz.R =================================================================== ---- R-4.4.0.orig/src/library/methods/R/zzz.R -+++ R-4.4.0/src/library/methods/R/zzz.R +--- R-4.4.2.orig/src/library/methods/R/zzz.R ++++ R-4.4.2/src/library/methods/R/zzz.R @@ -21,6 +21,8 @@ ## Initialize the methods package. function(libname, pkgname) @@ -111,10 +111,10 @@ Index: R-4.4.0/src/library/methods/R/zzz.R where <- environment(sys.function()) # the namespace coerceVars <- c("as", "as<-", "is", "new", "S3Part", "S3Part<-", "slot", "slot<-") -Index: R-4.4.0/src/library/tools/Makefile.in +Index: R-4.4.2/src/library/tools/Makefile.in =================================================================== ---- R-4.4.0.orig/src/library/tools/Makefile.in -+++ R-4.4.0/src/library/tools/Makefile.in +--- R-4.4.2.orig/src/library/tools/Makefile.in ++++ R-4.4.2/src/library/tools/Makefile.in @@ -52,7 +52,7 @@ $(top_builddir)/library/$(pkg)/R/$(pkg).rdb: Makefile @$(ECHO) "byte-compiling package '$(pkg)'" @$(INSTALL_DATA) all.R $(top_builddir)/library/$(pkg)/R/$(pkg) @@ -133,10 +133,10 @@ Index: R-4.4.0/src/library/tools/Makefile.in R_SYSTEM_ABI='@R_SYSTEM_ABI@' \ R_DEFAULT_PACKAGES=NULL LC_ALL=C $(R_EXE) > /dev/null -Index: R-4.4.0/src/library/tools/R/makeLazyLoad.R +Index: R-4.4.2/src/library/tools/R/makeLazyLoad.R =================================================================== ---- R-4.4.0.orig/src/library/tools/R/makeLazyLoad.R -+++ R-4.4.0/src/library/tools/R/makeLazyLoad.R +--- R-4.4.2.orig/src/library/tools/R/makeLazyLoad.R ++++ R-4.4.2/src/library/tools/R/makeLazyLoad.R @@ -20,11 +20,12 @@ code2LazyLoadDB <- function(package, lib.loc = NULL, keep.source = getOption("keep.source.pkgs"), @@ -194,10 +194,10 @@ Index: R-4.4.0/src/library/tools/R/makeLazyLoad.R file.copy(loaderFile, codeFile, TRUE) } -Index: R-4.4.0/src/library/base/makebasedb.R +Index: R-4.4.2/src/library/base/makebasedb.R =================================================================== ---- R-4.4.0.orig/src/library/base/makebasedb.R -+++ R-4.4.0/src/library/base/makebasedb.R +--- R-4.4.2.orig/src/library/base/makebasedb.R ++++ R-4.4.2/src/library/base/makebasedb.R @@ -116,7 +116,11 @@ local({ if (length(search()[search()!="Autoloads"]) != 2) stop("start R with NO packages loaded to create the data base") @@ -211,10 +211,10 @@ Index: R-4.4.0/src/library/base/makebasedb.R if (file.info(baseFileBase)["size"] < 20000) # crude heuristic stop("may already be using lazy loading on base"); -Index: R-4.4.0/src/library/base/R/library.R +Index: R-4.4.2/src/library/base/R/library.R =================================================================== ---- R-4.4.0.orig/src/library/base/R/library.R -+++ R-4.4.0/src/library/base/R/library.R +--- R-4.4.2.orig/src/library/base/R/library.R ++++ R-4.4.2/src/library/base/R/library.R @@ -771,7 +771,7 @@ function(package = NULL, lib.loc = NULL, quiet = FALSE ## don't waste time looking for the standard packages: ## we know where they are and this can take a significant diff --git a/patches/R-4.4.1/emscripten-r-home-stderr.diff b/patches/R-4.4.2/emscripten-r-home-stderr.diff similarity index 77% rename from patches/R-4.4.1/emscripten-r-home-stderr.diff rename to patches/R-4.4.2/emscripten-r-home-stderr.diff index f1637e3f..9e78b267 100644 --- a/patches/R-4.4.1/emscripten-r-home-stderr.diff +++ b/patches/R-4.4.2/emscripten-r-home-stderr.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/scripts/R.sh.in +Index: R-4.4.2/src/scripts/R.sh.in =================================================================== ---- R-4.4.0.orig/src/scripts/R.sh.in -+++ R-4.4.0/src/scripts/R.sh.in +--- R-4.4.2.orig/src/scripts/R.sh.in ++++ R-4.4.2/src/scripts/R.sh.in @@ -28,7 +28,7 @@ if test -n "${R_HOME}" && \ if test -n "${R_HOME}" && \ diff --git a/patches/R-4.4.1/emscripten-unimplmented.diff b/patches/R-4.4.2/emscripten-sigsuspend.diff similarity index 82% rename from patches/R-4.4.1/emscripten-unimplmented.diff rename to patches/R-4.4.2/emscripten-sigsuspend.diff index 67bc1a89..8ca86ef6 100644 --- a/patches/R-4.4.1/emscripten-unimplmented.diff +++ b/patches/R-4.4.2/emscripten-sigsuspend.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/unix/sys-unix.c +Index: R-4.4.2/src/unix/sys-unix.c =================================================================== ---- R-4.4.0.orig/src/unix/sys-unix.c -+++ R-4.4.0/src/unix/sys-unix.c +--- R-4.4.2.orig/src/unix/sys-unix.c ++++ R-4.4.2/src/unix/sys-unix.c @@ -60,7 +60,20 @@ #include diff --git a/patches/R-4.4.1/emscripten-disable-system.diff b/patches/R-4.4.2/emscripten-system.diff similarity index 84% rename from patches/R-4.4.1/emscripten-disable-system.diff rename to patches/R-4.4.2/emscripten-system.diff index 3c5d9140..160352c4 100644 --- a/patches/R-4.4.1/emscripten-disable-system.diff +++ b/patches/R-4.4.2/emscripten-system.diff @@ -1,12 +1,12 @@ -Index: R-4.4.0/src/library/base/R/unix/system.unix.R +Index: R-4.4.2/src/library/base/R/unix/system.unix.R =================================================================== ---- R-4.4.0.orig/src/library/base/R/unix/system.unix.R -+++ R-4.4.0/src/library/base/R/unix/system.unix.R +--- R-4.4.2.orig/src/library/base/R/unix/system.unix.R ++++ R-4.4.2/src/library/base/R/unix/system.unix.R @@ -37,6 +37,11 @@ system <- function(command, intern = FALSE, if(!is.logical(receive.console.signals) || is.na(receive.console.signals)) stop("'receive.console.signals' must be TRUE or FALSE") -+ # Disable system() command when running under emscripten ++ # Hook system() command when running under emscripten + if (grepl("emscripten", R.version$os)) { + return(webr_hook_system(command)) + } @@ -19,7 +19,7 @@ Index: R-4.4.0/src/library/base/R/unix/system.unix.R if(!is.logical(receive.console.signals) || is.na(receive.console.signals)) stop("'receive.console.signals' must be TRUE or FALSE") + -+ # Disable system() command when running under emscripten ++ # Hook system() command when running under emscripten + if (grepl("emscripten", R.version$os)) { + return(webr_hook_system(command)) + } @@ -52,10 +52,10 @@ Index: R-4.4.0/src/library/base/R/unix/system.unix.R warning("'which' was not found on this platform") return(res) } -Index: R-4.4.0/src/library/utils/R/sessionInfo.R +Index: R-4.4.2/src/library/utils/R/sessionInfo.R =================================================================== ---- R-4.4.0.orig/src/library/utils/R/sessionInfo.R -+++ R-4.4.0/src/library/utils/R/sessionInfo.R +--- R-4.4.2.orig/src/library/utils/R/sessionInfo.R ++++ R-4.4.2/src/library/utils/R/sessionInfo.R @@ -23,6 +23,8 @@ ## Now try to figure out the OS we are running under if (.Platform$OS.type == "windows") { diff --git a/patches/R-4.4.1/emscripten-xhr-download.diff b/patches/R-4.4.2/emscripten-xhr-download.diff similarity index 99% rename from patches/R-4.4.1/emscripten-xhr-download.diff rename to patches/R-4.4.2/emscripten-xhr-download.diff index d439afba..bc484d76 100644 --- a/patches/R-4.4.1/emscripten-xhr-download.diff +++ b/patches/R-4.4.2/emscripten-xhr-download.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/modules/internet/libcurl.c +Index: R-4.4.2/src/modules/internet/libcurl.c =================================================================== ---- R-4.4.0.orig/src/modules/internet/libcurl.c -+++ R-4.4.0/src/modules/internet/libcurl.c +--- R-4.4.2.orig/src/modules/internet/libcurl.c ++++ R-4.4.2/src/modules/internet/libcurl.c @@ -55,6 +55,7 @@ static int current_timeout = 0; static int current_timeout = 0; diff --git a/patches/R-4.4.1/fix-sink-release.diff b/patches/R-4.4.2/fix-sink-release.diff similarity index 77% rename from patches/R-4.4.1/fix-sink-release.diff rename to patches/R-4.4.2/fix-sink-release.diff index df105b5d..db4a6174 100644 --- a/patches/R-4.4.1/fix-sink-release.diff +++ b/patches/R-4.4.2/fix-sink-release.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/main/connections.c +Index: R-4.4.2/src/main/connections.c =================================================================== ---- R-4.4.0.orig/src/main/connections.c -+++ R-4.4.0/src/main/connections.c +--- R-4.4.2.orig/src/main/connections.c ++++ R-4.4.2/src/main/connections.c @@ -5356,7 +5356,7 @@ attribute_hidden SEXP do_sink(SEXP call, SEXP op, SEXP error(_("sink stack is full")); switch_or_tee_stdout(icon, closeOnExit, tee); diff --git a/patches/R-4.4.1/flang-avoid-maxloc.diff b/patches/R-4.4.2/flang-avoid-maxloc.diff similarity index 100% rename from patches/R-4.4.1/flang-avoid-maxloc.diff rename to patches/R-4.4.2/flang-avoid-maxloc.diff diff --git a/patches/R-4.4.1/fontconfig-typeof.diff b/patches/R-4.4.2/fontconfig-typeof.diff similarity index 80% rename from patches/R-4.4.1/fontconfig-typeof.diff rename to patches/R-4.4.2/fontconfig-typeof.diff index 96b9ff0f..c2937692 100644 --- a/patches/R-4.4.1/fontconfig-typeof.diff +++ b/patches/R-4.4.2/fontconfig-typeof.diff @@ -1,7 +1,7 @@ -Index: R-4.4.0/src/library/grDevices/src/cairo/cairoFns.c +Index: R-4.4.2/src/library/grDevices/src/cairo/cairoFns.c =================================================================== ---- R-4.4.0.orig/src/library/grDevices/src/cairo/cairoFns.c -+++ R-4.4.0/src/library/grDevices/src/cairo/cairoFns.c +--- R-4.4.2.orig/src/library/grDevices/src/cairo/cairoFns.c ++++ R-4.4.2/src/library/grDevices/src/cairo/cairoFns.c @@ -1679,10 +1679,13 @@ PangoCairo_Text(double x, double y, with freetype2/fontconfig (FT implies FC in Cairo). */ diff --git a/patches/R-4.4.1/series b/patches/R-4.4.2/series similarity index 61% rename from patches/R-4.4.1/series rename to patches/R-4.4.2/series index 4ac72465..8f37fb0d 100644 --- a/patches/R-4.4.1/series +++ b/patches/R-4.4.2/series @@ -1,17 +1,13 @@ emscripten-configure.diff -emscripten-includes.diff -emscripten-makefiles.diff +emscripten-xhr-download.diff +emscripten-sigsuspend.diff emscripten-lazyload.diff -emscripten-unimplmented.diff emscripten-input.diff -emscripten-disable-system.diff +emscripten-system.diff emscripten-jumpctxt.diff -emscripten-xhr-download.diff -emscripten-disable-bcEval.diff -emscripten-fix-blas-dlsym-search.diff +emscripten-dataviewer.diff emscripten-avoid-testing-issues.diff emscripten-r-home-stderr.diff -flang-avoid-maxloc.diff fontconfig-typeof.diff fix-sink-release.diff -emscripten-dataviewer.diff +flang-avoid-maxloc.diff diff --git a/src/tests/packages/webr.test.ts b/src/tests/packages/webr.test.ts index 67d889a1..55cfe742 100644 --- a/src/tests/packages/webr.test.ts +++ b/src/tests/packages/webr.test.ts @@ -68,6 +68,11 @@ describe('Run R default package examples and tests', () => { expect(await test.toNumber()).toEqual(0); }); + test('grid', async () => { + const test = await evalTest('grid'); + expect(await test.toNumber()).toEqual(0); + }); + test('compiler', async () => { const test = await evalTest('compiler'); expect(await test.toNumber()).toEqual(0); @@ -77,13 +82,6 @@ describe('Run R default package examples and tests', () => { const test = await evalTest('base'); expect(await test.toNumber()).toEqual(0); }); - - test('grid', async () => { - await webR.evalR('options(expressions=5000)'); - await webR.evalR('graphics.off()'); - const test = await evalTest('grid'); - expect(await test.toNumber()).toEqual(0); - }); }); afterAll(() => { diff --git a/src/webR/emscripten.ts b/src/webR/emscripten.ts index a7b34447..bf42b848 100644 --- a/src/webR/emscripten.ts +++ b/src/webR/emscripten.ts @@ -24,7 +24,6 @@ export interface Module extends EmscriptenModule { noImageDecoding: boolean; noAudioDecoding: boolean; noWasmDecoding: boolean; - setPrompt: (prompt: string) => void; downloadFileContent: ( URL: string, headers?: Array @@ -137,6 +136,7 @@ export interface Module extends EmscriptenModule { }; }; readConsole: () => number; + setPrompt: (prompt: string) => void; resolveInit: () => void; handleEvents: () => void; dataViewer: (data: RPtr, title: string) => void; diff --git a/src/webR/webr-worker.ts b/src/webR/webr-worker.ts index c5df8a78..b2071acb 100644 --- a/src/webR/webr-worker.ts +++ b/src/webR/webr-worker.ts @@ -57,6 +57,7 @@ import { } from './robj-worker'; let initialised = false; +let resolved = false; let chan: ChannelWorker | undefined; // Make webR Worker R objects available in WorkerGlobalScope @@ -875,12 +876,18 @@ function init(config: Required) { Module.setValue(Module._R_Interactive, _config.interactive ? 1 : 0, 'i8'); evalR(`options(webr_pkg_repos="${_config.repoUrl}")`); chan?.resolve(); + resolved = true; + }, + + setPrompt: (prompt: string) => { + chan?.write({ type: 'prompt', data: prompt }); }, readConsole: () => { if (!chan) { throw new Error("Can't read console input without a communication channel"); } + if (!resolved) Module.webr.resolveInit(); return chan.inputOrDispatch(); }, @@ -931,12 +938,10 @@ function init(config: Required) { Module.print = (text: string) => { chan?.write({ type: 'stdout', data: text }); }; + Module.printErr = (text: string) => { chan?.write({ type: 'stderr', data: text }); }; - Module.setPrompt = (prompt: string) => { - chan?.write({ type: 'prompt', data: prompt }); - }; // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access (globalThis as any).Module = Module;