react-native-webgpu 0.12.1 → 0.13.1

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.
Files changed (94) hide show
  1. package/Package.swift +86 -56
  2. package/android/CMakeLists.txt +10 -4
  3. package/android/build.gradle +23 -0
  4. package/cpp/rnwgpu/SurfaceRegistry.h +2 -2
  5. package/lib/commonjs/install.js +6 -7
  6. package/lib/commonjs/install.js.map +1 -1
  7. package/lib/module/install.js +6 -7
  8. package/lib/module/install.js.map +1 -1
  9. package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
  10. package/lib/typescript/lib/module/install.d.ts.map +1 -1
  11. package/lib/typescript/src/install.d.ts +6 -7
  12. package/lib/typescript/src/install.d.ts.map +1 -1
  13. package/package.json +5 -7
  14. package/react-native-webgpu.podspec +38 -2
  15. package/src/install.ts +6 -7
  16. package/cpp/webgpu/webgpu.h +0 -5063
  17. package/cpp/webgpu/webgpu_cpp.h +0 -10401
  18. package/cpp/webgpu/webgpu_cpp_chained_struct.h +0 -57
  19. package/cpp/webgpu/webgpu_cpp_print.h +0 -2868
  20. package/cpp/webgpu/webgpu_enum_class_bitmasks.h +0 -163
  21. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  22. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  23. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  24. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  25. package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +0 -65
  26. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/dawn_proc_table.h +0 -329
  27. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/native/DawnNative.h +0 -367
  28. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/native/NullBackend.h +0 -39
  29. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/native/OpenGLBackend.h +0 -89
  30. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/native/VulkanBackend.h +0 -183
  31. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/native/dawn_native_export.h +0 -49
  32. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/webgpu.h +0 -5063
  33. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/webgpu.ixx +0 -358
  34. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/webgpu_cpp.h +0 -10401
  35. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/webgpu_cpp_print.h +0 -2868
  36. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/wire/client/webgpu.h +0 -369
  37. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/wire/client/webgpu_cpp.h +0 -10584
  38. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/dawn/wire/client/webgpu_cpp_print.h +0 -2868
  39. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu/webgpu.h +0 -33
  40. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu/webgpu_cpp.h +0 -33
  41. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu/webgpu_cpp_chained_struct.h +0 -57
  42. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu/webgpu_cpp_print.h +0 -33
  43. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu/webgpu_enum_class_bitmasks.h +0 -163
  44. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu_upstream/webgpu/webgpu_cpp.h +0 -5932
  45. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu_upstream/webgpu/webgpu_cpp_chained_struct.h +0 -54
  46. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu_upstream/webgpu/webgpu_cpp_print.h +0 -2059
  47. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/Headers/webgpu_upstream/webgpu/webgpu_enum_class_bitmasks.h +0 -163
  48. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  49. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/dawn_proc_table.h +0 -329
  50. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/native/DawnNative.h +0 -367
  51. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/native/NullBackend.h +0 -39
  52. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/native/OpenGLBackend.h +0 -89
  53. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/native/VulkanBackend.h +0 -183
  54. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/native/dawn_native_export.h +0 -49
  55. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/webgpu.h +0 -5063
  56. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/webgpu.ixx +0 -358
  57. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/webgpu_cpp.h +0 -10401
  58. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/webgpu_cpp_print.h +0 -2868
  59. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/wire/client/webgpu.h +0 -369
  60. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/wire/client/webgpu_cpp.h +0 -10584
  61. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/dawn/wire/client/webgpu_cpp_print.h +0 -2868
  62. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu/webgpu.h +0 -33
  63. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu/webgpu_cpp.h +0 -33
  64. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu/webgpu_cpp_chained_struct.h +0 -57
  65. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu/webgpu_cpp_print.h +0 -33
  66. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu/webgpu_enum_class_bitmasks.h +0 -163
  67. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu_upstream/webgpu/webgpu_cpp.h +0 -5932
  68. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu_upstream/webgpu/webgpu_cpp_chained_struct.h +0 -54
  69. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu_upstream/webgpu/webgpu_cpp_print.h +0 -2059
  70. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/Headers/webgpu_upstream/webgpu/webgpu_enum_class_bitmasks.h +0 -163
  71. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -4
  72. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/dawn_proc_table.h +0 -329
  73. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/native/DawnNative.h +0 -367
  74. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/native/NullBackend.h +0 -39
  75. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/native/OpenGLBackend.h +0 -89
  76. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/native/VulkanBackend.h +0 -183
  77. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/native/dawn_native_export.h +0 -49
  78. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/webgpu.h +0 -5063
  79. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/webgpu.ixx +0 -358
  80. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/webgpu_cpp.h +0 -10401
  81. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/webgpu_cpp_print.h +0 -2868
  82. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/wire/client/webgpu.h +0 -369
  83. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/wire/client/webgpu_cpp.h +0 -10584
  84. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/dawn/wire/client/webgpu_cpp_print.h +0 -2868
  85. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu/webgpu.h +0 -33
  86. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu/webgpu_cpp.h +0 -33
  87. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu/webgpu_cpp_chained_struct.h +0 -57
  88. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu/webgpu_cpp_print.h +0 -33
  89. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu/webgpu_enum_class_bitmasks.h +0 -163
  90. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu_upstream/webgpu/webgpu_cpp.h +0 -5932
  91. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu_upstream/webgpu/webgpu_cpp_chained_struct.h +0 -54
  92. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu_upstream/webgpu/webgpu_cpp_print.h +0 -2059
  93. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/Headers/webgpu_upstream/webgpu/webgpu_enum_class_bitmasks.h +0 -163
  94. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -4
