diff --git a/R/tbb.R b/R/tbb.R index f00f0322..ac1050f3 100644 --- a/R/tbb.R +++ b/R/tbb.R @@ -110,6 +110,10 @@ tbbLdFlags <- function() { # shortcut if TBB_LIB defined tbbLib <- Sys.getenv("TBB_LINK_LIB", Sys.getenv("TBB_LIB", unset = TBB_LIB)) if (nzchar(tbbLib)) { + if (R.version$os == "emscripten") { + fmt <- "-L%1$s -l%2$s" + return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME)) + } fmt <- "-L%1$s -Wl,-rpath,%1$s -l%2$s -l%3$s" return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME, TBB_MALLOC_NAME)) } diff --git a/src/install.libs.R b/src/install.libs.R index ceec728c..03819e9e 100644 --- a/src/install.libs.R +++ b/src/install.libs.R @@ -30,6 +30,10 @@ Darwin = "^libtbb.*\\.dylib$", "^libtbb.*\\.so.*$" ) + # WASM only supports static libraries + if (R.version$os == "emscripten") { + shlibPattern <- "^libtbb.*\\.a$" + } if (!nzchar(tbbLib)) { @@ -114,6 +118,15 @@ useBundledTbb <- function() { ".." ) + if (R.version$os == "emscripten") { + cmakeFlags <- c( + "-DEMSCRIPTEN=1", + "-DTBBMALLOC_BUILD=0", + "-DBUILD_SHARED_LIBS=0", + cmakeFlags + ) + } + writeLines("*** configuring tbb") owd <- setwd("tbb/build-tbb") output <- system2(cmake, shQuote(cmakeFlags), stdout = TRUE, stderr = TRUE) @@ -145,6 +158,11 @@ useBundledTbb <- function() { "^libtbb.*\\.so.*$" ) + # WASM only supports static libraries + if (R.version$os == "emscripten") { + shlibPattern <- "^libtbb.*\\.a$" + } + tbbFiles <- list.files( file.path(getwd(), "tbb/build-tbb"), pattern = shlibPattern, diff --git a/tools/config/configure.R b/tools/config/configure.R index ec295df6..a36ef8fb 100644 --- a/tools/config/configure.R +++ b/tools/config/configure.R @@ -238,13 +238,18 @@ pkgLibs <- if (!is.na(tbbLib)) { NULL } else { - - c( - "-Wl,-Ltbb/build/lib_release", - "-l$(TBB_NAME)", - "-l$(TBB_MALLOC_NAME)" - ) - + if (R.version$os == "emscripten") { + c( + "-Wl,-Ltbb/build/lib_release", + "-l$(TBB_NAME)" + ) + } else { + c( + "-Wl,-Ltbb/build/lib_release", + "-l$(TBB_NAME)", + "-l$(TBB_MALLOC_NAME)" + ) + } }