Skip to content

Commit 84e4366

Browse files
authored
Fix building under wasm/webr (#237)
* Fix building under wasm/webr * Update ldflags for wasm
1 parent aa28b17 commit 84e4366

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

R/tbb.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ tbbLdFlags <- function() {
110110
# shortcut if TBB_LIB defined
111111
tbbLib <- Sys.getenv("TBB_LINK_LIB", Sys.getenv("TBB_LIB", unset = TBB_LIB))
112112
if (nzchar(tbbLib)) {
113+
if (R.version$os == "emscripten") {
114+
fmt <- "-L%1$s -l%2$s"
115+
return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME))
116+
}
113117
fmt <- "-L%1$s -Wl,-rpath,%1$s -l%2$s -l%3$s"
114118
return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME, TBB_MALLOC_NAME))
115119
}

src/install.libs.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
Darwin = "^libtbb.*\\.dylib$",
3131
"^libtbb.*\\.so.*$"
3232
)
33+
# WASM only supports static libraries
34+
if (R.version$os == "emscripten") {
35+
shlibPattern <- "^libtbb.*\\.a$"
36+
}
3337

3438
if (!nzchar(tbbLib)) {
3539

@@ -114,6 +118,15 @@ useBundledTbb <- function() {
114118
".."
115119
)
116120

121+
if (R.version$os == "emscripten") {
122+
cmakeFlags <- c(
123+
"-DEMSCRIPTEN=1",
124+
"-DTBBMALLOC_BUILD=0",
125+
"-DBUILD_SHARED_LIBS=0",
126+
cmakeFlags
127+
)
128+
}
129+
117130
writeLines("*** configuring tbb")
118131
owd <- setwd("tbb/build-tbb")
119132
output <- system2(cmake, shQuote(cmakeFlags), stdout = TRUE, stderr = TRUE)
@@ -145,6 +158,11 @@ useBundledTbb <- function() {
145158
"^libtbb.*\\.so.*$"
146159
)
147160

161+
# WASM only supports static libraries
162+
if (R.version$os == "emscripten") {
163+
shlibPattern <- "^libtbb.*\\.a$"
164+
}
165+
148166
tbbFiles <- list.files(
149167
file.path(getwd(), "tbb/build-tbb"),
150168
pattern = shlibPattern,

tools/config/configure.R

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,18 @@ pkgLibs <- if (!is.na(tbbLib)) {
238238
NULL
239239

240240
} else {
241-
242-
c(
243-
"-Wl,-Ltbb/build/lib_release",
244-
"-l$(TBB_NAME)",
245-
"-l$(TBB_MALLOC_NAME)"
246-
)
247-
241+
if (R.version$os == "emscripten") {
242+
c(
243+
"-Wl,-Ltbb/build/lib_release",
244+
"-l$(TBB_NAME)"
245+
)
246+
} else {
247+
c(
248+
"-Wl,-Ltbb/build/lib_release",
249+
"-l$(TBB_NAME)",
250+
"-l$(TBB_MALLOC_NAME)"
251+
)
252+
}
248253
}
249254

250255

0 commit comments

Comments
 (0)