Skip to content

Set TBB_INC and TBB_LIB variables for package build (if TBB present) - #61

Open
andrjohns wants to merge 1 commit into
r-wasm:mainfrom
andrjohns:tbb
Open

Set TBB_INC and TBB_LIB variables for package build (if TBB present)#61
andrjohns wants to merge 1 commit into
r-wasm:mainfrom
andrjohns:tbb

Conversation

@andrjohns

Copy link
Copy Markdown

Looks up and sets the location of the TBB include and lib directories for the build process using the webr pkg-config.

If the TBB has not been installed for webr (e.g., via this PR), the variables are empty and the build is unaffected.

You can verify that all works (after installing the oneTBB webr libs) via:

pak::pak("RcppCore/RcppParallel")
rwasm::build("andrjohns/StanEstimators")

@jeroen

jeroen commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Usually R packages call pkg-config in their configure or Makevars to get the cflags/libs. Why do we need these envvars globally here?

@andrjohns

Copy link
Copy Markdown
Author

Usually R packages call pkg-config in their configure or Makevars to get the cflags/libs. Why do we need these envvars globally here?

R packages use RcppParallel to get the compilation flags and libs for linking against. By default, RcppParallel provides flags to link/compile against its bundled headers and static lib unless the TBB_INC and TBB_LIB vars are set. Because the rwasm process builds its dependencies as x86_64, when a package depends on RcppParallel, RcppParallel is built for x86_64 and WASM packages will fail to link against it

So we need to set the environment variables so that the x86_64 RcppParallel provides flags for linking against the WASM oneTBB

@andrjohns

Copy link
Copy Markdown
Author

We could configure rstan & rstantools to first use pkg-config to find the TBB and then fallback to RcppParallel, but I suppose it's a question of whether it should work out of the box for other packages

@jeroen

jeroen commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

We could configure rstan & rstantools to first use pkg-config to find the TBB and then fallback to RcppParallel, but I suppose it's a question of whether it should work out of the box for other packages

In the long run, using pkg-config is definitely a more portable solution, rather than relying on all build systems setting some env vars. pkg-config is used to expose the correct flags for libraries, even on other cross-compiled systems (e.g. posit p3m macoscross builds).

But for now we can use this PR to get things to work, I'll deploy it on r-universe!

@jeroen

jeroen commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@andrjohns I had to revert this because it causes RcppParallel to fail loading (at least the current CRAN version) when it is a dependency: https://github.com/r-universe/bioc/actions/runs/29756050039/attempts/1

The problem is that when cross compiling, we need to set the linker lib to the wasm build of libtbb, but the runtime libtbb when loading RcppParallel still be the host native one on Linux. So effectively the difference between LDFLAGS and LD_LIBRARY_PATH. However I think the TBB_LIB variable overrides both, so RcppParallel fails to load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants