| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2025 The Dawn & Tint Authors |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are met: |
| 7 | # |
| 8 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | # list of conditions and the following disclaimer. |
| 10 | # |
| 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer in the documentation |
| 13 | # and/or other materials provided with the distribution. |
| 14 | # |
| 15 | # 3. Neither the name of the copyright holder nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 25 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 26 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 27 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 30 | set -euo pipefail |
| 31 | |
| 32 | # Version format: vYYYYMMDD.HHMMSS or vYYYYMMDD.HHMMSS-FORKOWNER.dawn.BRANCHNAME |
| 33 | VERSION_DATETIME=$(git show -s --date=format:'%Y%m%d.%H%M%S' --format=%cd) |
| 34 | VERSION_SUFFIX=${GITHUB_REPOSITORY/\//.}.${GITHUB_REF_NAME} |
| 35 | if [[ "$VERSION_SUFFIX" != "google.dawn.main" ]] ; then |
| 36 | PKG_VERSION=v${VERSION_DATETIME}-${VERSION_SUFFIX} |
| 37 | else |
| 38 | PKG_VERSION=v${VERSION_DATETIME} |
| 39 | fi |
| 40 | PKG_FILE=emdawnwebgpu_pkg-${PKG_VERSION}.zip |
| Kai Ninomiya | b0a896c | 2025-05-27 16:08:18 -0700 | [diff] [blame] | 41 | REMOTE_PORT_FILE=emdawnwebgpu-${PKG_VERSION}.remoteport.py |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 42 | |
| Kai Ninomiya | 7ec477f | 2025-07-29 10:49:34 -0700 | [diff] [blame] | 43 | # Initialize emsdk so we can use emcmake. Other dependencies wll be downloaded |
| 44 | # later via DAWN_FETCH_DEPENDENCIES (set in dawn-ci.cmake). |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 45 | git submodule update --init --depth=1 third_party/emsdk |
| 46 | python3 tools/activate-emsdk |
| 47 | |
| Kai Ninomiya | 7ec477f | 2025-07-29 10:49:34 -0700 | [diff] [blame] | 48 | # First build the link test in debug mode as a basic test. |
| 49 | third_party/emsdk/upstream/emscripten/emcmake cmake -S=. -B=out/wasm \ |
| 50 | -C=.github/workflows/dawn-ci.cmake \ |
| Kai Ninomiya | c55c052 | 2025-09-16 11:39:19 -0700 | [diff] [blame] | 51 | -DDAWN_ENABLE_INSTALL=0 \ |
| Kai Ninomiya | 7ec477f | 2025-07-29 10:49:34 -0700 | [diff] [blame] | 52 | -DCMAKE_BUILD_TYPE=Debug |
| 53 | make -j4 -C out/wasm emdawnwebgpu_link_test |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 54 | |
| Kai Ninomiya | 6cdc708 | 2025-10-10 13:05:41 -0700 | [diff] [blame] | 55 | # Switch the build type (in-place to save time), rebuild the link test and a C++ |
| 56 | # sample (to verify webgpu_cpp.h builds and to run Closure, which verifies the |
| 57 | # linked JS to some extent), and build the final package (which is not actually |
| 58 | # affected by build type). |
| Kai Ninomiya | 7e39f3b | 2025-08-01 17:34:07 -0700 | [diff] [blame] | 59 | # TODO: If we have Ninja (from depot_tools), we could use -G'Ninja Multi-Config' |
| 60 | # to do multiple build types more cleanly. |
| 61 | # https://cmake.org/cmake/help/latest/generator/Ninja%20Multi-Config.html |
| Kai Ninomiya | 7ec477f | 2025-07-29 10:49:34 -0700 | [diff] [blame] | 62 | cmake -S=. -B=out/wasm -DCMAKE_BUILD_TYPE=Release |
| Kai Ninomiya | 6cdc708 | 2025-10-10 13:05:41 -0700 | [diff] [blame] | 63 | make -j4 -C out/wasm emdawnwebgpu_pkg emdawnwebgpu_link_test HelloTriangle |
| Kai Ninomiya | 616a406 | 2025-05-20 19:58:42 -0700 | [diff] [blame] | 64 | |
| Kai Ninomiya | 46621a3 | 2025-05-27 11:47:59 -0700 | [diff] [blame] | 65 | # Get variables for documentation. |
| 66 | SHA=$(git rev-parse HEAD) |
| 67 | EMSDK_VERSION=$(python3 tools/activate-emsdk --get-emsdk-version) |
| 68 | |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 69 | # Create zip |
| 70 | cat << EOF > out/wasm/emdawnwebgpu_pkg/VERSION.txt |
| Kai Ninomiya | b0a896c | 2025-05-27 16:08:18 -0700 | [diff] [blame] | 71 | Dawn release ${PKG_VERSION} at revision <https://dawn.googlesource.com/dawn/+log/${SHA}>. |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 72 | EOF |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 73 | (cd out/wasm && zip -9roX - emdawnwebgpu_pkg > "../../${PKG_FILE}") |
| 74 | PKG_FILE_SHA512=$(python3 -c 'import hashlib, sys; print(hashlib.sha512(sys.stdin.buffer.read()).hexdigest())' < "${PKG_FILE}") |
| 75 | |
| 76 | cat << EOF > "$REMOTE_PORT_FILE" |
| 77 | # Copyright 2025 The Emscripten Authors. All rights reserved. |
| 78 | # Emscripten is available under two separate licenses, the MIT license and the |
| 79 | # University of Illinois/NCSA Open Source License. Both these licenses can be |
| 80 | # found in the LICENSE file. |
| 81 | |
| Kai Ninomiya | 6b425c7 | 2025-06-03 14:17:44 -0700 | [diff] [blame] | 82 | # https://dawn.googlesource.com/dawn/+/${SHA}/src/emdawnwebgpu/pkg/README.md |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 83 | r""" |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 84 | This "remote port" instructs Emscripten (4.0.10+) how to automatically download |
| 85 | the actual port for Emdawnwebgpu. See README below for instructions. |
| Kai Ninomiya | 5366e67 | 2025-08-06 18:47:46 -0700 | [diff] [blame] | 86 | |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 87 | $(cat out/wasm/emdawnwebgpu_pkg/README.md) |
| 88 | """ |
| 89 | |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 90 | import sys |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 91 | |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 92 | if __name__ == '__main__': |
| 93 | print('Please see documentation inside this file for details on how to use this port.') |
| 94 | sys.exit(1) |
| 95 | |
| 96 | _VERSION = '${PKG_VERSION}' |
| 97 | |
| 98 | # Remote-specific port information |
| 99 | |
| 100 | # - Where to download the port |
| 101 | EXTERNAL_PORT = f'https://github.com/${GITHUB_REPOSITORY}/releases/download/{_VERSION}/emdawnwebgpu_pkg-{_VERSION}.zip' |
| 102 | # - Hash to verify the download integrity |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 103 | SHA512 = '${PKG_FILE_SHA512}' |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 104 | # - Path of the port inside the zip file |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 105 | PORT_FILE = 'emdawnwebgpu_pkg/emdawnwebgpu.port.py' |
| 106 | |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 107 | # General port information |
| Kai Ninomiya | 6b425c7 | 2025-06-03 14:17:44 -0700 | [diff] [blame] | 108 | |
| 109 | # - Visible in emcc --show-ports and emcc --use-port=emdawnwebgpu:help |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 110 | LICENSE = "Some files: BSD 3-Clause License. Other files: Emscripten's license (available under both MIT License and University of Illinois/NCSA Open Source License)" |
| Kai Ninomiya | 6b425c7 | 2025-06-03 14:17:44 -0700 | [diff] [blame] | 111 | |
| 112 | # - Visible in emcc --use-port=emdawnwebgpu:help |
| 113 | DESCRIPTION = "Emdawnwebgpu implements webgpu.h on WebGPU, replacing -sUSE_WEBGPU. **For info on usage and filing feedback, see link below.**" |
| 114 | URL = 'https://dawn.googlesource.com/dawn/+/${SHA}/src/emdawnwebgpu/pkg/README.md' |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 115 | |
| Kai Ninomiya | a3650c0 | 2025-10-02 12:13:53 -0700 | [diff] [blame] | 116 | |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 117 | # Emscripten <4.0.10 won't notice EXTERNAL_PORT and will try to use this. |
| 118 | def get(ports, settings, shared): |
| 119 | raise Exception('Remote ports require Emscripten 4.0.10+.') |
| Kai Ninomiya | a3650c0 | 2025-10-02 12:13:53 -0700 | [diff] [blame] | 120 | |
| 121 | |
| 122 | # (Make this look like a port so that the error message above can be hit.) |
| Kai Ninomiya | bd3f983 | 2025-09-16 13:18:54 -0700 | [diff] [blame] | 123 | def clear(ports, settings, shared): |
| 124 | pass |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 125 | EOF |
| 126 | |
| 127 | # Create RELEASE_INFO.md |
| Kai Ninomiya | 2d7bdf1 | 2026-01-05 00:45:09 -0800 | [diff] [blame] | 128 | # TODO(crbug.com/430624000): This is not specific to Emdawnwebgpu, move it |
| 129 | # out of this script, and ideally include it in every release artifact. |
| 130 | # (Also rename release artifacts for consistency.) |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 131 | cat << EOF > RELEASE_INFO.md |
| 132 | $(cat out/wasm/emdawnwebgpu_pkg/VERSION.txt) |
| 133 | |
| Kai Ninomiya | 2d7bdf1 | 2026-01-05 00:45:09 -0800 | [diff] [blame] | 134 | Only dawn.googlesource.com Git source code is official. Nightly releases of |
| 135 | native binaries and Emdawnwebgpu are built on GitHub, provided as a best-effort |
| 136 | service. They are not signed or guaranteed by Google or the Dawn team. |
| 137 | |
| 138 | ## Emdawnwebgpu |
| 139 | |
| Kai Ninomiya | b0a896c | 2025-05-27 16:08:18 -0700 | [diff] [blame] | 140 | Use either the \`emdawnwebgpu-*.remoteport.py\` file (Emscripten 4.0.10+) or the \`emdawnwebgpu_pkg-*.zip\`. |
| 141 | For full instructions, see the [README](https://dawn.googlesource.com/dawn/+/${SHA}/src/emdawnwebgpu/pkg/README.md) which is included in both files. |
| Kai Ninomiya | 2d7bdf1 | 2026-01-05 00:45:09 -0800 | [diff] [blame] | 142 | |
| 143 | Tested against emsdk release ${EMSDK_VERSION}. |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 144 | EOF |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 145 | |
| 146 | # Save version numbers for later steps |
| 147 | if [[ -n "${GITHUB_OUTPUT:-}" ]] ; then |
| 148 | echo "PKG_VERSION=$PKG_VERSION" >> $GITHUB_OUTPUT |
| 149 | echo "PKG_FILE=$PKG_FILE" >> $GITHUB_OUTPUT |
| Kai Ninomiya | bd375f5 | 2025-05-21 15:27:36 -0700 | [diff] [blame] | 150 | echo "REMOTE_PORT_FILE=$REMOTE_PORT_FILE" >> $GITHUB_OUTPUT |
| Kai Ninomiya | 5ef1395 | 2025-04-22 21:11:49 -0700 | [diff] [blame] | 151 | fi |