package/Package.swift CHANGED
@@ -1,6 +1,4 @@
1
1
  // swift-tools-version: 6.0
2
- // Generated by scripts/generate-package-swift.ts — do not edit by hand.
3
- // Re-run that script after a new Dawn release to update the URL/checksum below.
4
2
  //
5
3
  // SwiftPM manifest for react-native-webgpu. iOS only.
6
4
  // Additive: the CocoaPods podspec remains the supported default.
@@ -21,49 +19,94 @@ let packageRoot = URL(fileURLWithPath: Context.packageDirectory)
21
19
  let sibling = { (relative: String) -> String in
22
20
  URL(fileURLWithPath: "\(packageRoot)/\(relative)").standardized.path
23
21
  }
22
+ // A node package next to this one: a sibling in the consumer's node_modules,
23
+ // or under this monorepo's root.
24
+ let nodePackage = { (name: String) -> String? in
25
+ ["../\(name)", "../../node_modules/\(name)"]
26
+ .map(sibling)
27
+ .first { FileManager.default.fileExists(atPath: "\($0)/package.json") }
28
+ }
29
+ let readJSON = { (path: String) -> [String: Any]? in
30
+ guard let data = FileManager.default.contents(atPath: path) else { return nil }
31
+ return try? JSONSerialization.jsonObject(with: data) as? [String: Any]
32
+ }
33
+
34
+ // Dawn, the WebGPU implementation, comes from the react-native-webgpu-dawn npm
35
+ // package this package depends on: an xcframework with the `webgpu/` and
36
+ // `dawn/` headers embedded in every slice, which SwiftPM exposes to dependents
37
+ // without any search path. react-native-skia's Graphite backend links the
38
+ // same package, so an app installing both contains exactly one Dawn.
39
+ guard let dawnPath = nodePackage("react-native-webgpu-dawn") else {
40
+ // Reached when the dependency was skipped at install time, which SwiftPM
41
+ // would otherwise report as an unresolvable dependency path.
42
+ fatalError(
43
+ """
44
+ react-native-webgpu-dawn was not found next to react-native-webgpu. It ships \
45
+ the Dawn binaries this package links against. Reinstall dependencies.
46
+ """)
47
+ }
48
+ let ownPackage = readJSON("\(packageRoot)/package.json") ?? [:]
49
+ let dawnVersion =
50
+ (readJSON("\(dawnPath)/package.json")?["version"] as? String) ?? "unknown"
24
51
 
25
52
  // Skia Graphite and WebGPU must link the exact same Dawn, or the pair links
26
53
  // fine and crashes at runtime. react-native-skia's podspec enforces this at
