diff --git a/recipes/recipes_emscripten/onetbb/build.sh b/recipes/recipes_emscripten/onetbb/build.sh index 9763c1a546..c1edebe775 100755 --- a/recipes/recipes_emscripten/onetbb/build.sh +++ b/recipes/recipes_emscripten/onetbb/build.sh @@ -8,13 +8,6 @@ CFLAGS="${CFLAGS:-}" CXXFLAGS="${CXXFLAGS:-}" LDFLAGS="${LDFLAGS:-}" -# Disable ucontext-based resumable tasks — ucontext symbols -# (getcontext/makecontext/swapcontext) are not linkable on WASM. -# This forces oneTBB to use pthread-based coroutines instead. -export CFLAGS="$CFLAGS $EM_FORGE_SIDE_MODULE_CFLAGS -D__TBB_RESUMABLE_TASKS_USE_THREADS=1" -export CXXFLAGS="$CXXFLAGS $EM_FORGE_SIDE_MODULE_CFLAGS -D__TBB_RESUMABLE_TASKS_USE_THREADS=1" -export LDFLAGS="$LDFLAGS $EM_FORGE_SIDE_MODULE_LDFLAGS" - mkdir -p build cd build @@ -27,12 +20,14 @@ emcmake cmake -GNinja \ -DBUILD_SHARED_LIBS=OFF \ -DTBB_STRICT=OFF \ -DTBB_DISABLE_HWLOC_AUTOMATIC_SEARCH=ON \ + -DEMSCRIPTEN_WITHOUT_PTHREAD=ON \ -DTBB_EXAMPLES=OFF \ -DTBB_TEST=OFF \ -DTBB4PY_BUILD=OFF \ -DTBBMALLOC_BUILD=ON \ -DTBBMALLOC_PROXY_BUILD=ON \ -DTBB_INSTALL=ON \ + -DCMAKE_C_FLAGS="-Wno-unused-command-line-argument ${CFLAGS}" \ -DCMAKE_CXX_FLAGS="-Wno-unused-command-line-argument ${CXXFLAGS}" \ .. diff --git a/recipes/recipes_emscripten/onetbb/build_tests.sh b/recipes/recipes_emscripten/onetbb/build_tests.sh index 331cba5841..60d8a02667 100755 --- a/recipes/recipes_emscripten/onetbb/build_tests.sh +++ b/recipes/recipes_emscripten/onetbb/build_tests.sh @@ -1,19 +1,15 @@ #!/bin/bash set -e -# -pthread must match libtbb.a build; without it the linker rejects -# --shared-memory and the test binary won't link. -export CFLAGS="${CFLAGS} -pthread" -export CXXFLAGS="${CXXFLAGS} -pthread" - emcmake cmake -S tests -B build_tests \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH="${PREFIX}" \ - -DCMAKE_FIND_ROOT_PATH="${PREFIX}" \ - -DCMAKE_CXX_FLAGS="-pthread" \ - -DCMAKE_EXE_LINKER_FLAGS="-pthread" + -DCMAKE_FIND_ROOT_PATH="${PREFIX}" emmake make -C build_tests -j"${CPU_COUNT}" -echo "Running test..." +echo "Running TBB threading test..." node build_tests/test_onetbb.js + +echo "Running TBB malloc test..." +node build_tests/test_onetbb_malloc.js diff --git a/recipes/recipes_emscripten/onetbb/recipe.yaml b/recipes/recipes_emscripten/onetbb/recipe.yaml index 4fff27acd2..d61dee05e0 100644 --- a/recipes/recipes_emscripten/onetbb/recipe.yaml +++ b/recipes/recipes_emscripten/onetbb/recipe.yaml @@ -11,7 +11,7 @@ source: sha256: f8767b971ec6aea25dde58ae0f593e94e7aa75a739a86f67967012f69e2199b1 build: - number: 0 + number: 1 script: build.sh requirements: diff --git a/recipes/recipes_emscripten/onetbb/tests/CMakeLists.txt b/recipes/recipes_emscripten/onetbb/tests/CMakeLists.txt index e3a914bd61..e8850d78c9 100644 --- a/recipes/recipes_emscripten/onetbb/tests/CMakeLists.txt +++ b/recipes/recipes_emscripten/onetbb/tests/CMakeLists.txt @@ -2,14 +2,12 @@ cmake_minimum_required(VERSION 3.16) project(test_onetbb CXX) set(CMAKE_CXX_STANDARD 17) -# pthreads are required to match libtbb.a (compiled with -pthread). -# These flags must be set BEFORE find_package / add_executable so they -# affect both compilation and linking. -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread") - find_package(TBB CONFIG REQUIRED) +# Test TBB threading library add_executable(test_onetbb test_onetbb.cpp) target_link_libraries(test_onetbb TBB::tbb) + +# Test TBB malloc library (needed by oneDAL) +add_executable(test_onetbb_malloc test_onetbb_malloc.cpp) +target_link_libraries(test_onetbb_malloc TBB::tbbmalloc) diff --git a/recipes/recipes_emscripten/onetbb/tests/test_onetbb_malloc.cpp b/recipes/recipes_emscripten/onetbb/tests/test_onetbb_malloc.cpp new file mode 100644 index 0000000000..24f97e2a68 --- /dev/null +++ b/recipes/recipes_emscripten/onetbb/tests/test_onetbb_malloc.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +int main() { + // 1. scalable_malloc / scalable_free + void* p = scalable_malloc(1024); + assert(p != nullptr); + std::memset(p, 0xAB, 1024); + scalable_free(p); + + // 2. scalable_calloc + int* arr = static_cast(scalable_calloc(100, sizeof(int))); + assert(arr != nullptr); + for (int i = 0; i < 100; ++i) { + assert(arr[i] == 0); + } + scalable_free(arr); + + // 3. scalable_realloc + char* s = static_cast(scalable_malloc(32)); + assert(s != nullptr); + std::memcpy(s, "hello tbbmalloc", 15); + s = static_cast(scalable_realloc(s, 64)); + assert(s != nullptr); + scalable_free(s); + + // 4. scalable_aligned_malloc / scalable_aligned_free + void* ap = scalable_aligned_malloc(256, 64); + assert(ap != nullptr); + assert(reinterpret_cast(ap) % 64 == 0); + scalable_aligned_free(ap); + + // 5. scalable_posix_memalign + void* pp = nullptr; + int ret = scalable_posix_memalign(&pp, 64, 128); + assert(ret == 0); + assert(pp != nullptr); + assert(reinterpret_cast(pp) % 64 == 0); + scalable_free(pp); + + std::cout << "tbbmalloc tests passed!" << std::endl; + return 0; +}