blob: c4e72a4efbb9ea5de034026d4db626b230ab79f2 [file] [log] [blame]
Kai Ninomiya5ef13952025-04-22 21:11:49 -07001#!/bin/bash
Kai Ninomiyabd375f52025-05-21 15:27:36 -07002#
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 Ninomiya5ef13952025-04-22 21:11:49 -070030set -euo pipefail
31
32# Version format: vYYYYMMDD.HHMMSS or vYYYYMMDD.HHMMSS-FORKOWNER.dawn.BRANCHNAME
33VERSION_DATETIME=$(git show -s --date=format:'%Y%m%d.%H%M%S' --format=%cd)
34VERSION_SUFFIX=${GITHUB_REPOSITORY/\//.}.${GITHUB_REF_NAME}
35if [[ "$VERSION_SUFFIX" != "google.dawn.main" ]] ; then
36 PKG_VERSION=v${VERSION_DATETIME}-${VERSION_SUFFIX}
37else
38 PKG_VERSION=v${VERSION_DATETIME}
39fi
40PKG_FILE=emdawnwebgpu_pkg-${PKG_VERSION}.zip
Kai Ninomiyab0a896c2025-05-27 16:08:18 -070041REMOTE_PORT_FILE=emdawnwebgpu-${PKG_VERSION}.remoteport.py
Kai Ninomiya5ef13952025-04-22 21:11:49 -070042
Kai Ninomiya7ec477f2025-07-29 10:49:34 -070043# Initialize emsdk so we can use emcmake. Other dependencies wll be downloaded
44# later via DAWN_FETCH_DEPENDENCIES (set in dawn-ci.cmake).
Kai Ninomiya5ef13952025-04-22 21:11:49 -070045git submodule update --init --depth=1 third_party/emsdk
46python3 tools/activate-emsdk
47
Kai Ninomiya7ec477f2025-07-29 10:49:34 -070048# First build the link test in debug mode as a basic test.
49third_party/emsdk/upstream/emscripten/emcmake cmake -S=. -B=out/wasm \
50 -C=.github/workflows/dawn-ci.cmake \
Kai Ninomiyac55c0522025-09-16 11:39:19 -070051 -DDAWN_ENABLE_INSTALL=0 \
Kai Ninomiya7ec477f2025-07-29 10:49:34 -070052 -DCMAKE_BUILD_TYPE=Debug
53make -j4 -C out/wasm emdawnwebgpu_link_test
Kai Ninomiya5ef13952025-04-22 21:11:49 -070054
Kai Ninomiya6cdc7082025-10-10 13:05:41 -070055# 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 Ninomiya7e39f3b2025-08-01 17:34:07 -070059# 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 Ninomiya7ec477f2025-07-29 10:49:34 -070062cmake -S=. -B=out/wasm -DCMAKE_BUILD_TYPE=Release
Kai Ninomiya6cdc7082025-10-10 13:05:41 -070063make -j4 -C out/wasm emdawnwebgpu_pkg emdawnwebgpu_link_test HelloTriangle
Kai Ninomiya616a4062025-05-20 19:58:42 -070064
Kai Ninomiya46621a32025-05-27 11:47:59 -070065# Get variables for documentation.
66SHA=$(git rev-parse HEAD)
67EMSDK_VERSION=$(python3 tools/activate-emsdk --get-emsdk-version)
68
Kai Ninomiya5ef13952025-04-22 21:11:49 -070069# Create zip
70cat << EOF > out/wasm/emdawnwebgpu_pkg/VERSION.txt
Kai Ninomiyab0a896c2025-05-27 16:08:18 -070071Dawn release ${PKG_VERSION} at revision <https://dawn.googlesource.com/dawn/+log/${SHA}>.
Kai Ninomiya5ef13952025-04-22 21:11:49 -070072EOF
Kai Ninomiyabd375f52025-05-21 15:27:36 -070073(cd out/wasm && zip -9roX - emdawnwebgpu_pkg > "../../${PKG_FILE}")
74PKG_FILE_SHA512=$(python3 -c 'import hashlib, sys; print(hashlib.sha512(sys.stdin.buffer.read()).hexdigest())' < "${PKG_FILE}")
75
76cat << 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 Ninomiya6b425c72025-06-03 14:17:44 -070082# https://dawn.googlesource.com/dawn/+/${SHA}/src/emdawnwebgpu/pkg/README.md
Kai Ninomiyabd375f52025-05-21 15:27:36 -070083r"""
Kai Ninomiyabd3f9832025-09-16 13:18:54 -070084This "remote port" instructs Emscripten (4.0.10+) how to automatically download
85the actual port for Emdawnwebgpu. See README below for instructions.
Kai Ninomiya5366e672025-08-06 18:47:46 -070086
Kai Ninomiyabd375f52025-05-21 15:27:36 -070087$(cat out/wasm/emdawnwebgpu_pkg/README.md)
88"""
89
Kai Ninomiyabd3f9832025-09-16 13:18:54 -070090import sys
Kai Ninomiyabd375f52025-05-21 15:27:36 -070091
Kai Ninomiyabd3f9832025-09-16 13:18:54 -070092if __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
101EXTERNAL_PORT = f'https://github.com/${GITHUB_REPOSITORY}/releases/download/{_VERSION}/emdawnwebgpu_pkg-{_VERSION}.zip'
102# - Hash to verify the download integrity
Kai Ninomiyabd375f52025-05-21 15:27:36 -0700103SHA512 = '${PKG_FILE_SHA512}'
Kai Ninomiyabd3f9832025-09-16 13:18:54 -0700104# - Path of the port inside the zip file
Kai Ninomiyabd375f52025-05-21 15:27:36 -0700105PORT_FILE = 'emdawnwebgpu_pkg/emdawnwebgpu.port.py'
106
Kai Ninomiyabd3f9832025-09-16 13:18:54 -0700107# General port information
Kai Ninomiya6b425c72025-06-03 14:17:44 -0700108
109# - Visible in emcc --show-ports and emcc --use-port=emdawnwebgpu:help
Kai Ninomiyabd375f52025-05-21 15:27:36 -0700110LICENSE = "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 Ninomiya6b425c72025-06-03 14:17:44 -0700111
112# - Visible in emcc --use-port=emdawnwebgpu:help
113DESCRIPTION = "Emdawnwebgpu implements webgpu.h on WebGPU, replacing -sUSE_WEBGPU. **For info on usage and filing feedback, see link below.**"
114URL = 'https://dawn.googlesource.com/dawn/+/${SHA}/src/emdawnwebgpu/pkg/README.md'
Kai Ninomiyabd3f9832025-09-16 13:18:54 -0700115
Kai Ninomiyaa3650c02025-10-02 12:13:53 -0700116
Kai Ninomiyabd3f9832025-09-16 13:18:54 -0700117# Emscripten <4.0.10 won't notice EXTERNAL_PORT and will try to use this.
118def get(ports, settings, shared):
119 raise Exception('Remote ports require Emscripten 4.0.10+.')
Kai Ninomiyaa3650c02025-10-02 12:13:53 -0700120
121
122# (Make this look like a port so that the error message above can be hit.)
Kai Ninomiyabd3f9832025-09-16 13:18:54 -0700123def clear(ports, settings, shared):
124 pass
Kai Ninomiyabd375f52025-05-21 15:27:36 -0700125EOF
126
127# Create RELEASE_INFO.md
Kai Ninomiya2d7bdf12026-01-05 00:45:09 -0800128# 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 Ninomiyabd375f52025-05-21 15:27:36 -0700131cat << EOF > RELEASE_INFO.md
132$(cat out/wasm/emdawnwebgpu_pkg/VERSION.txt)
133
Kai Ninomiya2d7bdf12026-01-05 00:45:09 -0800134Only dawn.googlesource.com Git source code is official. Nightly releases of
135native binaries and Emdawnwebgpu are built on GitHub, provided as a best-effort
136service. They are not signed or guaranteed by Google or the Dawn team.
137
138## Emdawnwebgpu
139
Kai Ninomiyab0a896c2025-05-27 16:08:18 -0700140Use either the \`emdawnwebgpu-*.remoteport.py\` file (Emscripten 4.0.10+) or the \`emdawnwebgpu_pkg-*.zip\`.
141For full instructions, see the [README](https://dawn.googlesource.com/dawn/+/${SHA}/src/emdawnwebgpu/pkg/README.md) which is included in both files.
Kai Ninomiya2d7bdf12026-01-05 00:45:09 -0800142
143Tested against emsdk release ${EMSDK_VERSION}.
Kai Ninomiyabd375f52025-05-21 15:27:36 -0700144EOF
Kai Ninomiya5ef13952025-04-22 21:11:49 -0700145
146# Save version numbers for later steps
147if [[ -n "${GITHUB_OUTPUT:-}" ]] ; then
148 echo "PKG_VERSION=$PKG_VERSION" >> $GITHUB_OUTPUT
149 echo "PKG_FILE=$PKG_FILE" >> $GITHUB_OUTPUT
Kai Ninomiyabd375f52025-05-21 15:27:36 -0700150 echo "REMOTE_PORT_FILE=$REMOTE_PORT_FILE" >> $GITHUB_OUTPUT
Kai Ninomiya5ef13952025-04-22 21:11:49 -0700151fi