Skip to content

Commit 868a467

Browse files
lokokungDawn LUCI CQ
authored andcommitted
[dawn][emscripten] Add bare-bone unit testing for Emscripten bindings.
Change-Id: Id950fa83fc3c36e0433e516f96a6c3acbecc1862 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/211235 Reviewed-by: Corentin Wallez <[email protected]> Reviewed-by: Kai Ninomiya <[email protected]> Commit-Queue: Loko Kung <[email protected]>
1 parent 5418546 commit 868a467

File tree

6 files changed

+413
-10
lines changed

6 files changed

+413
-10
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ set(USE_WAYLAND OFF)
7777
set(USE_X11 OFF)
7878
set(USE_WINDOWS_UI OFF)
7979
set(BUILD_SAMPLES OFF)
80+
set(BUILD_TESTS OFF)
8081
set(TARGET_MACOS OFF)
8182
if (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
8283
# Only the samples are supported for Emscripten at the moment.
8384
# TODO(crbug.com/42240181): Make dawn_end2end_tests work too.
8485
set(ENABLE_EMSCRIPTEN ON)
8586
set(BUILD_SAMPLES ON)
87+
set(BUILD_TESTS ON)
8688
set(ENABLE_NULL OFF)
8789
elseif (WIN32)
8890
set(ENABLE_D3D11 ON)
@@ -174,6 +176,7 @@ option(DAWN_DXC_ENABLE_ASSERTS_IN_NDEBUG "Enable DXC asserts in non-debug builds
174176
option(DAWN_TARGET_MACOS "Manually link Apple core frameworks" ${TARGET_MACOS})
175177

176178
option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
179+
option(DAWN_BUILD_TESTS "Enables building Dawn's tests" ${BUILD_TESTS})
177180
option(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
178181
option(DAWN_ENABLE_SWIFTSHADER "Enables building Swiftshader as part of the build and Vulkan adapter discovery" OFF)
179182
option(DAWN_BUILD_BENCHMARKS "Build Dawn benchmarks" OFF)
@@ -293,6 +296,7 @@ set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "D
293296
set_if_not_defined(DAWN_PROTOBUF_DIR "${DAWN_THIRD_PARTY_DIR}/protobuf" "Directory in which to find protobuf")
294297
set_if_not_defined(DAWN_LPM_DIR "${DAWN_THIRD_PARTY_DIR}/libprotobuf-mutator/src" "Directory in which to find libprotobuf")
295298
set_if_not_defined(DAWN_EMDAWNWEBGPU_DIR "${DAWN_THIRD_PARTY_DIR}/emdawnwebgpu" "Directory in which to find Dawn specific Emscripten bindings")
299+
set_if_not_defined(DAWN_GOOGLETEST_DIR "${DAWN_THIRD_PARTY_DIR}/googletest" "Directory in which to find googletest")
296300

297301
set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
298302
set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/spirv-headers/src" "Directory in which to find SPIRV-Headers")

src/dawn/samples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function(Sample)
7878
if (${DAWN_ENABLE_EMSCRIPTEN})
7979
set_target_properties(${arg_NAME} PROPERTIES
8080
SUFFIX ".html")
81+
target_link_options(${arg_NAME} PUBLIC
82+
# We need JSPI for Future implementation.
83+
"-sJSPI"
84+
)
8185
endif()
8286
target_link_libraries(${arg_NAME} PUBLIC dawn::dawn_sample_utils)
8387
common_compile_options(${arg_NAME})

src/emdawnwebgpu/CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ if (${DAWN_ENABLE_EMSCRIPTEN})
194194
target_link_options(emdawnwebgpu_config INTERFACE
195195
# We are using Dawn-generated bindings, not built-in ones
196196
"-sUSE_WEBGPU=0"
197-
# We need Asyncify for Future implementation.
198-
"-sASYNCIFY=1"
199197
# The JS libraries needed for bindings
200198
"--js-library=${EM_BUILD_GEN_DIR}/library_webgpu_enum_tables.js"
201199
"--js-library=${EM_BUILD_GEN_DIR}/library_webgpu_generated_struct_info.js"
@@ -220,11 +218,34 @@ if (${DAWN_ENABLE_EMSCRIPTEN})
220218
ENABLE_EMSCRIPTEN
221219
HEADER_ONLY
222220
HEADERS
221+
"${EM_BUILD_GEN_DIR}/include/dawn/webgpu_cpp_print.h"
223222
"${EM_BUILD_GEN_DIR}/include/webgpu/webgpu_cpp.h"
224223
"${EM_BUILD_GEN_DIR}/include/webgpu/webgpu_cpp_chained_struct.h"
225224
"${DAWN_INCLUDE_DIR}/webgpu/webgpu_enum_class_bitmasks.h"
226225
DEPENDS
227226
emdawnwebgpu_c
228227
)
229228

229+
if (${DAWN_BUILD_TESTS})
230+
set(emdawnwebgpu_test_sources
231+
"tests/FuturesTests.cpp"
232+
)
233+
add_executable(emdawnwebgpu_tests ${emdawnwebgpu_test_sources})
234+
set_target_properties(emdawnwebgpu_tests PROPERTIES
235+
SUFFIX ".html")
236+
target_link_libraries(
237+
emdawnwebgpu_tests
238+
PUBLIC
239+
dawn::dawn_wgpu_utils
240+
emdawnwebgpu_cpp
241+
gmock_main
242+
)
243+
target_link_options(emdawnwebgpu_tests PUBLIC
244+
# We need ASYNCIFY for Future implementation. Note that for
245+
# some reason, at the moment, these tests do not work with
246+
# JSPI.
247+
"-sASYNCIFY=1"
248+
)
249+
endif()
250+
230251
endif()

0 commit comments

Comments
 (0)