From fa8a9c8e3261ce64940127aecc1d52f540c21c57 Mon Sep 17 00:00:00 2001 From: yuiseki Date: Thu, 11 Jun 2026 20:26:48 +0900 Subject: [PATCH] Bundle wgpu-native into Linux WebGPU amalgamation (#4220) --- .github/scripts/check-linux-webgpu-amalgam | 29 ++++++++++++++++++++++ .github/workflows/core-release.yml | 18 +++++++++++--- platform/linux/linux.cmake | 7 ++++++ vendor/wgpu.cmake | 27 +++++++++++++++----- 4 files changed, 71 insertions(+), 10 deletions(-) create mode 100755 .github/scripts/check-linux-webgpu-amalgam diff --git a/.github/scripts/check-linux-webgpu-amalgam b/.github/scripts/check-linux-webgpu-amalgam new file mode 100755 index 000000000..353c60f0c --- /dev/null +++ b/.github/scripts/check-linux-webgpu-amalgam @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Linux-only helper: requires GNU nm long options. +set -euo pipefail + +if [[ $# -ne 1 ]]; then + echo "usage: $0 " >&2 + exit 1 +fi + +archive_path="$1" + +if [[ ! -f "$archive_path" ]]; then + echo "archive not found: $archive_path" >&2 + exit 1 +fi + +unresolved_symbols="$( + nm -g --undefined-only "$archive_path" \ + | grep -E '(^|[[:space:]])U[[:space:]]+wgpu([A-Z]|_)' \ + || true +)" + +if [[ -n "$unresolved_symbols" ]]; then + echo "found unresolved WebGPU symbols in $archive_path" >&2 + echo "$unresolved_symbols" >&2 + exit 1 +fi + +echo "no unresolved WebGPU symbols found in $archive_path" diff --git a/.github/workflows/core-release.yml b/.github/workflows/core-release.yml index 5d0bdb041..8c07dfa93 100644 --- a/.github/workflows/core-release.yml +++ b/.github/workflows/core-release.yml @@ -85,6 +85,8 @@ jobs: build-linux: needs: [create-release] runs-on: ${{ matrix.runner.os }} + env: + PRESET_RENDERER: ${{ matrix.preset_renderer || matrix.renderer }} strategy: matrix: include: @@ -92,6 +94,9 @@ jobs: runner: { os: ubuntu-latest, arch: x64 } - renderer: vulkan runner: { os: ubuntu-latest, arch: x64 } + - renderer: wgpu + preset_renderer: webgpu-wgpu + runner: { os: ubuntu-latest, arch: x64 } - renderer: opengl runner: { os: ubuntu-24.04-arm, arch: arm64 } - renderer: vulkan @@ -110,13 +115,18 @@ jobs: - name: Build mbgl-core for Linux run: | - cmake --preset linux-${{ matrix.renderer }} -DCMAKE_CXX_COMPILER_LAUNCHER="" -DMLN_CREATE_AMALGAMATION=ON - cmake --build build-linux-${{ matrix.renderer }} --target mbgl-core + cmake --preset "linux-${PRESET_RENDERER}" -DCMAKE_CXX_COMPILER_LAUNCHER="" -DMLN_CREATE_AMALGAMATION=ON + cmake --build "build-linux-${PRESET_RENDERER}" --target mbgl-core + + - name: Verify Linux WebGPU amalgamation + if: matrix.renderer == 'wgpu' + run: | + .github/scripts/check-linux-webgpu-amalgam "build-linux-${PRESET_RENDERER}/libmbgl-core-amalgam.a" - name: Rename artifact run: | - cp build-linux-${{ matrix.renderer }}/libmbgl-core.a libmaplibre-native-core-linux-${{ matrix.runner.arch }}-${{ matrix.renderer }}.a - cp build-linux-${{ matrix.renderer }}/libmbgl-core-amalgam.a libmaplibre-native-core-amalgam-linux-${{ matrix.runner.arch }}-${{ matrix.renderer }}.a + cp "build-linux-${PRESET_RENDERER}/libmbgl-core.a" "libmaplibre-native-core-linux-${{ matrix.runner.arch }}-${{ matrix.renderer }}.a" + cp "build-linux-${PRESET_RENDERER}/libmbgl-core-amalgam.a" "libmaplibre-native-core-amalgam-linux-${{ matrix.runner.arch }}-${{ matrix.renderer }}.a" - name: Upload Linux artifacts if: github.event_name == 'pull_request' diff --git a/platform/linux/linux.cmake b/platform/linux/linux.cmake index f1aae1b20..2cfa07651 100644 --- a/platform/linux/linux.cmake +++ b/platform/linux/linux.cmake @@ -208,6 +208,13 @@ if(MLN_CREATE_AMALGAMATION) find_static_library(STATIC_LIBS NAMES GenericCodeGen) endif() + if(MLN_WITH_WEBGPU AND MLN_WEBGPU_IMPL_WGPU) + if(NOT WGPU_STATIC_LIBRARY) + message(FATAL_ERROR "Linux WebGPU amalgamation requires WGPU_STATIC_LIBRARY") + endif() + list(APPEND STATIC_LIBS "${WGPU_STATIC_LIBRARY}") + endif() + add_custom_command( TARGET mbgl-core POST_BUILD diff --git a/vendor/wgpu.cmake b/vendor/wgpu.cmake index 221c7af6a..385b32b75 100644 --- a/vendor/wgpu.cmake +++ b/vendor/wgpu.cmake @@ -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")