Support for WebGPU backend in iOS SDK, core (#4103)

This commit is contained in:
Birk Skyum
2026-02-28 23:25:19 +01:00
committed by GitHub
parent 57a14cf110
commit 10453c1ec4
23 changed files with 1366 additions and 72 deletions

69
vendor/wgpu.cmake vendored
View File

@@ -25,10 +25,14 @@ endif()
# Platform-specific library names and paths
if(APPLE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
set(_wgpu_lib_arch "aarch64-apple-darwin")
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
include("${CMAKE_CURRENT_LIST_DIR}/wgpu.ios.cmake")
else()
set(_wgpu_lib_arch "x86_64-apple-darwin")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
set(_wgpu_lib_arch "aarch64-apple-darwin")
else()
set(_wgpu_lib_arch "x86_64-apple-darwin")
endif()
endif()
set(_wgpu_lib_name "libwgpu_native.a")
elseif(ANDROID)
@@ -53,24 +57,37 @@ endif()
# Search platform-specific path first to prefer cross-compiled libraries
set(_wgpu_lib_search_paths
"${_mln_wgpu_source_dir}/target/${_wgpu_lib_arch}/release"
)
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
mln_wgpu_ios_append_search_paths(_wgpu_lib_search_paths)
endif()
list(APPEND _wgpu_lib_search_paths
"${_mln_wgpu_source_dir}/target/release"
"${_mln_wgpu_source_dir}/lib"
"${_mln_wgpu_source_dir}/build/release"
)
# On Android, prefer the static library to avoid needing to ship a separate .so
if(ANDROID)
mln_wgpu_android_find_library()
else()
find_library(WGPU_LIBRARY
NAMES wgpu_native libwgpu_native
PATHS ${_wgpu_lib_search_paths}
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
endif()
# 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()
else()
find_library(WGPU_LIBRARY
NAMES wgpu_native libwgpu_native
PATHS ${_wgpu_lib_search_paths}
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
endif()
endmacro()
mln_wgpu_find_library()
# If not found, try to build it using cargo
if(NOT WGPU_LIBRARY)
message(STATUS "Pre-built wgpu-native library not found, attempting to build from source...")
@@ -89,8 +106,22 @@ if(NOT WGPU_LIBRARY)
# Build wgpu-native using cargo
message(STATUS "Building wgpu-native with cargo (this may take a few minutes)...")
# For cross-compilation targets (iOS, Android), pass --target and platform-specific features
set(_cargo_extra_args "")
if(_wgpu_lib_arch AND NOT _wgpu_lib_arch MATCHES "apple-darwin$")
list(APPEND _cargo_extra_args --target ${_wgpu_lib_arch})
endif()
if(_wgpu_cargo_features)
list(APPEND _cargo_extra_args ${_wgpu_cargo_features})
endif()
set(_cargo_env_prefix "")
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
mln_wgpu_ios_setup_cargo_env(_cargo_env_prefix)
endif()
execute_process(
COMMAND ${CARGO_EXECUTABLE} build --release
COMMAND ${_cargo_env_prefix} ${CARGO_EXECUTABLE} build --release ${_cargo_extra_args}
WORKING_DIRECTORY ${_mln_wgpu_source_dir}
RESULT_VARIABLE _cargo_result
OUTPUT_VARIABLE _cargo_output
@@ -105,11 +136,7 @@ if(NOT WGPU_LIBRARY)
endif()
# Try to find the library again
find_library(WGPU_LIBRARY
NAMES wgpu_native libwgpu_native
PATHS ${_wgpu_lib_search_paths}
NO_DEFAULT_PATH
)
mln_wgpu_find_library()
if(NOT WGPU_LIBRARY)
message(FATAL_ERROR "Failed to locate wgpu-native library after building")