Compiling errors while building with Emscripten for WASM
Hi,
I am trying to port our app that uses oneTBB to WASM (emscripten) and the compilation of oneTBB from source is failing.
The project uses cmake FetchContent to pull in oneTBB and build form source as a dependency. I tried the latest head as well but the issue remains.
Example log with build error:
C:\proj\src\build (wip/web-offscreen-acceleration-experiment -> origin)
λ cmake --build .
[0/2] Re-checking globbed directories...
[1/64] Building CXX object _deps/tbb-build/src/tbb/CMakeFiles/tbb.dir/arena_slot.cpp.o
FAILED: _deps/tbb-build/src/tbb/CMakeFiles/tbb.dir/arena_slot.cpp.o
C:\emsdk\emscripten-1.39.4.7-windows64\fastcomp\emscripten\em++.bat -D__TBB_BUILD -D__TBB_DYNAMIC_LOAD_ENABLED=0 -D__TBB_SOURCE_DIRECTLY_INCLUDED=1 -D__TBB_USE_ITT_NOTIFY -IC:/proj/src/build/_deps/tbb-src/src/tbb/../../include -DNDEBUG -O2 -std=c++2a -fPIC -Wall -Wextra -mrtm -MD -MT _deps/tbb-build/src/tbb/CMakeFiles/tbb.dir/arena_slot.cpp.o -MF _deps\tbb-build\src\tbb\CMakeFiles\tbb.dir\arena_slot.cpp.o.d -o _deps/tbb-build/src/tbb/CMakeFiles/tbb.dir/arena_slot.cpp.o -c C:/proj/src/build/_deps/tbb-src/src/tbb/arena_slot.cpp
clang++.exe: warning: argument unused during compilation: '-mrtm' [-Wunused-command-line-argument]
In file included from C:/proj/src/build/_deps/tbb-src/src/tbb/arena_slot.cpp:18:
In file included from C:/proj/src/build/_deps/tbb-src/src/tbb/arena.h:31:
In file included from C:/proj/src/build/_deps/tbb-src/src/tbb/market.h:21:
In file included from C:/proj/src/build/_deps/tbb-src/src/tbb/market_concurrent_monitor.h:20:
In file included from C:/proj/src/build/_deps/tbb-src/src/tbb/concurrent_monitor.h:23:
In file included from C:/proj/src/build/_deps/tbb-src/src/tbb/concurrent_monitor_mutex.h:22:
C:/proj/src/build/_deps/tbb-src/src/tbb/semaphore.h:104:15: error: no member named 'syscall' in the global namespace
int r = ::syscall(SYS_futex, futex, __TBB_FUTEX_WAIT, comparand, nullptr, nullptr, 0);
~~^
C:/proj/src/build/_deps/tbb-src/src/tbb/semaphore.h:113:15: error: no member named 'syscall' in the global namespace
int r = ::syscall(SYS_futex, futex, __TBB_FUTEX_WAKE, 1, nullptr, nullptr, 0);
~~^
2 errors generated.
Essentially everywhere there is a call to syscall it doesnt work and from what I have learned there is no generic syscall available in emscripten, only specific wrappers: https://github.com/emscripten-core/emscripten/issues/6708
Unless this issue is outdated and we are missing configuration options?
This is part of the CMake file that consumes oneTBB:
include(FetchContent)
FetchContent_Declare(
TBB
GIT_REPOSITORY https://github.com/oneapi-src/oneTBB.git
GIT_TAG 8259efb3473c045eb4a0af4a72764f6c468d3acc
)
set(TBB_TEST OFF CACHE BOOL "Enable testing" FORCE)
set(TBB_EXAMPLES OFF CACHE BOOL "Enable examples" FORCE)
set(TBB_STRICT OFF CACHE BOOL "Treat compiler warnings as errors" FORCE)
# WARNING: might need to turn this one OFF for linux builds in the future
# see: https://github.com/oneapi-src/oneTBB/issues/297#issuecomment-1043979502
#set(TBB_ENABLE_IPO ON CACHE BOOL "Enable Interprocedural Optimization (FORCE) #default during the compilation" ON)
if(EMSCRIPTEN)
set(TBB_STRICT OFF CACHE BOOL "" FORCE)
set(TBB_DISABLE_HWLOC_AUTOMATIC_SEARCH ON CACHE BOOL "" FORCE)
set(TBB_ENABLE_IPO OFF CACHE BOOL "" FORCE )
endif()
set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
set(BUILD_SHARED_LIBS ON)
FetchContent_MakeAvailable(TBB)
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")
Shared builds, although advised, are disabled since emscripten can only consume static libraries.
From here TBB::tbb is consumed with target_link_libraries.
Any help would be appreciated.
Hi, I tried it on Linux and it works. Let me try on windows (I presume you are using windows looking at your commands) and I will get back to you. I would be surprised if syscall is supported on Linux and not on windows. My command to build arena_slot.cpp is the same as yours. Note: If you pull the most recent oneTBB, -mrtm the warning should disappear.
Hi, I tried it on windows and it is working. For reference, my command to build arena_slot is _
"C:...\emsdk\upstream\emscripten\em++.bat -D__TBB_BUILD -D__TBB_DYNAMIC_LOAD_ENABLED=0 -D__TBB_SOURCE_DIRECTLY_INCLUDED=1 -D__TBB_USE_ITT_NOTIFY -I../src/tbb/../../include -DNDEBUG -O2 -std=c++2a -fPIC -Wall -Wextra -c ../src/tbb/arena_slot.cpp"
_ Could you try using latest version of Emscripten(it is 3.1.49).
@twadrianlis is this issue still relevant?
If anyone encounter this issue in the future please open new issue with a link to this one