27
- // `pod install` time by comparing its libs/.dawn-version against this
28
- // package's `dawn` field. A Swift package has no install hook, so the same
29
- // check runs here, at manifest evaluation. SwiftPM caches evaluations, so
30
- // after changing either package's Dawn version reset the package caches
31
- // (File > Packages > Reset Package Caches) if this does not re-run.
32
- let dawnReleaseTag = "dawn-chrome-m154a"
33
- // Only Graphite builds of react-native-skia carry this marker (Ganesh builds
34
- // do not link Dawn and impose no constraint). From v3 the Skia binaries ship
35
- // in react-native-skia-graphite-apple-ios, which records the tag at
36
- // libs/.dawn-version; react-native-skia's podspec copies it into its own
37
- // libs/ at `pod install`, which never runs here. The v2 Graphite previews
38
- // (e.g. @shopify/react-native-skia@2.12.0-next.1) keep it in their own libs/.
39
- // The graphite packages are normally hoisted next to this package, but may
40
- // be nested under react-native-skia when the package manager cannot hoist
41
- // them. Every marker found is checked.
42
- let skiaDawnMarkers = [
43
- "react-native-skia-graphite-apple-ios/libs/.dawn-version",
44
- "react-native-skia-graphite-apple-macos/libs/.dawn-version",
45
- "react-native-skia/node_modules/react-native-skia-graphite-apple-ios/libs/.dawn-version",
46
- "react-native-skia/node_modules/react-native-skia-graphite-apple-macos/libs/.dawn-version",
47
- "@shopify/react-native-skia/libs/.dawn-version",
48
- ].flatMap { marker in
49
- [
50
- sibling("../\(marker)"), // consumer: sibling in node_modules
51
- sibling("../../node_modules/\(marker)"), // this monorepo
52
- ]
53
- }
54
- for marker in skiaDawnMarkers {
55
- guard let data = FileManager.default.contents(atPath: marker),
56
- let skiaDawn = String(data: data, encoding: .utf8)?
57
- .trimmingCharacters(in: .whitespacesAndNewlines)
58
- else { continue }
59
- if skiaDawn != dawnReleaseTag {
54
+ // `pod install` time; a Swift package has no install hook, so the same check
55
+ // runs here, at manifest evaluation. SwiftPM caches evaluations, so after
56
+ // changing either package's Dawn reset the package caches (File > Packages >
57
+ // Reset Package Caches) if this does not re-run.
58
+ //
59
+ // A react-native-skia that depends on react-native-webgpu-dawn itself must pin
60
+ // the same version as this package. Older Graphite builds (react-native-skia
61
+ // 3.0.x) vendor their own Dawn and record its release tag at
62
+ // libs/.dawn-version in their binary packages; this package's `dawn` field
63
+ // names the release that Dawn is interchangeable with.
64
+ if let skiaPath = nodePackage("react-native-skia"),
65
+ let skiaPackage = readJSON("\(skiaPath)/package.json"),
66
+ let skiaDawn = (skiaPackage["dependencies"] as? [String: String])?["react-native-webgpu-dawn"]
67
+ {
68
+ if skiaDawn != dawnVersion {
60
69
  fatalError(
61
70
  """
62
- react-native-webgpu: Dawn version mismatch. This package links \(dawnReleaseTag) \
63
- but the react-native-skia Graphite binaries (\(marker)) link \(skiaDawn). \
64
- Align the two packages so the app contains exactly one Dawn.
71
+ react-native-webgpu: Dawn version mismatch. This package links \
72
+ react-native-webgpu-dawn \(dawnVersion) but react-native-skia depends on \
73
+ \(skiaDawn). Align the two packages so the app contains exactly one Dawn.
65
74
  """)
66
75
  }
76
+ } else {
77
+ let dawnReleaseTag =
78
+ "dawn-\((ownPackage["dawn"] as? String ?? "").replacingOccurrences(of: "/", with: "-"))"
79
+ // The graphite packages are normally hoisted next to this package, but may
80
+ // be nested under react-native-skia when the package manager cannot hoist
81
+ // them. The v2 Graphite previews (e.g. @shopify/react-native-skia@2.12.0-next.1)
82
+ // keep the marker in their own libs/. Every marker found is checked.
83
+ let skiaDawnMarkers = [
84
+ "react-native-skia-graphite-apple-ios/libs/.dawn-version",
85
+ "react-native-skia-graphite-apple-macos/libs/.dawn-version",
86
+ "react-native-skia/node_modules/react-native-skia-graphite-apple-ios/libs/.dawn-version",
87
+ "react-native-skia/node_modules/react-native-skia-graphite-apple-macos/libs/.dawn-version",
88
+ "@shopify/react-native-skia/libs/.dawn-version",
89
+ ].flatMap { marker in
90
+ [
91
+ sibling("../\(marker)"), // consumer: sibling in node_modules
92
+ sibling("../../node_modules/\(marker)"), // this monorepo
93
+ ]
94
+ }
95
+ for marker in skiaDawnMarkers {
96
+ guard let data = FileManager.default.contents(atPath: marker),
97
+ let skiaDawn = String(data: data, encoding: .utf8)?
98
+ .trimmingCharacters(in: .whitespacesAndNewlines)
99
+ else { continue }
100
+ if skiaDawn != dawnReleaseTag {
101
+ fatalError(
102
+ """
103
+ react-native-webgpu: Dawn version mismatch. This package links \
104
+ react-native-webgpu-dawn \(dawnVersion) (\(dawnReleaseTag)) but the \
105
+ react-native-skia Graphite binaries (\(marker)) link \(skiaDawn). Align \
106
+ the two packages so the app contains exactly one Dawn.
107
+ """)
108
+ }
109
+ }
67
110
  }
68
111
 
69
112
  // Unlike a native Xcode target, SwiftPM doesn't generate an implicit
@@ -71,15 +114,10 @@ for marker in skiaDawnMarkers {
71
114
  // including file's own directory. The sources use bare cross-directory
72
115
  // includes (e.g. apple/WebGPUModule.h includes "RNWebGPUManager.h" from
73
116
  // cpp/rnwgpu), so every directory that's the target of one of those bare
74
- // includes has to be listed explicitly here.
117
+ // includes has to be listed explicitly here. The "webgpu/..." and "dawn/..."
118
+ // includes resolve through the Dawn xcframework's embedded headers.
75
119
  let internalHeaderDirs = [
76
120
  "apple",
77
- // "cpp" itself resolves the "webgpu/..." and "dawn/..." namespaced
78
- // includes. Those two directories are only present locally when built via
79
- // `yarn install-dawn` (without the xcframework's embedded headers); a
80
- // remote binaryTarget's xcframework embeds them instead (see
81
- // build-dawn.yml's `-headers` flag), so "cpp" not containing them there
82
- // is fine — the xcframework's own headers cover it.
83
121
  "cpp",
84
122
  "cpp/jsi",
85
123
  "cpp/rnwgpu",
@@ -102,16 +140,9 @@ let package = Package(
102
140
  dependencies: [
103
141
  .package(name: "React-GeneratedCode", path: "../../../ios"),
104
142
  .package(name: "ReactNative", path: "../../../../xcframeworks"),
143
+ .package(path: dawnPath),
105
144
  ],
106
145
  targets: [
107
- // Dawn's compiled WebGPU implementation. The xcframework embeds the
108
- // `webgpu/` and `dawn/` C headers per-slice (built via `-headers` in
109
- // build-dawn.yml), so SPM exposes them to dependents automatically.
110
- .binaryTarget(
111
- name: "WebGPUDawn",
112
- url: "https://github.com/wcandillon/react-native-webgpu/releases/download/dawn-chrome-m154a/dawn-apple-dawn-chrome-m154a.xcframework.zip",
113
- checksum: "ec06936cca08bca5177e41d78a1b190a22d62980e11df8a4c4ca5868de17c36c"
114
- ),
115
146
  .target(
116
147
  name: "ReactNativeWebGPU",
117
148
  dependencies: [
@@ -120,13 +151,12 @@ let package = Package(
120
151
  .product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
121
152
  // RNWgpuViewSpec, generated by the app's codegen run.
122
153
  .product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
123
- "WebGPUDawn",
154
+ .product(name: "react-native-webgpu-dawn", package: "react-native-webgpu-dawn"),
124
155
  ],
125
156
  // apple/ and cpp/ have no common ancestor below the package root, and
126
157
  // .headerSearchPath cannot escape the target path.
127
158
  path: ".",
128
- // Explicit, so SwiftPM never walks node_modules, lib, android, or the
129
- // headers-only cpp/webgpu and cpp/dawn trees.
159
+ // Explicit, so SwiftPM never walks node_modules, lib or android.
130
160
  sources: ["apple", "cpp/jsi", "cpp/rnwgpu"],
131
161
  // SwiftPM requires a public headers directory inside the target and
132
162
  // defaults to "include", which this package does not have.
@@ -7,8 +7,6 @@ set (CMAKE_CXX_STANDARD_REQUIRED True)
7
7
 
8
8
  set (PACKAGE_NAME "react-native-webgpu")
9
9
 
10
- #link_directories(../libs/android/${ANDROID_ABI}/)
11
-
12
10
  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
13
11
  add_definitions(-DDEBUG=1)
14
12
  endif()
@@ -19,7 +17,15 @@ else()
19
17
  add_definitions(-DRNF_ENABLE_LOGS=0)
20
18
  endif()
21
19
 
22
- set (WEBGPU_LIBS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../libs/android/${ANDROID_ABI}")
20
+ # Dawn comes from the react-native-webgpu-dawn npm package (DAWN_DIR is passed
21
+ # by build.gradle): the shared library per ABI and the headers.
22
+ if(NOT DAWN_DIR)
23
+ message(FATAL_ERROR "react-native-webgpu: DAWN_DIR is not set (the react-native-webgpu-dawn package directory)")
24
+ endif()
25
+ set (WEBGPU_LIBS_PATH "${DAWN_DIR}/libs/android/${ANDROID_ABI}")
26
+ if(NOT EXISTS "${WEBGPU_LIBS_PATH}/libwebgpu_dawn.so")
27
+ message(FATAL_ERROR "react-native-webgpu: libwebgpu_dawn.so not found at ${WEBGPU_LIBS_PATH}. Reinstall dependencies (yarn install / npm install).")
28
+ endif()
23
29
 
24
30
  find_package(ReactAndroid REQUIRED CONFIG)
25
31
  find_package(fbjni REQUIRED CONFIG)
@@ -72,8 +78,8 @@ target_include_directories(
72
78
  ../cpp/rnwgpu/api
73
79
  ../cpp/rnwgpu/api/descriptors
74
80
  ../cpp/jsi
75
- ../cpp/webgpu
76
81
  ../cpp/platform
82
+ "${DAWN_DIR}/include"
77
83
 
78
84
  ${libfbjni_include_DIRS}
79
85
  )
@@ -45,6 +45,28 @@ static def findNodeModules(baseDir) {
45
45
 
46
46
  def nodeModules = findNodeModules(projectDir)
47
47
 
48
+ // Resolve a node package directory using Node's own module resolution
49
+ // (mirrors `require.resolve(pkg/package.json)`).
50
+ static def resolveNodePackage(packageName, baseDir) {
51
+ def script = "process.stdout.write(require('path').dirname(require.resolve('${packageName}/package.json')))"
52
+ def proc = ["node", "-e", script].execute(null, baseDir)
53
+ proc.waitFor()
54
+ if (proc.exitValue() != 0) {
55
+ throw new GradleException(
56
+ "react-native-webgpu: Could not resolve the '${packageName}' package. " +
57
+ "Make sure dependencies are installed (yarn install / npm install).\n" + proc.err.text
58
+ )
59
+ }
60
+ return proc.text.trim()
61
+ }
62
+
63
+ // Dawn, the WebGPU implementation, ships in the react-native-webgpu-dawn npm
64
+ // package this package depends on: libs/android/<abi>/libwebgpu_dawn.so and
65
+ // the headers under include/. react-native-skia's Graphite backend links the
66
+ // same package, so an app installing both contains exactly one Dawn.
67
+ def dawnDir = resolveNodePackage('react-native-webgpu-dawn', projectDir)
68
+ logger.warn("react-native-webgpu: Dawn from ${dawnDir}")
69
+
48
70
  def getExtOrDefault(name) {
49
71
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Wgpu_" + name]
50
72
  }
@@ -75,6 +97,7 @@ android {
75
97
  abiFilters (*reactNativeArchitectures())
76
98
  arguments '-DANDROID_STL=c++_shared',
77
99
  "-DNODE_MODULES_DIR=${nodeModules}",
100
+ "-DDAWN_DIR=${dawnDir}",
78
101
  "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
79
102
  }
80
103
  }
@@ -401,8 +401,8 @@ public:
401
401
  // not touch the device, and this must not change behaviour there.
402
402
  //
403
403
  // Remove once the pinned Dawn contains the upstream fix; the check in
404
- // scripts/install-dawn.ts fails the install when the Dawn pin changes so
405
- // that decision is not forgotten.
404
+ // scripts/check-dawn.ts fails when the Dawn the react-native-webgpu-dawn
405
+ // package was built from changes, so that decision is not forgotten.
406
406
  void releaseSurfaceForDevice(const wgpu::Device &device) {
407
407
  #if defined(__ANDROID__)
408
408
  std::unique_lock<std::shared_mutex> lock(_mutex);
@@ -54,7 +54,7 @@ const provideGPUForInstall = gpu => {
54
54
  * const work = () => {
55
55
  * "worklet";
56
56
  * installWebGPU();
57
- * globalThis.navigator.gpu.requestAdapter().then((adapter) => {
57
+ * navigator.gpu.requestAdapter().then((adapter) => {
58
58
  * // ...
59
59
  * });
60
60
  * };
@@ -62,12 +62,11 @@ const provideGPUForInstall = gpu => {
62
62
  *
63
63
  * Known limitations:
64
64
  *
65
- * - Read `navigator` through `globalThis.navigator`: the Worklets Babel
66
- * plugin does not treat a bare `navigator` as a known global, so it would
67
- * capture the main runtime's `navigator` object by closure instead of
68
- * reading the one this function installed. Fixed upstream in
69
- * react-native-reanimated#10364; the prefix becomes unnecessary on
70
- * react-native-worklets versions that include it.
65
+ * - On react-native-worklets < 0.13.0, read `navigator` through
66
+ * `globalThis.navigator`: older versions of the Worklets Babel plugin do
67
+ * not treat a bare `navigator` as a known global, so they capture the main
68
+ * runtime's `navigator` object by closure instead of reading the one this
69
+ * function installed.
71
70
  * - Spontaneous events are main-runtime only: on a device created on a
72
71
  * worklet runtime, `device.lost` never settles (unless the device is
73
72
  * already lost when read) and `uncapturederror` listeners never fire.
@@ -1 +1 @@
1
- {"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","holder","provideGPUForInstall","gpu","exports","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AADA;;AASA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBC,cAAc,EAAdA,yBAAc;EACdC,eAAe,EAAfA,0BAAe;EACfC,cAAc,EAAdA,yBAAc;EACdC,aAAa,EAAbA,wBAAa;EACbC,UAAU,EAAVA;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA3CAC,OAAA,CAAAF,oBAAA,GAAAA,oBAAA;AA4CO,MAAMG,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAAChB,SAAS,CAAC,EAAE;IACpD,IAAIW,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,MAAM;IAAEN;EAAI,CAAC,GAAGF,MAAM;EACtB,IAAIE,GAAG,KAAKS,SAAS,EAAE;IACrB,MAAMC,GAAG,GAAGP,CAAC,CAACQ,SAA0D;IACxE,IAAID,GAAG,KAAKD,SAAS,EAAE;MACrBN,CAAC,CAACQ,SAAS,GAAG;QAAEX,GAAG;QAAEY,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACV,GAAG,KAAKS,SAAS,EAAE;MAChCC,GAAG,CAACV,GAAG,GAAGA,GAAG;IACf;EACF;AACF,CAAC;AAACC,OAAA,CAAAC,aAAA,GAAAA,aAAA","ignoreList":[]}
1
+ {"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","holder","provideGPUForInstall","gpu","exports","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AADA;;AASA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBC,cAAc,EAAdA,yBAAc;EACdC,eAAe,EAAfA,0BAAe;EACfC,cAAc,EAAdA,yBAAc;EACdC,aAAa,EAAbA,wBAAa;EACbC,UAAU,EAAVA;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA1CAC,OAAA,CAAAF,oBAAA,GAAAA,oBAAA;AA2CO,MAAMG,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAAChB,SAAS,CAAC,EAAE;IACpD,IAAIW,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,MAAM;IAAEN;EAAI,CAAC,GAAGF,MAAM;EACtB,IAAIE,GAAG,KAAKS,SAAS,EAAE;IACrB,MAAMC,GAAG,GAAGP,CAAC,CAACQ,SAA0D;IACxE,IAAID,GAAG,KAAKD,SAAS,EAAE;MACrBN,CAAC,CAACQ,SAAS,GAAG;QAAEX,GAAG;QAAEY,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACV,GAAG,KAAKS,SAAS,EAAE;MAChCC,GAAG,CAACV,GAAG,GAAGA,GAAG;IACf;EACF;AACF,CAAC;AAACC,OAAA,CAAAC,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -48,7 +48,7 @@ export const provideGPUForInstall = gpu => {
48
48
  * const work = () => {
49
49
  * "worklet";
50
50
  * installWebGPU();
51
- * globalThis.navigator.gpu.requestAdapter().then((adapter) => {
51
+ * navigator.gpu.requestAdapter().then((adapter) => {
52
52
  * // ...
53
53
  * });
54
54
  * };
@@ -56,12 +56,11 @@ export const provideGPUForInstall = gpu => {
56
56
  *
57
57
  * Known limitations:
58
58
  *
59
- * - Read `navigator` through `globalThis.navigator`: the Worklets Babel
60
- * plugin does not treat a bare `navigator` as a known global, so it would
61
- * capture the main runtime's `navigator` object by closure instead of
62
- * reading the one this function installed. Fixed upstream in
63
- * react-native-reanimated#10364; the prefix becomes unnecessary on
64
- * react-native-worklets versions that include it.
59
+ * - On react-native-worklets < 0.13.0, read `navigator` through
60
+ * `globalThis.navigator`: older versions of the Worklets Babel plugin do
61
+ * not treat a bare `navigator` as a known global, so they capture the main
62
+ * runtime's `navigator` object by closure instead of reading the one this
63
+ * function installed.
65
64
  * - Spontaneous events are main-runtime only: on a device created on a
66
65
  * worklet runtime, `device.lost` never settles (unless the device is
67
66
  * already lost when read) and `uncapturederror` listeners never fire.
@@ -1 +1 @@
1
- {"version":3,"names":["GPUBufferUsage","GPUColorWrite","GPUMapMode","GPUShaderStage","GPUTextureUsage","constants","holder","provideGPUForInstall","gpu","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":"AAAA;AACA,SACEA,cAAc,EACdC,aAAa,EACbC,UAAU,EACVC,cAAc,EACdC,eAAe,QACV,aAAa;;AAEpB;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBL,cAAc;EACdI,eAAe;EACfD,cAAc;EACdF,aAAa;EACbC;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACV,SAAS,CAAC,EAAE;IACpD,IAAIK,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,MAAM;IAAEL;EAAI,CAAC,GAAGF,MAAM;EACtB,IAAIE,GAAG,KAAKQ,SAAS,EAAE;IACrB,MAAMC,GAAG,GAAGP,CAAC,CAACQ,SAA0D;IACxE,IAAID,GAAG,KAAKD,SAAS,EAAE;MACrBN,CAAC,CAACQ,SAAS,GAAG;QAAEV,GAAG;QAAEW,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACT,GAAG,KAAKQ,SAAS,EAAE;MAChCC,GAAG,CAACT,GAAG,GAAGA,GAAG;IACf;EACF;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["GPUBufferUsage","GPUColorWrite","GPUMapMode","GPUShaderStage","GPUTextureUsage","constants","holder","provideGPUForInstall","gpu","installWebGPU","g","globalThis","key","value","Object","entries","undefined","nav","navigator","userAgent"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":"AAAA;AACA,SACEA,cAAc,EACdC,aAAa,EACbC,UAAU,EACVC,cAAc,EACdC,eAAe,QACV,aAAa;;AAEpB;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBL,cAAc;EACdI,eAAe;EACfD,cAAc;EACdF,aAAa;EACbC;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,MAAqB,GAAG,CAAC,CAAC;;AAEhC;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAIC,GAAQ,IAAK;EAChDF,MAAM,CAACE,GAAG,GAAGA,GAAG;AAClB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACV,SAAS,CAAC,EAAE;IACpD,IAAIK,CAAC,CAACE,GAAG,CAAC,KAAKI,SAAS,EAAE;MACxBN,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,MAAM;IAAEL;EAAI,CAAC,GAAGF,MAAM;EACtB,IAAIE,GAAG,KAAKQ,SAAS,EAAE;IACrB,MAAMC,GAAG,GAAGP,CAAC,CAACQ,SAA0D;IACxE,IAAID,GAAG,KAAKD,SAAS,EAAE;MACrBN,CAAC,CAACQ,SAAS,GAAG;QAAEV,GAAG;QAAEW,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACT,GAAG,KAAKQ,SAAS,EAAE;MAChCC,GAAG,CAACT,GAAG,GAAGA,GAAG;IACf;EACF;AACF,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";AA+BA;;;GAGG;AACH,qDAEC;AA+CD,sCAuBC"}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../commonjs/install.js"],"names":[],"mappings":";AA+BA;;;GAGG;AACH,qDAEC;AA8CD,sCAuBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"AA6BO,qDAEN;AA8CM,sCAuBN"}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../module/install.js"],"names":[],"mappings":"AA6BO,qDAEN;AA6CM,sCAuBN"}
@@ -20,7 +20,7 @@ export declare const provideGPUForInstall: (gpu: GPU) => void;
20
20
  * const work = () => {
21
21
  * "worklet";
22
22
  * installWebGPU();
23
- * globalThis.navigator.gpu.requestAdapter().then((adapter) => {
23
+ * navigator.gpu.requestAdapter().then((adapter) => {
24
24
  * // ...
25
25
  * });
26
26
  * };
@@ -28,12 +28,11 @@ export declare const provideGPUForInstall: (gpu: GPU) => void;
28
28
  *
29
29
  * Known limitations:
30
30
  *
31
- * - Read `navigator` through `globalThis.navigator`: the Worklets Babel
32
- * plugin does not treat a bare `navigator` as a known global, so it would
33
- * capture the main runtime's `navigator` object by closure instead of
34
- * reading the one this function installed. Fixed upstream in
35
- * react-native-reanimated#10364; the prefix becomes unnecessary on
36
- * react-native-worklets versions that include it.
31
+ * - On react-native-worklets < 0.13.0, read `navigator` through
32
+ * `globalThis.navigator`: older versions of the Worklets Babel plugin do
33
+ * not treat a bare `navigator` as a known global, so they capture the main
34
+ * runtime's `navigator` object by closure instead of reading the one this
35
+ * function installed.
37
36
  * - Spontaneous events are main-runtime only: on a device created on a
38
37
  * worklet runtime, `device.lost` never settles (unless the device is
39
38
  * already lost when read) and `uncapturederror` listeners never fire.
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AA+BA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,GAAG,SAE5C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,aAAa,YAiBzB,CAAC"}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/install.ts"],"names":[],"mappings":"AA+BA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,GAAG,SAE5C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,aAAa,YAiBzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webgpu",
3
- "version": "0.12.1",
3
+ "version": "0.13.1",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -18,7 +18,6 @@
18
18
  "android/src/**",
19
19
  "cpp/**/*.{h,cpp}",
20
20
  "apple/**",
21
- "libs/**",
22
21
  "*.podspec",
23
22
  "Package.swift",
24
23
  "react-native.config.js",
@@ -26,7 +25,6 @@
26
25
  "plugin/build/**"
27
26
  ],
28
27
  "dawn": "chrome-m154a",
29
- "dawnCommit": "3d786993a7ded64c4ebb4884b9b079db9ad0e580",
30
28
  "scripts": {
31
29
  "test": "NODE_OPTIONS='--experimental-require-module' jest -i",
32
30
  "test:ref": "REFERENCE=true NODE_OPTIONS='--experimental-require-module' jest -i",
@@ -37,15 +35,12 @@
37
35
  "build": "bob build && yarn build:plugin",
38
36
  "build:plugin": "tsc -p plugin/tsconfig.build.json",
39
37
  "release": "semantic-release",
40
- "build-dawn": "tsx scripts/build/dawn.ts",
41
- "clean-dawn": "rimraf ./libs && rimraf ../../externals/dawn/out",
42
38
  "clang-format": "yarn clang-format-ios && yarn clang-format-android && yarn clang-format-common",
43
39
  "clang-format-ios": "find apple/ -iname \"*.h\" -o -iname \"*.mm\" -o -iname \"*.cpp\" | xargs clang-format -i",
44
40
  "clang-format-android": "find android/cpp/ -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
45
41
  "clang-format-common": "find cpp/rnwgpu -iname \"*.h\" -o -iname \"*.m\" -o -iname \"*.cpp\" | xargs clang-format -i",
46
42
  "cpplint": "cpplint --linelength=230 --filter=-legal/copyright,-whitespace/indent,-whitespace/comments,-whitespace/ending_newline,-build/include_order,-runtime/references,-readability/todo,-whitespace/blank_line,-whitespace/todo,-runtime/int,-build/c++11,-whitespace/parens --exclude=example --exclude=android/.cxx --exclude=cpp/webgpu --exclude=cpp/dawn --exclude=ios --exclude=android/build --exclude=node_modules --recursive .",
47
- "install-dawn": "tsx scripts/install-dawn.ts",
48
- "generate-package-swift": "tsx scripts/generate-package-swift.ts"
43
+ "check-dawn": "tsx scripts/check-dawn.ts"
49
44
  },
50
45
  "keywords": [
51
46
  "react-native",
@@ -114,6 +109,9 @@
114
109
  "ws": "^8.18.0",
115
110
  "yargs": "^17.7.2"
116
111
  },
112
+ "dependencies": {
113
+ "react-native-webgpu-dawn": "154.3.0"
114
+ },
117
115
  "peerDependencies": {
118
116
  "react": "*",
119
117
  "react-native": ">=0.81.0",
@@ -1,8 +1,44 @@
1
1
  require "json"
2
+ require "fileutils"
2
3
 
3
4
  package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
5
  folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
6
 
7
+ # Resolve a node package directory using Node's own module resolution
8
+ # (mirrors `require.resolve(pkg/package.json)`). A lambda rather than a `def`:
9
+ # CocoaPods evaluates the podspec inside the `Pod` module, where top-level
10
+ # methods are not reachable at the call site.
11
+ resolve_node_package = lambda do |name, base_dir|
12
+ script = "process.stdout.write(require('path').dirname(require.resolve('#{name}/package.json')))"
13
+ dir = Dir.chdir(base_dir) { `node -e "#{script}" 2>/dev/null`.strip }
14
+ dir.empty? ? nil : dir
15
+ end
16
+
17
+ # Dawn, the WebGPU implementation, ships in the react-native-webgpu-dawn npm
18
+ # package this package depends on (react-native-skia's Graphite backend links
19
+ # the same one, so an app installing both contains exactly one Dawn). Its
20
+ # headers are used in place, but CocoaPods only vendors frameworks from inside
21
+ # the pod, so the xcframework is copied into libs/apple at `pod install` time.
22
+ # The copy is stamped with the package version and skipped when it already
23
+ # matches, which keeps CocoaPods' cache intact across installs.
24
+ dawn_dir = resolve_node_package.call('react-native-webgpu-dawn', __dir__)
25
+ if dawn_dir.nil?
26
+ raise "react-native-webgpu: the react-native-webgpu-dawn package was not found. " \
27
+ "It ships the Dawn binaries this package links against; make sure " \
28
+ "dependencies are installed (yarn install / npm install), then run `pod install` again."
29
+ end
30
+ dawn_version = JSON.parse(File.read(File.join(dawn_dir, 'package.json')))['version'].to_s
31
+ dawn_include = File.join(dawn_dir, 'include')
32
+ dawn_libs = File.join(__dir__, 'libs', 'apple')
33
+ dawn_marker = File.join(dawn_libs, '.version')
34
+ unless File.exist?(dawn_marker) && File.read(dawn_marker).strip == dawn_version
35
+ Pod::UI.puts "react-native-webgpu: installing Dawn (react-native-webgpu-dawn #{dawn_version})"
36
+ FileUtils.rm_rf(dawn_libs)
37
+ FileUtils.mkdir_p(dawn_libs)
38
+ FileUtils.cp_r(File.join(dawn_dir, 'libs', 'apple', 'libwebgpu_dawn.xcframework'), dawn_libs)
39
+ File.write(dawn_marker, dawn_version)
40
+ end
41
+
6
42
  Pod::Spec.new do |s|
7
43
  s.name = "react-native-webgpu"
8
44
  s.version = package["version"]
@@ -50,7 +86,7 @@ Pod::Spec.new do |s|
50
86
  end
51
87
 
52
88
  s.pod_target_xcconfig = {
53
- 'HEADER_SEARCH_PATHS' => '$(PODS_TARGET_SRCROOT)/cpp',
89
+ 'HEADER_SEARCH_PATHS' => "$(PODS_TARGET_SRCROOT)/cpp \"#{dawn_include}\"",
54
90
  # Xcode's all-target headermaps let same-named headers leak across pods
55
91
  # (e.g. @shopify/react-native-skia keeps a jsi/ helper layer with
56
92
  # identical relative header paths). Resolve includes strictly through our
@@ -66,7 +102,7 @@ Pod::Spec.new do |s|
66
102
  s.dependency "React-Core"
67
103
  s.compiler_flags = folly_compiler_flags
68
104
  s.pod_target_xcconfig = {
69
- "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_TARGET_SRCROOT)/cpp\"",
105
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" \"$(PODS_TARGET_SRCROOT)/cpp\" \"#{dawn_include}\"",
70
106
  "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
71
107
  "CLANG_CXX_LANGUAGE_STANDARD" => "c++20"
72
108
  }
package/src/install.ts CHANGED
@@ -54,7 +54,7 @@ export const provideGPUForInstall = (gpu: GPU) => {
54
54
  * const work = () => {
55
55
  * "worklet";
56
56
  * installWebGPU();
57
- * globalThis.navigator.gpu.requestAdapter().then((adapter) => {
57
+ * navigator.gpu.requestAdapter().then((adapter) => {
58
58
  * // ...
59
59
  * });
60
60
  * };
@@ -62,12 +62,11 @@ export const provideGPUForInstall = (gpu: GPU) => {
62
62
  *
63
63
  * Known limitations:
64
64
  *
65
- * - Read `navigator` through `globalThis.navigator`: the Worklets Babel
66
- * plugin does not treat a bare `navigator` as a known global, so it would
67
- * capture the main runtime's `navigator` object by closure instead of
68
- * reading the one this function installed. Fixed upstream in
69
- * react-native-reanimated#10364; the prefix becomes unnecessary on
70
- * react-native-worklets versions that include it.
65
+ * - On react-native-worklets < 0.13.0, read `navigator` through
66
+ * `globalThis.navigator`: older versions of the Worklets Babel plugin do
67
+ * not treat a bare `navigator` as a known global, so they capture the main
68
+ * runtime's `navigator` object by closure instead of reading the one this
69
+ * function installed.
71
70
  * - Spontaneous events are main-runtime only: on a device created on a
72
71
  * worklet runtime, `device.lost` never settles (unless the device is
73
72
  * already lost when read) and `uncapturederror` listeners never fire.