Skip to content

[DRAFT] Fix/support cross-compiling packages depending on RcppParallel & TBB #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -170,6 +171,26 @@ 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 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")),
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
Expand Down