Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions backends/webgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ target_include_directories(

target_link_libraries(webgpu_backend PRIVATE vulkan_schema executorch_core)

# Native WebGPU backend: Dawn (Tint) + SwiftShader; deps script sets Dawn_DIR.
# Native-only: browser/Emscripten builds use the system webgpu.h and never reach
# this find_package (root CMake gates it via EXECUTORCH_BUILD_WEBGPU).
# dawn::webgpu_dawn's link interface references Threads::Threads.
find_package(Threads REQUIRED)
find_package(Dawn REQUIRED)
set(WEBGPU_GPU_LIB dawn::webgpu_dawn)
target_link_libraries(webgpu_backend PUBLIC ${WEBGPU_GPU_LIB})

if(APPLE)
target_link_libraries(
webgpu_backend PRIVATE "-framework Metal" "-framework QuartzCore"
"-framework CoreGraphics" "-framework Foundation"
)
# WASM gets its WebGPU implementation from emdawnwebgpu at executable link time.
# Native builds link Dawn (Tint) and the platform GPU libraries.
if(EMSCRIPTEN)
target_compile_options(webgpu_backend PUBLIC "--use-port=emdawnwebgpu")
# --use-port is also required at link time: the link step pulls in the port's
# headers, JS glue, and libraries for consumers that link webgpu_backend.
target_link_options(webgpu_backend PUBLIC "--use-port=emdawnwebgpu")
else()
target_link_libraries(webgpu_backend PRIVATE dl m pthread)
find_package(Threads REQUIRED)
find_package(Dawn REQUIRED)
set(WEBGPU_GPU_LIB dawn::webgpu_dawn)
target_link_libraries(webgpu_backend PUBLIC ${WEBGPU_GPU_LIB})

if(APPLE)
target_link_libraries(
webgpu_backend PRIVATE "-framework Metal" "-framework QuartzCore"
"-framework CoreGraphics" "-framework Foundation"
)
else()
target_link_libraries(webgpu_backend PRIVATE dl m pthread)
endif()
endif()

target_compile_options(webgpu_backend PRIVATE -fexceptions)
Expand Down
25 changes: 25 additions & 0 deletions backends/webgpu/test/test_cmake_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import pathlib
import unittest


class TestCMakeConfiguration(unittest.TestCase):
def test_emscripten_uses_port_instead_of_native_dawn(self) -> None:
cmake = pathlib.Path(__file__).parents[1] / "CMakeLists.txt"
source = cmake.read_text()
wasm_branch = """if(EMSCRIPTEN)
target_compile_options(webgpu_backend PUBLIC \"--use-port=emdawnwebgpu\")
target_link_options(webgpu_backend PUBLIC \"--use-port=emdawnwebgpu\")
else()"""

self.assertIn(wasm_branch, source)
# Dawn is linked only in the native (else) branch, never under EMSCRIPTEN.
# Split on the branch head so the assertion does not depend on which
# endif() (the nested APPLE one vs the outer one) appears first.
native_branch = source.split(wasm_branch, 1)[1]
self.assertIn("find_package(Dawn REQUIRED)", native_branch)
Loading