react-native-webgpu 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +18 -129
- package/android/cpp/AndroidPlatformContext.h +10 -9
- package/android/src/main/java/com/webgpu/WebGPUModule.java +3 -3
- package/android/src/main/java/com/webgpu/WebGPUVideoPlayer.java +1 -1
- package/apple/ApplePlatformContext.h +2 -1
- package/apple/ApplePlatformContext.mm +2 -2
- package/binaries.json +53 -105
- package/cpp/dawn/common/ExternalTextureParams.h +3 -3
- package/cpp/dawn/include/dawn/dawn_proc.h +53 -0
- package/cpp/dawn/include/dawn/dawn_proc_table.h +329 -0
- package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
- package/cpp/dawn/include/dawn/dawn_version.h +51 -0
- package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
- package/cpp/dawn/include/dawn/native/D3D12Backend.h +104 -0
- package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/DawnNative.h +375 -0
- package/cpp/dawn/include/dawn/native/MetalBackend.h +67 -0
- package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
- package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
- package/cpp/dawn/include/dawn/native/VulkanBackend.h +199 -0
- package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
- package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
- package/cpp/dawn/include/dawn/platform/DawnPlatform.h +210 -0
- package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
- package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
- package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
- package/cpp/dawn/include/dawn/webgpu.h +5119 -0
- package/cpp/dawn/include/dawn/webgpu_cpp.h +10506 -0
- package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2897 -0
- package/cpp/dawn/include/webgpu/webgpu.h +33 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp.h +33 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp_print.h +33 -0
- package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +163 -0
- package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
- package/cpp/rnwgpu/PlatformContext.h +1 -1
- package/cpp/rnwgpu/SurfaceRegistry.h +2 -2
- package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
- package/cpp/rnwgpu/api/RNWebGPU.h +5 -4
- package/lib/commonjs/video.js +8 -4
- package/lib/commonjs/video.js.map +1 -1
- package/lib/module/video.js +6 -2
- package/lib/module/video.js.map +1 -1
- package/lib/typescript/lib/commonjs/video.d.ts +6 -2
- package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
- package/lib/typescript/lib/module/video.d.ts +1 -1
- package/lib/typescript/lib/module/video.d.ts.map +1 -1
- package/lib/typescript/react-native.config.d.ts +1 -0
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +1 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/video.d.ts +7 -3
- package/lib/typescript/src/video.d.ts.map +1 -1
- package/package.json +10 -5
- package/react-native-webgpu.podspec +46 -78
- package/react-native.config.js +9 -6
- package/scripts/apple-binaries-utils.sh +280 -0
- package/scripts/prepare-apple-binaries.sh +309 -0
- package/scripts/spm-plugin.js +130 -0
- package/src/index.tsx +4 -4
- package/src/types.ts +1 -1
- package/src/video.ts +12 -5
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# CocoaPods and RN SwiftPM share this Node-free preparation phase.
|
|
4
|
+
# SDK archives contain static libraries; headers already ship in react-native-webgpu.
|
|
5
|
+
# Nothing compiles here: resolve libraries, update XCFramework slices, then copy
|
|
6
|
+
# the selected SDK's archives into Xcode's library search path.
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
# /bin/bash prepare-apple-binaries.sh --config
|
|
10
|
+
# /bin/bash prepare-apple-binaries.sh --config --spm-package <generated-package>
|
|
11
|
+
# /bin/bash prepare-apple-binaries.sh --output <build-products> --assembly-root <build-intermediates>
|
|
12
|
+
#
|
|
13
|
+
# Xcode environment:
|
|
14
|
+
# PLATFORM_NAME, EFFECTIVE_PLATFORM_NAME, SDK_VARIANT select the SDK/variant.
|
|
15
|
+
# ARCHS, EXCLUDED_ARCHS, ONLY_ACTIVE_ARCH, CURRENT_ARCH, NATIVE_ARCH_ACTUAL
|
|
16
|
+
# select required architectures; metadata may contain additional ones.
|
|
17
|
+
# IPHONEOS_DEPLOYMENT_TARGET, TVOS_DEPLOYMENT_TARGET, MACOSX_DEPLOYMENT_TARGET
|
|
18
|
+
# must meet the selected archive's deployment floor.
|
|
19
|
+
# BUILT_PRODUCTS_DIR and OBJROOT supply default output/assembly directories.
|
|
20
|
+
# ENABLE_USER_SCRIPT_SANDBOXING must be NO on the target running this phase.
|
|
21
|
+
#
|
|
22
|
+
# Overrides:
|
|
23
|
+
# RNSKIA_CACHE_DIR changes the shared download cache (default:
|
|
24
|
+
# ~/Library/Caches/react-native-skia). Version/checksum subdirectories remain.
|
|
25
|
+
# REACT_NATIVE_SKIA_BINARIES_URL changes the release base URL; the installed
|
|
26
|
+
# binaries.json still pins the tag and checksums, including for mirrors.
|
|
27
|
+
# libs/apple, when present, is a read-only local Dawn override.
|
|
28
|
+
set -Eeuo pipefail
|
|
29
|
+
|
|
30
|
+
# MARK: Package paths and shared constants
|
|
31
|
+
|
|
32
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
33
|
+
PACKAGE_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
34
|
+
source "$SCRIPT_DIR/apple-binaries-utils.sh"
|
|
35
|
+
|
|
36
|
+
# MARK: Failure reporting and cleanup
|
|
37
|
+
|
|
38
|
+
# Report the actual command failure before Xcode's generic PhaseScriptExecution error.
|
|
39
|
+
report_failure() {
|
|
40
|
+
local status="$1" line="$2" command="$3"
|
|
41
|
+
if [[ ! -f "$WORK_DIR/failed" ]]; then
|
|
42
|
+
printf 'error: [react-native-webgpu] Preparation failed at line %s (exit %s): %s. Check the diagnostic above, permissions, and free disk space.\n' "$line" "$status" "$command" >&2
|
|
43
|
+
: > "$WORK_DIR/failed"
|
|
44
|
+
fi
|
|
45
|
+
exit "$status"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Release only locks still owned by this process, never a later cache writer.
|
|
49
|
+
cleanup() {
|
|
50
|
+
# Missing pid files are expected for locks released before EXIT. Bash 3.2
|
|
51
|
+
# otherwise inherits ERR into their reads and reports a successful run as failed.
|
|
52
|
+
trap - ERR
|
|
53
|
+
local directory owner entry
|
|
54
|
+
for directory in ${LOCKS[@]+"${LOCKS[@]}"}; do
|
|
55
|
+
owner=$(cat "$directory/pid" 2>/dev/null) || owner=''
|
|
56
|
+
if [[ "$owner" == "$$" ]]; then rm -rf "$directory"; fi
|
|
57
|
+
done
|
|
58
|
+
# Interrupted downloads/copies are temporary. Keep verified cache entries,
|
|
59
|
+
# local overrides, and complete XCFramework slices from earlier builds.
|
|
60
|
+
for entry in ${TEMP_PATHS[@]+"${TEMP_PATHS[@]}"}; do rm -rf "$entry"; done
|
|
61
|
+
rm -rf "$WORK_DIR"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# MARK: Xcode target selection
|
|
65
|
+
|
|
66
|
+
# Sets SDK and REQUESTED_ARCHS from Xcode's expanded architecture settings.
|
|
67
|
+
# Catalyst uses the macOS SDK, but must select iOS/macabi libraries. Exclusions
|
|
68
|
+
# apply before ONLY_ACTIVE_ARCH reduces the request to the current architecture.
|
|
69
|
+
detect_target() {
|
|
70
|
+
SDK="${PLATFORM_NAME:-}"
|
|
71
|
+
if [[ "$SDK" == macosx ]]; then
|
|
72
|
+
SDK=macos
|
|
73
|
+
if [[ "${EFFECTIVE_PLATFORM_NAME:-}" == -maccatalyst || "${SDK_VARIANT:-}" == maccatalyst || "${SDK_VARIANT:-}" == iosmac ]]; then
|
|
74
|
+
SDK=maccatalyst
|
|
75
|
+
fi
|
|
76
|
+
fi
|
|
77
|
+
sdk_descriptor "$SDK" >/dev/null ||
|
|
78
|
+
fail "Unsupported Apple platform '${PLATFORM_NAME:-unset}' (EFFECTIVE_PLATFORM_NAME='${EFFECTIVE_PLATFORM_NAME:-}'). Supported SDKs: ${RNWGPU_SDKS[*]}. Build an Apple target in Xcode."
|
|
79
|
+
local arch excluded skip seen='' active="${CURRENT_ARCH:-}"
|
|
80
|
+
if [[ -z "$active" || "$active" == undefined_arch ]]; then active="${NATIVE_ARCH_ACTUAL:-}"; fi
|
|
81
|
+
REQUESTED_ARCHS=()
|
|
82
|
+
for arch in ${ARCHS:-}; do
|
|
83
|
+
[[ "$arch" =~ ^[A-Za-z0-9_]+$ ]] || fail "Invalid architecture in ARCHS: $arch"
|
|
84
|
+
skip=false
|
|
85
|
+
for excluded in ${EXCLUDED_ARCHS:-}; do
|
|
86
|
+
if [[ "$arch" == "$excluded" ]]; then skip=true; fi
|
|
87
|
+
done
|
|
88
|
+
if [[ "$skip" == false && " $seen " != *" $arch "* ]]; then
|
|
89
|
+
REQUESTED_ARCHS+=("$arch")
|
|
90
|
+
seen="$seen $arch"
|
|
91
|
+
fi
|
|
92
|
+
done
|
|
93
|
+
((${#REQUESTED_ARCHS[@]} > 0)) || fail "Cannot determine Apple architectures from ARCHS='${ARCHS:-}'. Run preparation from an Xcode target."
|
|
94
|
+
if [[ "${ONLY_ACTIVE_ARCH:-NO}" == YES && -n "$active" && " $seen " == *" $active "* ]]; then
|
|
95
|
+
REQUESTED_ARCHS=("$active")
|
|
96
|
+
fi
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
# MARK: CocoaPods and SwiftPM configuration
|
|
100
|
+
|
|
101
|
+
# Plain JSON is consumed by the podspec and the mandatory RN JavaScript adapter.
|
|
102
|
+
# Names are prefixed at staging so they cannot collide with another dependency's
|
|
103
|
+
# libwebgpu_dawn.a in the shared build-products directory.
|
|
104
|
+
print_configuration() {
|
|
105
|
+
local name="${RNWGPU_DAWN_LIBRARY#lib}"
|
|
106
|
+
printf '{"linkNames":["rnwgpu_%s"]}\n' "${name%.a}"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
# Keep generated files stable across repeated SwiftPM autolinking synchronizations.
|
|
110
|
+
write_if_changed() {
|
|
111
|
+
local source="$1" destination="$2"
|
|
112
|
+
if ! cmp -s "$source" "$destination"; then
|
|
113
|
+
mkdir -p "$(dirname "$destination")"
|
|
114
|
+
cp "$source" "$destination"
|
|
115
|
+
fi
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# write_spm_package DIRECTORY: generate a link-settings target, not binaryTargets.
|
|
119
|
+
# SwiftPM resolves this small local package before Xcode knows the selected SDK;
|
|
120
|
+
# the build phase provides its libraries later. Headers stay in react-native-webgpu.
|
|
121
|
+
# Only the RN hook is JavaScript. Package generation and the native phase use shell.
|
|
122
|
+
write_spm_package() {
|
|
123
|
+
local directory="$1" library name
|
|
124
|
+
printf '// Link settings only; Dawn headers ship in react-native-webgpu.\n' > "$WORK_DIR/ReactNativeWebGPUBinaries.h"
|
|
125
|
+
printf '// Propagates static binary link settings to the app.\n' > "$WORK_DIR/link.c"
|
|
126
|
+
cat > "$WORK_DIR/Package.swift" <<'SWIFT'
|
|
127
|
+
// swift-tools-version: 6.0
|
|
128
|
+
// Generated by react-native-webgpu; SDK binaries are prepared by its Xcode phase.
|
|
129
|
+
import PackageDescription
|
|
130
|
+
|
|
131
|
+
let package = Package(
|
|
132
|
+
name: "ReactNativeWebGPUBinaries",
|
|
133
|
+
platforms: [.iOS(.v15), .tvOS(.v15), .macOS(.v14)],
|
|
134
|
+
products: [.library(name: "ReactNativeWebGPUBinaries", targets: ["ReactNativeWebGPUBinaries"])],
|
|
135
|
+
targets: [
|
|
136
|
+
.target(
|
|
137
|
+
name: "ReactNativeWebGPUBinaries",
|
|
138
|
+
path: ".",
|
|
139
|
+
sources: ["link.c"],
|
|
140
|
+
publicHeadersPath: "include",
|
|
141
|
+
linkerSettings: [
|
|
142
|
+
SWIFT
|
|
143
|
+
for library in "${ALL_LIBRARIES[@]}"; do
|
|
144
|
+
name="${library#lib}"
|
|
145
|
+
printf ' .linkedLibrary("rnwgpu_%s"),\n' "${name%.a}" >> "$WORK_DIR/Package.swift"
|
|
146
|
+
done
|
|
147
|
+
cat >> "$WORK_DIR/Package.swift" <<'SWIFT'
|
|
148
|
+
]
|
|
149
|
+
)
|
|
150
|
+
]
|
|
151
|
+
)
|
|
152
|
+
SWIFT
|
|
153
|
+
write_if_changed "$WORK_DIR/Package.swift" "$directory/Package.swift"
|
|
154
|
+
write_if_changed "$WORK_DIR/link.c" "$directory/link.c"
|
|
155
|
+
write_if_changed "$WORK_DIR/ReactNativeWebGPUBinaries.h" "$directory/include/ReactNativeWebGPUBinaries.h"
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
# MARK: Incremental XCFramework assembly
|
|
159
|
+
|
|
160
|
+
# write_xcframework_plist CONTAINER LIBRARY METADATA_ROOT: describe only SDKs
|
|
161
|
+
# already prepared in this build folder. A later SDK appends its own slice.
|
|
162
|
+
# All values written to XML are fixed library/platform names or validated archs.
|
|
163
|
+
# The descriptors come from saved SDK metadata, rather than hardcoded slice names.
|
|
164
|
+
write_xcframework_plist() {
|
|
165
|
+
local container="$1" library="$2" metadata_root="$3" sdk file identifier archs arch
|
|
166
|
+
local ignored platform variant deployment
|
|
167
|
+
{
|
|
168
|
+
cat <<'PLIST'
|
|
169
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
170
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
171
|
+
<plist version="1.0"><dict>
|
|
172
|
+
<key>CFBundlePackageType</key><string>XFWK</string>
|
|
173
|
+
<key>XCFrameworkFormatVersion</key><string>1.0</string>
|
|
174
|
+
<key>AvailableLibraries</key><array>
|
|
175
|
+
PLIST
|
|
176
|
+
for sdk in "${RNWGPU_SDKS[@]}"; do
|
|
177
|
+
file="$metadata_root/$sdk.json"
|
|
178
|
+
[[ -f "$file" ]] || continue
|
|
179
|
+
IFS='|' read -r ignored platform variant deployment <<< "$(sdk_descriptor "$sdk")"
|
|
180
|
+
archs=$(json_strings "$file" architectures)
|
|
181
|
+
identifier="$platform-$(printf '%s\n' "$archs" | LC_ALL=C sort | paste -sd _ -)${variant:+-$variant}"
|
|
182
|
+
printf '<dict><key>LibraryIdentifier</key><string>%s</string>\n' "$identifier"
|
|
183
|
+
printf '<key>LibraryPath</key><string>%s</string>\n' "$library"
|
|
184
|
+
printf '<key>SupportedPlatform</key><string>%s</string>\n' "$platform"
|
|
185
|
+
if [[ -n "$variant" ]]; then printf '<key>SupportedPlatformVariant</key><string>%s</string>\n' "$variant"; fi
|
|
186
|
+
printf '<key>SupportedArchitectures</key><array>\n'
|
|
187
|
+
while IFS= read -r arch; do printf '<string>%s</string>\n' "$arch"; done <<< "$archs"
|
|
188
|
+
printf '</array></dict>\n'
|
|
189
|
+
done
|
|
190
|
+
printf '</array></dict></plist>\n'
|
|
191
|
+
} > "$container/Info.plist"
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
# Clone on APFS where possible; fall back to an ordinary copy on other volumes.
|
|
195
|
+
copy_library() {
|
|
196
|
+
cp -c "$1" "$2" 2>/dev/null || cp -p "$1" "$2"
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
# Update one SDK atomically and retain other SDKs already prepared in this build.
|
|
200
|
+
# Returns the module's CONTAINER_ROOT for the linker staging step.
|
|
201
|
+
# The caller holds the assembly lock across both assembly and linker staging.
|
|
202
|
+
assemble_module() {
|
|
203
|
+
local root="$CONTAINERS/$MODULE" library existing=true temporary previous='' old_archs platform variant ignored deployment
|
|
204
|
+
local signature_file="$CONTAINERS/$MODULE/.slices/$SDK.signature"
|
|
205
|
+
CONTAINER_ROOT="$root"
|
|
206
|
+
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
207
|
+
if [[ ! -f "$root/${library%.a}.xcframework/$META_IDENTIFIER/$library" || ! -f "$root/${library%.a}.xcframework/Info.plist" ]]; then existing=false; fi
|
|
208
|
+
done
|
|
209
|
+
if [[ -f "$signature_file" && "$(cat "$signature_file")" == "$SOURCE_SIGNATURE" && "$existing" == true ]]; then return; fi
|
|
210
|
+
temporary="$root.$$.assemble"
|
|
211
|
+
TEMP_PATHS+=("$temporary")
|
|
212
|
+
mkdir -p "$temporary"
|
|
213
|
+
if [[ -d "$root" ]]; then ditto "$root" "$temporary"; fi
|
|
214
|
+
if [[ -f "$temporary/.slices/$SDK.json" ]]; then
|
|
215
|
+
old_archs=$(json_strings "$temporary/.slices/$SDK.json" architectures)
|
|
216
|
+
IFS='|' read -r ignored platform variant deployment <<< "$(sdk_descriptor "$SDK")"
|
|
217
|
+
previous="$platform-$(printf '%s\n' "$old_archs" | LC_ALL=C sort | paste -sd _ -)${variant:+-$variant}"
|
|
218
|
+
fi
|
|
219
|
+
mkdir -p "$temporary/.slices"
|
|
220
|
+
cp "$SOURCE_DIRECTORY/metadata.json" "$temporary/.slices/$SDK.json"
|
|
221
|
+
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
222
|
+
local container="$temporary/${library%.a}.xcframework"
|
|
223
|
+
if [[ -n "$previous" && "$previous" != "$META_IDENTIFIER" ]]; then rm -rf "$container/$previous"; fi
|
|
224
|
+
mkdir -p "$container/$META_IDENTIFIER"
|
|
225
|
+
copy_library "$SOURCE_DIRECTORY/$library" "$container/$META_IDENTIFIER/$library"
|
|
226
|
+
write_xcframework_plist "$container" "$library" "$temporary/.slices"
|
|
227
|
+
done
|
|
228
|
+
printf '%s\n' "$SOURCE_SIGNATURE" > "$temporary/.slices/$SDK.signature"
|
|
229
|
+
replace_directory "$temporary" "$root"
|
|
230
|
+
note "Prepared $SDK XCFramework slices ($(printf '%s' "$META_ARCHS" | tr '\n' ' '))"
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# MARK: Linker inputs
|
|
234
|
+
|
|
235
|
+
# stage_module: expose the selected slice as librnwgpu_<name>.a in OUTPUT.
|
|
236
|
+
# Static libraries link into the app; XCFramework containers are build inputs,
|
|
237
|
+
# rather than dynamic frameworks copied into the app's Frameworks directory.
|
|
238
|
+
# Build-product stamps include SDK/version/source identity, avoiding equal-size
|
|
239
|
+
# archives from another platform and unnecessary copies on incremental builds.
|
|
240
|
+
stage_module() {
|
|
241
|
+
local library destination temporary stamp="$OUTPUT/.rnwgpu-$MODULE.signature"
|
|
242
|
+
local signature="$SDK:$VERSION:$SOURCE_SIGNATURE" name
|
|
243
|
+
mkdir -p "$OUTPUT"
|
|
244
|
+
for library in "${MODULE_LIBRARIES[@]}"; do
|
|
245
|
+
name="${library#lib}"
|
|
246
|
+
destination="$OUTPUT/librnwgpu_$name"
|
|
247
|
+
if [[ -f "$stamp" && "$(cat "$stamp")" == "$signature" && -f "$destination" ]]; then continue; fi
|
|
248
|
+
temporary="$destination.$$.tmp"
|
|
249
|
+
TEMP_PATHS+=("$temporary")
|
|
250
|
+
copy_library "$CONTAINER_ROOT/${library%.a}.xcframework/$META_IDENTIFIER/$library" "$temporary"
|
|
251
|
+
mv "$temporary" "$destination"
|
|
252
|
+
done
|
|
253
|
+
printf '%s\n' "$signature" > "$stamp"
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
# MARK: Entry point
|
|
257
|
+
|
|
258
|
+
# Configuration mode performs no downloads; native mode requires Xcode settings.
|
|
259
|
+
# Global state is shared with helpers; initialize cleanup ownership before any
|
|
260
|
+
# operation that may fail. CLI arguments override the Xcode directory defaults.
|
|
261
|
+
main() {
|
|
262
|
+
WORK_DIR=$(mktemp -d "${TMPDIR:-/tmp}/rnwgpu-apple.XXXXXX")
|
|
263
|
+
LOCKS=()
|
|
264
|
+
TEMP_PATHS=()
|
|
265
|
+
trap 'report_failure "$?" "$LINENO" "$BASH_COMMAND"' ERR
|
|
266
|
+
trap cleanup EXIT
|
|
267
|
+
trap 'exit 130' INT
|
|
268
|
+
trap 'exit 143' TERM
|
|
269
|
+
local config=false spm_package='' manifest_hash
|
|
270
|
+
OUTPUT="${BUILT_PRODUCTS_DIR:-}"
|
|
271
|
+
ASSEMBLY_ROOT="${OBJROOT:+$OBJROOT/ReactNativeWebGPUBinaries}"
|
|
272
|
+
while (($# > 0)); do
|
|
273
|
+
case "$1" in
|
|
274
|
+
--config) config=true; shift ;;
|
|
275
|
+
--output|--assembly-root|--spm-package)
|
|
276
|
+
(($# > 1)) && [[ -n "$2" ]] || fail "Missing value for $1."
|
|
277
|
+
case "$1" in
|
|
278
|
+
--output) OUTPUT="$2" ;;
|
|
279
|
+
--assembly-root) ASSEMBLY_ROOT="$2" ;;
|
|
280
|
+
--spm-package) spm_package="$2" ;;
|
|
281
|
+
esac
|
|
282
|
+
shift 2 ;;
|
|
283
|
+
*) fail "Unknown preparation option '$1'." ;;
|
|
284
|
+
esac
|
|
285
|
+
done
|
|
286
|
+
if [[ "$config" != true ]]; then detect_target; fi
|
|
287
|
+
load_release
|
|
288
|
+
ALL_LIBRARIES=("$RNWGPU_DAWN_LIBRARY")
|
|
289
|
+
if [[ -n "$spm_package" ]]; then write_spm_package "$spm_package"; fi
|
|
290
|
+
if [[ "$config" == true ]]; then print_configuration; return; fi
|
|
291
|
+
[[ "$OUTPUT" == /* && "$ASSEMBLY_ROOT" == /* ]] || fail 'Missing absolute binary output/build directory. Run preparation from the installed Xcode phase.'
|
|
292
|
+
[[ "${ENABLE_USER_SCRIPT_SANDBOXING:-NO}" != YES ]] || fail 'Binary preparation needs release-cache/build-product access. Set User Script Sandboxing to No on this app target.'
|
|
293
|
+
[[ -f "$PACKAGE_ROOT/cpp/dawn/include/webgpu/webgpu.h" ]] ||
|
|
294
|
+
fail 'Dawn headers are missing from react-native-webgpu. Reinstall it; contributors must run yarn copy-dawn-headers.'
|
|
295
|
+
# Isolate assembly by manifest while retaining other SDKs of the same release.
|
|
296
|
+
manifest_hash=$(hash_file "$MANIFEST")
|
|
297
|
+
CONTAINERS="$ASSEMBLY_ROOT/$VERSION-${manifest_hash:0:16}"
|
|
298
|
+
MODULE=dawn
|
|
299
|
+
MODULE_LIBRARIES=("$RNWGPU_DAWN_LIBRARY")
|
|
300
|
+
resolve_libraries "$SDK"
|
|
301
|
+
acquire_lock "$ASSEMBLY_ROOT.lock"
|
|
302
|
+
assemble_module
|
|
303
|
+
stage_module
|
|
304
|
+
release_lock "$ASSEMBLY_ROOT.lock"
|
|
305
|
+
note "Ready: $SDK (${REQUESTED_ARCHS[*]}); Dawn own"
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
# Sourcing exposes helpers for verification; direct execution prepares binaries.
|
|
309
|
+
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then main "$@"; fi
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// MARK: Autolinking helpers
|
|
4
|
+
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const { execFileSync } = require("child_process");
|
|
8
|
+
|
|
9
|
+
/** Quote a generated path as one shell argument, including spaces/apostrophes. */
|
|
10
|
+
const shellQuote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* RN requires a JavaScript autolinking entry point. It delegates configuration
|
|
14
|
+
* and package generation to Bash; the installed Xcode phase never invokes Node.
|
|
15
|
+
* RN invokes this hook again when it regenerates the autolinked package graph.
|
|
16
|
+
* Configuration reads the installed release pin; binary downloads wait for Xcode
|
|
17
|
+
* to supply the SDK and architecture build settings.
|
|
18
|
+
*/
|
|
19
|
+
module.exports = function webgpuSwiftPM(context) {
|
|
20
|
+
const packageRoot = path.join(__dirname, "..");
|
|
21
|
+
const scriptPath = path.join(__dirname, "prepare-apple-binaries.sh");
|
|
22
|
+
|
|
23
|
+
// MARK: RN hook compatibility
|
|
24
|
+
|
|
25
|
+
// Check the installed hook's capability, rather than assuming a semver string
|
|
26
|
+
// describes it: local RN checkouts and prereleases may carry different tooling.
|
|
27
|
+
// Without scriptPhases, libraries would be linked before they were prepared.
|
|
28
|
+
const contract = path.join(
|
|
29
|
+
context.reactNativeRoot,
|
|
30
|
+
"scripts/spm/autolinking-plugins.js"
|
|
31
|
+
);
|
|
32
|
+
if (
|
|
33
|
+
!fs.existsSync(contract) ||
|
|
34
|
+
!fs.readFileSync(contract, "utf8").includes("scriptPhases")
|
|
35
|
+
) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"react-native-webgpu: automatic SwiftPM binary preparation requires React Native 0.87.1 or newer. Upgrade React Native or use CocoaPods."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// MARK: Generated Dawn link settings
|
|
42
|
+
|
|
43
|
+
// WebGPU always supplies Dawn. Skia's integration opts out of its own copy
|
|
44
|
+
// when this native module is linked; both packages validate the same pin.
|
|
45
|
+
// Configuration writes a local link-settings package, without downloading SDKs.
|
|
46
|
+
execFileSync(
|
|
47
|
+
"/bin/bash",
|
|
48
|
+
[
|
|
49
|
+
scriptPath,
|
|
50
|
+
"--config",
|
|
51
|
+
"--spm-package",
|
|
52
|
+
path.join(context.outputDir, "ReactNativeWebGPUBinaries"),
|
|
53
|
+
],
|
|
54
|
+
{ encoding: "utf8" }
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// MARK: Xcode preparation phase
|
|
58
|
+
|
|
59
|
+
// RN already resolved the package during autolinking. A project-relative path
|
|
60
|
+
// handles hoisting/pnpm and relocation without Node lookups inside Xcode.
|
|
61
|
+
// Resolve symlinks on both sides before computing the path so workspace package
|
|
62
|
+
// aliases do not produce a different path after Xcode expands SRCROOT.
|
|
63
|
+
const relativeScript = shellQuote(
|
|
64
|
+
path.relative(fs.realpathSync(context.appRoot), fs.realpathSync(scriptPath))
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Xcode expands SDK/architecture variables when this phase runs. Cache and
|
|
68
|
+
// assembly logic stays in the shared shell scripts used by CocoaPods too.
|
|
69
|
+
// exec preserves their exit status and error diagnostics in Xcode's build log.
|
|
70
|
+
const script = `set -eo pipefail
|
|
71
|
+
# Check before reading package files, which script sandboxing may already deny.
|
|
72
|
+
if [ "\${ENABLE_USER_SCRIPT_SANDBOXING:-NO}" = YES ]; then
|
|
73
|
+
echo "error: [react-native-webgpu] Set User Script Sandboxing to No on this app target; preparation needs release-cache and build-product access." >&2
|
|
74
|
+
exit 1
|
|
75
|
+
fi
|
|
76
|
+
PREPARE_SCRIPT="$SRCROOT"/${relativeScript}
|
|
77
|
+
if [ ! -f "$PREPARE_SCRIPT" ]; then
|
|
78
|
+
echo "error: [react-native-webgpu] Binary preparation script is missing. Reinstall dependencies and rerun react-native spm update." >&2
|
|
79
|
+
exit 1
|
|
80
|
+
fi
|
|
81
|
+
exec /bin/bash "$PREPARE_SCRIPT" --output "$BUILT_PRODUCTS_DIR" --assembly-root "$OBJROOT/ReactNativeWebGPUBinaries"
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
// MARK: Native package registration
|
|
85
|
+
|
|
86
|
+
// RN delegates the plugin host's native contribution entirely to this hook.
|
|
87
|
+
// Recreate its usual libs/<name> alias so Package.swift's relative React and
|
|
88
|
+
// generated-code dependencies resolve within this app's autolinking tree.
|
|
89
|
+
const packageAlias = path.join(
|
|
90
|
+
context.outputDir,
|
|
91
|
+
"libs",
|
|
92
|
+
"ReactNativeWebGPU"
|
|
93
|
+
);
|
|
94
|
+
fs.mkdirSync(path.dirname(packageAlias), { recursive: true });
|
|
95
|
+
if (!fs.existsSync(packageAlias)) {
|
|
96
|
+
fs.symlinkSync(packageRoot, packageAlias, "dir");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// MARK: RN phase reconciliation and synchronization
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
packageDependencies: [{ name: "ReactNativeWebGPU", path: packageAlias }],
|
|
103
|
+
productDependencies: [
|
|
104
|
+
{ name: "ReactNativeWebGPU", package: "ReactNativeWebGPU" },
|
|
105
|
+
],
|
|
106
|
+
scriptPhases: [
|
|
107
|
+
{
|
|
108
|
+
// RN uses this stable id to update the phase instead of adding duplicates.
|
|
109
|
+
id: "react-native-webgpu.prepare-binaries",
|
|
110
|
+
name: "Prepare React Native WebGPU binaries",
|
|
111
|
+
script,
|
|
112
|
+
// Bundled headers allow package compilation without downloading binaries;
|
|
113
|
+
// prepare libraries before the app's compile/link steps consume them.
|
|
114
|
+
position: "beforeCompile",
|
|
115
|
+
// SDK selection and local overrides are not fixed Xcode input files.
|
|
116
|
+
// Run every build; shell signatures skip unchanged assembly and copies.
|
|
117
|
+
alwaysOutOfDate: true,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
// These trigger RN autolinking regeneration when the pin or adapter changes.
|
|
121
|
+
// They are separate from the preparation phase's own binary/cache checks.
|
|
122
|
+
watchPaths: [
|
|
123
|
+
path.join(packageRoot, "binaries.json"),
|
|
124
|
+
path.join(packageRoot, "Package.swift"),
|
|
125
|
+
__filename,
|
|
126
|
+
scriptPath,
|
|
127
|
+
path.join(__dirname, "apple-binaries-utils.sh"),
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -43,7 +43,7 @@ export type {
|
|
|
43
43
|
GPUSharedTextureMemoryDescriptor,
|
|
44
44
|
GPUSharedTextureMemoryEndAccessState,
|
|
45
45
|
NativeBufferPixelFormat,
|
|
46
|
-
|
|
46
|
+
CreateTestVideoPlayerOptions,
|
|
47
47
|
GPUCopyExternalNativeFrameSourceInfo,
|
|
48
48
|
GPUDawnTogglesDescriptor,
|
|
49
49
|
GPUNativeExternalTextureDescriptor,
|
|
@@ -117,8 +117,8 @@ declare global {
|
|
|
117
117
|
// taking ownership of one reference (pair with producers that return a
|
|
118
118
|
// +1 pointer, e.g. Skia.Image.MakeGPUTextureFromImage()).
|
|
119
119
|
adoptTexture: (pointer: bigint) => GPUTexture;
|
|
120
|
-
// Prefer the
|
|
121
|
-
|
|
120
|
+
// Prefer the createTestVideoPlayer() export, which takes an options object.
|
|
121
|
+
createTestVideoPlayer: (
|
|
122
122
|
source: string,
|
|
123
123
|
pixelFormat?: NativeBufferPixelFormat,
|
|
124
124
|
) => VideoPlayer;
|
|
@@ -185,7 +185,7 @@ declare global {
|
|
|
185
185
|
source: GPUDrawElementImageSource,
|
|
186
186
|
destination: GPUDrawElementImageDestination,
|
|
187
187
|
): Promise<void>;
|
|
188
|
-
// Non-spec extension: a NativeBuffer (from
|
|
188
|
+
// Non-spec extension: a NativeBuffer (from createTestVideoPlayer,
|
|
189
189
|
// createNativeBufferFromPointer or createTestVideoFrame) as the copy
|
|
190
190
|
// source. The frame is rendered into the destination on the GPU through
|
|
191
191
|
// an external texture, which converts YUV to RGB and applies `rotation`
|
package/src/types.ts
CHANGED
|
@@ -171,7 +171,7 @@ export interface GPUCopyExternalNativeFrameSourceInfo {
|
|
|
171
171
|
mirrored?: boolean;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
export interface
|
|
174
|
+
export interface CreateTestVideoPlayerOptions {
|
|
175
175
|
// The layout of the frames on Apple platforms:
|
|
176
176
|
// 'bgra8' (default): single-plane BGRA surfaces, for importSharedTextureMemory
|
|
177
177
|
// and a regular sampled GPUTexture.
|
package/src/video.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CreateNativeBufferOptions,
|
|
3
|
-
|
|
3
|
+
CreateTestVideoPlayerOptions,
|
|
4
4
|
NativeBuffer,
|
|
5
5
|
VideoPlayer,
|
|
6
6
|
} from "./types";
|
|
@@ -17,6 +17,10 @@ const native = (name: string) => {
|
|
|
17
17
|
/**
|
|
18
18
|
* Decodes a video into native frames the GPU samples without any copy.
|
|
19
19
|
*
|
|
20
|
+
* For tests and examples only: video decoding is out of the scope of this
|
|
21
|
+
* library. For video in an app, use a video library and wrap its frames with
|
|
22
|
+
* `createNativeBufferFromPointer()`.
|
|
23
|
+
*
|
|
20
24
|
* `source` is a URL (`http`, `https`, `file`) or a file path. Playback is
|
|
21
25
|
* controlled like an HTMLMediaElement (`play()`, `pause()`, `currentTime`,
|
|
22
26
|
* `loop`, `volume`); frames are pulled with `copyLatestFrame()` on every
|
|
@@ -24,7 +28,7 @@ const native = (name: string) => {
|
|
|
24
28
|
* `importSharedTextureMemory()`:
|
|
25
29
|
*
|
|
26
30
|
* ```ts
|
|
27
|
-
* const player =
|
|
31
|
+
* const player = createTestVideoPlayer(url);
|
|
28
32
|
* player.play();
|
|
29
33
|
* const render = () => {
|
|
30
34
|
* const frame = player.copyLatestFrame();
|
|
@@ -39,11 +43,14 @@ const native = (name: string) => {
|
|
|
39
43
|
* `{ pixelFormat: "nv12" }`. On Android they are always in the decoder's
|
|
40
44
|
* native YUV layout, for `importExternalTexture()`.
|
|
41
45
|
*/
|
|
42
|
-
export const
|
|
46
|
+
export const createTestVideoPlayer = (
|
|
43
47
|
source: string,
|
|
44
|
-
options?:
|
|
48
|
+
options?: CreateTestVideoPlayerOptions,
|
|
45
49
|
): VideoPlayer =>
|
|
46
|
-
native("
|
|
50
|
+
native("createTestVideoPlayer").createTestVideoPlayer(
|
|
51
|
+
source,
|
|
52
|
+
options?.pixelFormat,
|
|
53
|
+
);
|
|
47
54
|
|
|
48
55
|
/**
|
|
49
56
|
* Wraps a native buffer produced by another library (a `CVPixelBufferRef` on
|