Skip to content

Commit b5d77a0

Browse files
authored
[backport] Fix wasm build. (dmlc#11708) (dmlc#11714)
1 parent f6bce94 commit b5d77a0

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ if(FORCE_COLORED_OUTPUT AND (CMAKE_GENERATOR STREQUAL "Ninja") AND
253253
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
254254
endif()
255255

256-
find_package(Threads REQUIRED)
256+
if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten"))
257+
find_package(Threads REQUIRED)
258+
endif()
257259

258260
# -- OpenMP
259261
include(cmake/FindOpenMPMacOS.cmake)

cmake/Utils.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,12 @@ endmacro()
261261

262262
# handles dependencies
263263
macro(xgboost_target_link_libraries target)
264-
if(BUILD_STATIC_LIB)
265-
target_link_libraries(${target} PUBLIC Threads::Threads ${CMAKE_THREAD_LIBS_INIT})
266-
else()
267-
target_link_libraries(${target} PRIVATE Threads::Threads ${CMAKE_THREAD_LIBS_INIT})
264+
if(NOT (CMAKE_SYSTEM_NAME STREQUAL "Emscripten"))
265+
if(BUILD_STATIC_LIB)
266+
target_link_libraries(${target} PUBLIC Threads::Threads ${CMAKE_THREAD_LIBS_INIT})
267+
else()
268+
target_link_libraries(${target} PRIVATE Threads::Threads ${CMAKE_THREAD_LIBS_INIT})
269+
endif()
268270
endif()
269271

270272
if(USE_OPENMP)

src/c_api/c_api.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,9 @@ XGB_DLL int XGBoosterLoadModelFromBuffer(BoosterHandle handle, const void *buf,
15791579
API_BEGIN();
15801580
CHECK_HANDLE();
15811581
xgboost_CHECK_C_ARG_PTR(buf);
1582-
auto buffer = common::Span<char const>{static_cast<char const *>(buf), len};
1582+
using CharT = std::add_const_t<char>;
1583+
using IdxType = common::Span<CharT>::index_type;
1584+
auto buffer = common::Span{static_cast<CharT *>(buf), static_cast<IdxType>(len)};
15831585
// Don't warn, we have to guess the format with buffer input.
15841586
auto in = DispatchModelType(buffer, "", false);
15851587
common::MemoryFixSizeBuffer fs((void *)buf, len); // NOLINT(*)

src/common/threading_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void ParallelFor1d(Index size, std::int32_t n_threads, Func&& fn) {
267267
static_assert(std::is_void_v<std::invoke_result_t<Func, common::Range1d>>);
268268
auto const n_blocks = DivRoundUp(size, kBlockOfRowsSize);
269269
common::ParallelFor(n_blocks, n_threads, [&](auto block_id) {
270-
auto const block_beg = block_id * kBlockOfRowsSize;
270+
std::size_t const block_beg = block_id * kBlockOfRowsSize;
271271
auto const block_size = std::min(static_cast<std::size_t>(size - block_beg), kBlockOfRowsSize);
272272
fn(common::Range1d{block_beg, block_beg + block_size});
273273
});

0 commit comments

Comments
 (0)