From 9c819ae67d17171340f4dda578c3a7726e9b737d Mon Sep 17 00:00:00 2001 From: Elie Michel Date: Wed, 16 Oct 2024 00:43:40 +0200 Subject: [PATCH] Adapt CMakeLists to emscripten --- .github/workflows/cmake.yml | 44 ++++++------------------------------- examples/CMakeLists.txt | 30 +++++++++++++++---------- 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b84508c..6c6b131 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -42,6 +42,13 @@ jobs: - system: MacOS-x64 runner: macos-13 + - system: emscripten + runner: ubuntu-latest + webgpu-backend: EMSCRIPTEN + link-type: STATIC + build-type: Release + cmake-wrapper: emcmake + # Latest version of Dawn to not support static linking exclude: - webgpu-backend: DAWN @@ -109,40 +116,3 @@ jobs: cmake --build build --config ${{ matrix.build-type }} - - # Was too annoying to put emscripten in the matrix, so here it is, on its own: - build-web: - strategy: - fail-fast: false - matrix: - system: [ emscripten ] - build-type: [ Debug, Release ] - emsdk-version: [ 3.1.61 ] - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Install dependencies - if: ${{ matrix.install-deps }} - run: ${{ matrix.install-deps }} - - - name: Setup emscripten - if: ${{ matrix.emsdk-version }} - uses: mymindstorm/setup-emsdk@v14 - with: - version: ${{ matrix.emsdk-version }} - - - name: Configure CMake - run: > - emcmake cmake - -S examples - -B build - -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - - - name: Build - run: > - cmake - --build build - --config ${{ matrix.build-type }} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f22c7b1..9bb8257 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,17 +6,25 @@ include(FetchContent) include(utils.cmake) # Dependencies -FetchContent_Declare( - glfw-light - URL https://eliemichel.github.io/LearnWebGPU/_downloads/6873a344e35ea9f5e4fc7e5cc85d3ab8/glfw-3.4.0-light.zip - URL_HASH MD5=e6684142080457e9227e4f78a6f84fc2 -) -FetchContent_Declare( - webgpu - GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution.git - GIT_TAG 7ed61fb96d972a4c61ccc79af1139eba2a0ce4c4 # fetch -) -FetchContent_MakeAvailable(glfw-light webgpu) +if (NOT EMSCRIPTEN) + FetchContent_Declare( + glfw-light + URL https://eliemichel.github.io/LearnWebGPU/_downloads/6873a344e35ea9f5e4fc7e5cc85d3ab8/glfw-3.4.0-light.zip + URL_HASH MD5=e6684142080457e9227e4f78a6f84fc2 + ) + FetchContent_Declare( + webgpu + GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution.git + GIT_TAG 7ed61fb96d972a4c61ccc79af1139eba2a0ce4c4 # fetch + ) + FetchContent_MakeAvailable(glfw-light webgpu) +else() + # Emscripten has built-in support for GLFW but requires the `-sUSE_GLFW=3` link option: + add_library(glfw-light INTERFACE) + target_link_options(glfw-light INTERFACE -sUSE_GLFW=3) + add_library(webgpu INTERFACE) + target_link_options(webgpu INTERFACE -sUSE_WEBGPU=1) +endif() # The glfw3webgpu target # NB: We specify a second argument only because this is an out-of-tree