From 40eeb14dbdae334ba72c1a325d68885e5d2a5c4a Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 12 Jun 2025 17:18:54 +0800 Subject: [PATCH 1/2] rcpp fix test --- R/build.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/R/build.R b/R/build.R index 84588e6..aabf718 100644 --- a/R/build.R +++ b/R/build.R @@ -152,6 +152,7 @@ wasm_build <- function(pkg, tarball_path, contrib_bin, compress) { break } } + # Setup environment for wasm compilation webr_root <- getOption("rwasm.webr_root") @@ -170,6 +171,21 @@ wasm_build <- function(pkg, tarball_path, contrib_bin, compress) { sprintf("EM_PKG_CONFIG=%s", Sys.which("pkg-config")), sprintf("EM_PKG_CONFIG_PATH=%s/wasm/lib/pkgconfig", webr_root) ) + + if ("RcppParallel" %in% pak::pkg_deps(pkg)$package) { + rcppparallel_tar <- file.path(tmp_dir, "rcppparallel.tgz") + download.file( + "https://rcppcore.r-universe.dev/bin/emscripten/contrib/4.5/RcppParallel_5.1.10.9000.tgz", + rcppparallel_tar, + mode = "wb" + ) + untar(rcppparallel_tar) + webr_env <- c( + webr_env, + paste0("TBB_INC=", file.path(tmp_dir, "RcppParallel", "include")), + paste0("TBB_LIB=", file.path(tmp_dir, "RcppParallel", "lib")) + ) + } # Need to use an empty library otherwise R might try to load wasm packages # from the library and fail From a65429317a9b2176d8b03f6ffa03105cfaa62249 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 12 Jun 2025 09:59:33 +0000 Subject: [PATCH 2/2] Update and doc --- R/build.R | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/R/build.R b/R/build.R index aabf718..bfff5a4 100644 --- a/R/build.R +++ b/R/build.R @@ -172,14 +172,19 @@ wasm_build <- function(pkg, tarball_path, contrib_bin, compress) { sprintf("EM_PKG_CONFIG_PATH=%s/wasm/lib/pkgconfig", webr_root) ) - if ("RcppParallel" %in% pak::pkg_deps(pkg)$package) { - rcppparallel_tar <- file.path(tmp_dir, "rcppparallel.tgz") - download.file( - "https://rcppcore.r-universe.dev/bin/emscripten/contrib/4.5/RcppParallel_5.1.10.9000.tgz", - rcppparallel_tar, - mode = "wb" - ) - untar(rcppparallel_tar) + # If package requires linking against RcppParallel & the TBB, download + # a version of RcppParallel compiled for WASM and set include/lib paths + # for the build + if ("RcppParallel" %in% pak::pkg_deps(paste0("local::", tarball_path))$package) { + if (!dir.exists(file.path(tmp_dir, "RcppParallel"))) { + rcppparallel_tar <- file.path(tmp_dir, "rcppparallel.tgz") + download.file( + "https://rcppcore.r-universe.dev/bin/emscripten/contrib/4.5/RcppParallel_5.1.10.9000.tgz", + rcppparallel_tar, + mode = "wb" + ) + untar(rcppparallel_tar, exdir = tmp_dir) + } webr_env <- c( webr_env, paste0("TBB_INC=", file.path(tmp_dir, "RcppParallel", "include")),