Bundle wgpu-native into Linux WebGPU amalgamation (#4220)

This commit is contained in:
yuiseki
2026-06-11 20:26:48 +09:00
committed by GitHub
parent 3a7c0a11c2
commit fa8a9c8e32
4 changed files with 71 additions and 10 deletions

27
vendor/wgpu.cmake vendored
View File

@@ -67,15 +67,20 @@ list(APPEND _wgpu_lib_search_paths
"${_mln_wgpu_source_dir}/build/release"
)
# Resolve the exact archive/import library filename emitted by wgpu-native.
macro(mln_wgpu_find_exact_library out_var out_description)
foreach(_search_path ${_wgpu_lib_search_paths})
if(EXISTS "${_search_path}/${_wgpu_lib_name}")
set(${out_var} "${_search_path}/${_wgpu_lib_name}" CACHE FILEPATH "${out_description}")
break()
endif()
endforeach()
endmacro()
# On Android/iOS, use manual path search since find_library may not work with cross-compilation toolchains
macro(mln_wgpu_find_library)
if(ANDROID OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
foreach(_search_path ${_wgpu_lib_search_paths})
if(EXISTS "${_search_path}/${_wgpu_lib_name}")
set(WGPU_LIBRARY "${_search_path}/${_wgpu_lib_name}" CACHE FILEPATH "wgpu-native library")
break()
endif()
endforeach()
mln_wgpu_find_exact_library(WGPU_LIBRARY "wgpu-native library")
else()
find_library(WGPU_LIBRARY
NAMES wgpu_native libwgpu_native
@@ -87,6 +92,7 @@ macro(mln_wgpu_find_library)
endmacro()
mln_wgpu_find_library()
mln_wgpu_find_exact_library(WGPU_STATIC_LIBRARY "wgpu-native static library")
if(NOT WGPU_LIBRARY OR MLN_WGPU_NATIVE_VERSION)
# Use a specific version of WGPU. This is required when to a rust application
@@ -153,6 +159,7 @@ if(NOT WGPU_LIBRARY OR MLN_WGPU_NATIVE_VERSION)
# Try to find the library again
mln_wgpu_find_library()
mln_wgpu_find_exact_library(WGPU_STATIC_LIBRARY "wgpu-native static library")
if(NOT WGPU_LIBRARY)
message(FATAL_ERROR "Failed to locate wgpu-native library after building")
@@ -163,6 +170,14 @@ else()
message(STATUS "Found wgpu-native library: ${WGPU_LIBRARY}")
endif()
if(WGPU_STATIC_LIBRARY)
message(STATUS "Found wgpu-native static library: ${WGPU_STATIC_LIBRARY}")
elseif(MLN_CREATE_AMALGAMATION)
message(FATAL_ERROR
"MLN_CREATE_AMALGAMATION=ON requires a static wgpu-native library, "
"but none was found in: ${_wgpu_lib_search_paths}")
endif()
# Create compatibility shims for Dawn header paths if they don't exist
set(_webgpu-cpp-output_dir "${CMAKE_CURRENT_BINARY_DIR}/webgpu-cpp")
set(_compat_shim_dir "${_webgpu-cpp-output_dir}/webgpu")