From d4288d7b5d238ef5ffd8ba731c74a7e7ad71cbbe Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 11 Jun 2025 20:32:43 +0800 Subject: [PATCH 1/2] Fix building under wasm/webr --- src/install.libs.R | 18 ++++++++++++++++++ tools/config/configure.R | 19 ++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) 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)" + ) + } } From a7e3494a2d57521f75a135bf36e5ee590ce08545 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 11 Jun 2025 22:13:08 +0800 Subject: [PATCH 2/2] Update ldflags for wasm --- R/tbb.R | 4 ++++ 1 file changed, 4 insertions(+) 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)) }