diff --git a/.agents/skills/verify-and-build/SKILL.md b/.agents/skills/verify-and-build/SKILL.md index 4b641887dd..fb13aaeeb4 100644 --- a/.agents/skills/verify-and-build/SKILL.md +++ b/.agents/skills/verify-and-build/SKILL.md @@ -108,6 +108,17 @@ phoneme output. Use device/emulator integration for those behaviors. ## Native app verification +The [consumer build matrix](../../../.github/consumer-builds/README.md) checks a +packed library in fresh bare RN and Expo applications on Android and iOS. It +runs Expo profiles on relevant PRs, including Windows-hosted Android and two +emulator/simulator runtime smoke cells, Android AAB validation, and Expo +config-plugin integration builds for Sentry, Firebase, Vision Camera and audio-api. Manual dispatch can also select the full +bare RN/Worklets matrix. +Use it for publication, installation, autolinking, release bundling and +native build regressions. Only the smoke cells launch apps and verify a bundled +XNNPACK model; other backends and physical devices still need separate verification. The linked README owns its version pins, commands, +artifacts and limitations. + Choose the relevant app (`computer-vision`, `nlp` or `speech`) and inspect its current native setup. Provision matching native libraries before rebuilding. If iOS native projects already exist, run `pod install` in the app's `ios/` directory when dependencies, podspec files or source discovery change. diff --git a/.github/consumer-builds/README.md b/.github/consumer-builds/README.md new file mode 100644 index 0000000000..2af0b869dd --- /dev/null +++ b/.github/consumer-builds/README.md @@ -0,0 +1,210 @@ +# Consumer build matrix + + + +The [Consumer builds workflow](../workflows/consumer-builds.yml) installs one +published-format library tarball into fresh consumer applications outside the +checkout. All cells use the same tarball built from the current commit. They +cannot resolve the repository's workspace dependencies or library source files. + +## Version coverage + +[compatibility.json](./compatibility.json) declares supported RN minors for each +pinned Worklets release, pinned RN patches and peer versions, and the Expo +fixtures. [matrix.mjs](./matrix.mjs) generates every declared compatible pair and +expands it across Android and iOS. One workflow plans, packs and builds them. + +| React Native | Compatible Worklets pins | Release app builds | +| ---------------------------- | ------------------------------------------------------------ | ------------------ | +| 0.83.6 | 0.10.4, 0.11.4, 0.12.2 | 6 | +| 0.84.1 | 0.10.4, 0.11.4, 0.12.2 | 6 | +| 0.85.3 | 0.10.4, 0.11.4, 0.12.2 | 6 | +| 0.86.3 | 0.10.4, 0.11.4, 0.12.2, 0.13.0 | 8 | +| 0.87.1 | 0.12.2, 0.13.0 | 4 | +| 0.88.1 | 0.13.0 | 2 | +| Expo 55.0.32 / RN 0.83.10 | 0.10.4 | 2 | +| Expo 56.0.24 / RN 0.85.3 | 0.10.4 | 2 | +| Expo 57.0.28 / RN 0.86.3 | 0.13.0 | 2 | +| Expo 58.0.24 / RN 0.88.1 | 0.13.0 | 2 | +| Latest Expo, Windows Android | Same versions as the latest SDK | 1 | +| Latest Expo, runtime smoke | Same versions as the latest SDK | 2 | +| Latest Expo, integrations | Sentry, Firebase, Vision Camera, audio-api | 2 | +| **Total** | **32 bare + 8 Expo + 1 Windows + 2 runtime + 2 integration** | **45** | + +- **Relevant pull requests:** thirteen app builds: eight SDK/platform builds, + one additional Expo 58 Android build on Windows, and two latest-Expo runtime + smoke apps (Android emulator on Linux, iOS simulator on macOS), plus two + latest-Expo integration builds. +- **Manual dispatch:** `expo` (the default) runs those thirteen builds; `full` + adds all 32 bare RN/Worklets builds for **45 app builds**. Use `full` for + releases, native changes and compatibility investigations. +- **No scheduled runs yet.** A TODO tracks considering daily Expo coverage after + validation; the broader bare RN matrix remains manual. + +Each run also has one planning/test job and one shared library build/package job: +**15 jobs for regular coverage, 47 for manual full coverage**. Matrix jobs can +run concurrently, subject to GitHub runner availability and organization limits. The table above shows the complete manual matrix. + +The compatibility rules match the pinned Worklets packages' published RN peer +ranges. For example, Worklets 0.13 supports RN 0.86–0.88, whereas 0.12 supports +0.83–0.87. The manual `full` scope builds every compatible combination of the declared pins; +this does not test every patch release or expand support to Worklets 0.14. +Expo RN/React/build-properties pins follow each SDK's `bundledNativeModules.json`. +SDKs 55 and 56 bundle Worklets below this library's minimum; these fixtures +explicitly install 0.10.4, as required by the integration documentation. SDKs 57 +and 58 use 0.13.0. These are native prebuild tests, not Expo Go or EAS tests. + +blob-util is pinned to 0.25.1 for RN 0.83 and 1.0.0 for newer RN versions, because +blob-util 1.0 requires RN >=0.84. + +All builds are Release. Android uses Java 17, the hosted runner's preinstalled +SDK, and R8. Regular Linux/Windows Android builds target arm64; the Linux runtime +app targets x86_64 for the emulator. Windows uses `windows-2025` and a short +`C:\rnet\app` consumer path, with direct npm JavaScript entry points instead of +spawning `.cmd` scripts. iOS builds run on Apple Silicon macOS 26: regular cells +archive for devices, while the runtime cell builds for a simulator. + +App source lives in [apps/consumer-fixtures](../../apps/consumer-fixtures/), which +intentionally has no package manifest and is not a workspace. CI helpers stay in +`.github/consumer-builds/`. Preparation copies the app source into an isolated +consumer outside the repository. + +Other framework linkage variants, backend subsets, Debug, RN nightly, EAS and OTA +remain separate coverage to add. + +## What it checks + +- The publishing script packs built JavaScript, declarations, native sources and + the license, without bundling dependencies or downloaded native artifacts. +- npm installs the tarball and executes the real native-library postinstall hook. +- Bare RN and Expo autolinking, Worklets Babel configuration, native compilation, + release JS bundling, and Android R8 complete successfully. +- APKs contain RNE, ExecuTorch, XNNPACK and Vulkan shared libraries for the + selected ABI. +- iOS archives contain the application executable and JS bundle. When the package + ships its privacy manifest, the resource bundle must appear in the archive and + pass `plutil` validation. + +All optional native libraries for the selected platform are enabled. Postinstall +fetches only that platform via `RNET_TARGET`. This does not test cross-host Expo +fingerprint equality or backend opt-outs. + +## Production packaging and integration coverage + +The latest regular Expo Android/Linux cell also runs `bundleRelease`, reusing +its compiled app. A pinned, SHA-256-verified bundletool validates the AAB; checks +require the JS bundle, dex, manifest, and arm64 RNE, ExecuTorch, XNNPACK and +Vulkan libraries. The AAB and validation logs are retained. This checks bundle +packaging, not Play Store upload acceptance or production signing. + +Two latest-Expo build-only cells install Sentry 8.35.0, React Native Firebase +27.1.1 (App), Vision Camera 4.7.3, and audio-api 0.13.6 alongside RNE and Worklets. +Versions live in `compatibility.json`. Audio-api matches the repository apps; +Vision Camera 4 includes the Expo config plugin (version 5 does not ship it). +All four config plugins run during prebuild. Checks verify generated camera and +microphone permissions, iOS background audio, Firebase service configuration, +Sentry build hooks, and dynamic iOS frameworks required by Firebase 27. The app +references each library so Release bundling resolves its JS; native builds check +autolinking and linking on both platforms. + +Firebase configuration is synthetic and points to no real project. Sentry uses +its Expo Metro integration, with upload disabled for these credential-free +builds. These cells do not launch the app or test service connectivity, camera +capture, audio recording, or telemetry delivery. + +This extends #1609 with Android AAB packaging, iOS camera/audio build coexistence, +and Expo config-plugin coexistence. Linux/Windows hosts and bundled `.pte` are +already covered separately; EAS, OTA delivery and App Store upload validation +remain outstanding. Split combined checklist rows before marking only their +covered parts complete. + +## Runtime smoke checks + +Only the two latest-Expo smoke cells launch an app. They assert: + +1. Native tensor allocation, data transfer and softmax produce expected values. +2. A sliced typed array survives a worklet round trip and native tensor use. +3. A bundled selfie-segmentation model loads with `XnnpackBackend` and executes + on the worklet runtime, replacing NaN sentinel outputs with finite probabilities. + +The approximately 486 KB model is downloaded during preparation at the exact +revision and SHA-256 used by the host-test fixture script. It is bundled as a +`.pte` asset and resolved to a local file by `expo-asset`. No model binary is +committed, and the app does not fetch a model from the network at runtime. + +A loopback HTTP collector waits for a report containing all three assertions and +a per-build random token. App crashes, missing reports, assertion failures and +incomplete reports fail CI. The reporter's own tests verify those failure paths. +Android reaches the collector through `adb reverse`; iOS uses simulator loopback. +Simulator boot has a separate ten-minute deadline to allow first-boot data +migration. The three-minute assertion deadline starts immediately before app +launch, after boot and installation. Simulator boot output is saved in +`simulator-boot.log`; cleanup commands are limited to fifteen seconds each. +Cleartext loopback access is enabled only in the smoke fixtures. Native/runtime +logs and the successful report are retained in the cell's artifact. + +This verifies XNNPACK inference on emulators/simulators. It does not establish +Core ML, Vulkan or MLX inference, real camera/audio behavior, App Store validation, +EAS or OTA compatibility. Version build cells remain build-only checks. + +## Run locally + +Use Node from `.nvmrc`, the repository's Yarn version, and the toolchains in the +[verification skill](../../.agents/skills/verify-and-build/SKILL.md). From the +repository root: + +```bash +RNET_SKIP_DOWNLOAD=1 yarn install --immutable +(cd packages/react-native-executorch && RNET_SKIP_DOWNLOAD=1 RNE_SKIP_INSTALL=1 GIT_LFS_SKIP_SMUDGE=1 ./scripts/create-package.sh) + +# Use a new directory outside the checkout. Leave RNET_SKIP_DOWNLOAD unset. +node .github/consumer-builds/prepare.mjs expo-55 android \ + packages/react-native-executorch/react-native-executorch-1.0.0.tgz \ + /tmp/ConsumerBuild + +cd /tmp/ConsumerBuild/android +./gradlew :app:assembleRelease --no-daemon --stacktrace --max-workers=2 +``` + +Adjust the tarball filename to the package version. For iOS, pass `ios` instead +of `android`, run `pod install` in the generated `ios/` directory, then use the +workflow's archive command. `expo-55`, `expo-56`, `expo-57` and `expo-58` work on either platform. iOS app +deployment targets are at least 17.0, preserving a higher RN requirement. +Use `expo-58-integration` for the plugin fixture, setting +`SENTRY_DISABLE_AUTO_UPLOAD=true` when running native builds. +To reproduce AAB coverage, run `:app:bundleRelease` in the regular latest-Expo +Android project and use `validate-aab.mjs ` from +the checkout with Java 17 on PATH. + +Compatibility data pins the framework, Worklets, blob-util and CLI; other template and +transitive dependencies are resolved on each run. Every cell retains its resolved +profile, npm lockfile, Gradle files, Podfile configuration and lockfile when present, native +library configuration and logs in a seven-day artifact. Android artifacts also +contain the APK and, for the AAB cell, the app bundle; full iOS archives are not uploaded. No successful-build marker +cache skips compilation of a new library commit. + +## Maintain the matrix + +Update the JSON pins and compatibility declarations deliberately, checking the +published npm peer requirements. Every configured RN minor must have a compatible +Worklets version, every Worklets RN declaration must name a configured RN minor, +and Expo must use a declared compatible pair. The newest Expo profile also pins +`expoAsset` for the bundled-model smoke app. Windows and runtime cells follow +that newest profile automatically, as do the integration cells and AAB selection. +Review the `integrations` pins against the new RN/Expo versions when upgrading; +repeat both platform builds to establish compatibility. The tests verify full combination +coverage, unique artifact ids, default host/runtime selection and smoke report failures. The planning job reports +the actual build count in the GitHub job summary; update the table and expected +counts in the tests when changing support. + +```bash +node --test .github/consumer-builds/*.test.mjs +node .github/consumer-builds/matrix.mjs full +node --check .github/consumer-builds/prepare.mjs +actionlint .github/workflows/consumer-builds.yml +yarn prettier --ignore-path /dev/null --check '.github/consumer-builds/*' '.github/workflows/consumer-build*.yml' 'apps/consumer-fixtures/*.jsx' +``` + +Exercise preparation and the affected platform build after changing templates or +build commands. `.github` is excluded by the repository's default Prettier ignore +file, so formatting these files needs `--ignore-path /dev/null`. diff --git a/.github/consumer-builds/compatibility.json b/.github/consumer-builds/compatibility.json new file mode 100644 index 0000000000..e24bf70ef4 --- /dev/null +++ b/.github/consumer-builds/compatibility.json @@ -0,0 +1,106 @@ +{ + "cli": "20.1.1", + "bare": [ + { + "id": "rn-0-83", + "reactNative": "0.83.6", + "blobUtil": "0.25.1" + }, + { + "id": "rn-0-84", + "reactNative": "0.84.1", + "blobUtil": "1.0.0" + }, + { + "id": "rn-0-85", + "reactNative": "0.85.3", + "blobUtil": "1.0.0" + }, + { + "id": "rn-0-86", + "reactNative": "0.86.3", + "blobUtil": "1.0.0" + }, + { + "id": "rn-0-87", + "reactNative": "0.87.1", + "blobUtil": "1.0.0" + }, + { + "id": "rn-0-88", + "reactNative": "0.88.1", + "blobUtil": "1.0.0" + } + ], + "expo": [ + { + "id": "expo-55", + "expo": "55.0.32", + "reactNative": "0.83.10", + "react": "19.2.0", + "worklets": "0.10.4", + "blobUtil": "0.25.1", + "buildProperties": "55.0.18", + "babelPreset": "55.0.25", + "babelCore": "7.29.7" + }, + { + "id": "expo-56", + "expo": "56.0.24", + "reactNative": "0.85.3", + "react": "19.2.3", + "worklets": "0.10.4", + "blobUtil": "1.0.0", + "buildProperties": "56.0.27", + "babelPreset": "56.0.21", + "babelCore": "7.29.7" + }, + { + "id": "expo-57", + "expo": "57.0.28", + "reactNative": "0.86.3", + "react": "19.2.3", + "worklets": "0.13.0", + "blobUtil": "1.0.0", + "buildProperties": "57.0.22", + "babelPreset": "57.0.15", + "babelCore": "7.29.7" + }, + { + "id": "expo-58", + "expo": "58.0.24", + "reactNative": "0.88.1", + "react": "19.3.0", + "worklets": "0.13.0", + "blobUtil": "1.0.0", + "buildProperties": "58.0.12", + "babelPreset": "58.0.25", + "babelCore": "7.29.7", + "expoAsset": "58.0.21" + } + ], + "worklets": [ + { + "version": "0.10.4", + "reactNative": ["0.83", "0.84", "0.85", "0.86"] + }, + { + "version": "0.11.4", + "reactNative": ["0.83", "0.84", "0.85", "0.86"] + }, + { + "version": "0.12.2", + "reactNative": ["0.83", "0.84", "0.85", "0.86", "0.87"] + }, + { + "version": "0.13.0", + "reactNative": ["0.86", "0.87", "0.88"] + } + ], + "integrations": { + "@sentry/react-native": "8.35.0", + "@react-native-firebase/app": "27.1.1", + "react-native-vision-camera": "4.7.3", + "react-native-audio-api": "0.13.6" + } +} diff --git a/.github/consumer-builds/host.mjs b/.github/consumer-builds/host.mjs new file mode 100644 index 0000000000..f02c161fe9 --- /dev/null +++ b/.github/consumer-builds/host.mjs @@ -0,0 +1,30 @@ +import path from 'node:path'; + +export function isInside(parent, child, paths = path) { + const relative = paths.relative(parent, child); + return ( + relative === '' || + (!paths.isAbsolute(relative) && relative !== '..' && !relative.startsWith(`..${paths.sep}`)) + ); +} + +export function packageManagerCommand( + command, + args, + platform = process.platform, + execPath = process.execPath +) { + if (!['npm', 'npx'].includes(command)) + throw new Error(`Unsupported package manager command: ${command}`); + if (platform !== 'win32') return { command, args }; + // Windows npm/npx entry points are .cmd scripts. Invoke the npm installation + // shipped beside node.exe directly, keeping paths and arguments out of a shell. + const cli = path.win32.join( + path.win32.dirname(execPath), + 'node_modules', + 'npm', + 'bin', + `${command}-cli.js` + ); + return { command: execPath, args: [cli, ...args] }; +} diff --git a/.github/consumer-builds/host.test.mjs b/.github/consumer-builds/host.test.mjs new file mode 100644 index 0000000000..e6f89a244c --- /dev/null +++ b/.github/consumer-builds/host.test.mjs @@ -0,0 +1,38 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import { posix, win32 } from 'node:path'; +import { test } from 'node:test'; +import { isInside, packageManagerCommand } from './host.mjs'; + +test('consumer isolation handles Windows separators, drive letters and sibling prefixes', () => { + assert.equal(isInside('C:\\repo', 'C:\\repo\\consumer', win32), true); + assert.equal(isInside('C:\\repo', 'c:\\REPO', win32), true); + assert.equal(isInside('C:\\repo', 'C:\\repo-copy\\consumer', win32), false); + assert.equal(isInside('C:\\repo', 'C:\\', win32), false); + assert.equal(isInside('C:\\repo', 'D:\\consumer', win32), false); + assert.equal(isInside('/repo', '/repo/consumer', posix), true); + assert.equal(isInside('/repo', '/repo-copy/consumer', posix), false); + assert.equal(isInside('/repo', '/', posix), false); +}); + +test('Windows npm and npx use node with distinct arguments, including paths with spaces', () => { + const node = 'C:\\Program Files\\nodejs\\node.exe'; + const args = ['install', 'file:C:\\app & fixtures\\library.tgz']; + assert.deepEqual(packageManagerCommand('npm', args, 'win32', node), { + command: node, + args: ['C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', ...args], + }); + assert.deepEqual(packageManagerCommand('npx', ['--no-install', 'expo'], 'win32', node).args, [ + 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npx-cli.js', + '--no-install', + 'expo', + ]); + assert.deepEqual(packageManagerCommand('npm', args, 'linux'), { command: 'npm', args }); +}); + +test('the real host can invoke the selected npm entry point', () => { + const command = packageManagerCommand('npm', ['--version']); + const result = spawnSync(command.command, command.args, { encoding: 'utf8' }); + assert.equal(result.status, 0, result.error?.message ?? result.stderr); + assert.match(result.stdout.trim(), /^\d+\.\d+\.\d+$/); +}); diff --git a/.github/consumer-builds/integration-fixture.mjs b/.github/consumer-builds/integration-fixture.mjs new file mode 100644 index 0000000000..4f1829138e --- /dev/null +++ b/.github/consumer-builds/integration-fixture.mjs @@ -0,0 +1,97 @@ +import assert from 'node:assert/strict'; +import { copyFileSync, readFileSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; + +export const integrationPlugins = [ + ['@sentry/react-native/expo', { organization: 'consumer-fixture', project: 'consumer-fixture' }], + '@react-native-firebase/app', + ['react-native-vision-camera', { enableMicrophonePermission: true }], + [ + 'react-native-audio-api', + { + iosBackgroundMode: true, + iosMicrophonePermission: 'Consumer compatibility fixture microphone access.', + androidPermissions: [ + 'android.permission.RECORD_AUDIO', + 'android.permission.MODIFY_AUDIO_SETTINGS', + ], + }, + ], +]; + +export function prepareIntegrationFixture(directory, appFixtures, bundleIdentifier) { + copyFileSync(join(appFixtures, 'App.integration.jsx'), join(directory, 'App.jsx')); + // Deliberately synthetic build inputs: no Firebase project, services or credentials. + writeFileSync( + join(directory, 'google-services.json'), + JSON.stringify( + { + project_info: { project_number: '123456789012', project_id: 'rnet-consumer-fixture' }, + client: [ + { + client_info: { + mobilesdk_app_id: '1:123456789012:android:0123456789abcdef', + android_client_info: { package_name: bundleIdentifier }, + }, + api_key: [{ current_key: 'AIzaSy' + '0'.repeat(33) }], + }, + ], + configuration_version: '1', + }, + null, + 2 + ) + '\n' + ); + writeFileSync( + join(directory, 'GoogleService-Info.plist'), + ` + + +API_KEYAIzaSy${'0'.repeat(33)} +GCM_SENDER_ID123456789012 +PLIST_VERSION1 +BUNDLE_ID${bundleIdentifier} +PROJECT_IDrnet-consumer-fixture +GOOGLE_APP_ID1:123456789012:ios:0123456789abcdef +IS_ANALYTICS_ENABLED + +` + ); + writeFileSync( + join(directory, 'metro.config.js'), + `const { getSentryExpoConfig } = require('@sentry/react-native/metro'); +module.exports = getSentryExpoConfig(__dirname); +` + ); +} + +export function verifyIntegrationFixture(directory, platform) { + const read = (file) => readFileSync(join(directory, file), 'utf8'); + if (platform === 'android') { + const manifest = read('android/app/src/main/AndroidManifest.xml'); + for (const permission of ['CAMERA', 'RECORD_AUDIO', 'MODIFY_AUDIO_SETTINGS']) { + assert.ok(manifest.includes(`android.permission.${permission}`), `Missing ${permission}`); + } + assert.ok(read('android/app/build.gradle').includes('com.google.gms.google-services')); + assert.ok(read('android/app/build.gradle').includes('sentry.gradle')); + assert.equal( + JSON.parse(read('android/app/google-services.json')).project_info.project_id, + 'rnet-consumer-fixture' + ); + } else { + const info = read('ios/ConsumerBuild/Info.plist'); + for (const key of [ + 'NSCameraUsageDescription', + 'NSMicrophoneUsageDescription', + 'UIBackgroundModes', + ]) { + assert.ok(info.includes(`${key}`), `Missing ${key}`); + } + assert.ok(info.includes('audio')); + assert.equal(JSON.parse(read('ios/Podfile.properties.json'))['ios.useFrameworks'], 'dynamic'); + const project = read('ios/ConsumerBuild.xcodeproj/project.pbxproj'); + assert.ok(project.includes('GoogleService-Info.plist')); + assert.ok(project.includes('sentry-xcode.sh')); + } + console.log(`PASS: ${platform} integration config plugins modified the generated native project`); +} diff --git a/.github/consumer-builds/matrix.mjs b/.github/consumer-builds/matrix.mjs new file mode 100644 index 0000000000..c2ead585b9 --- /dev/null +++ b/.github/consumer-builds/matrix.mjs @@ -0,0 +1,177 @@ +import { appendFileSync, readFileSync } from 'node:fs'; +import { pathToFileURL } from 'node:url'; + +const minor = (version) => version.split('.').slice(0, 2).join('.'); +const compareVersions = (left, right) => { + const a = left.split('.').map(Number); + const b = right.split('.').map(Number); + return a[0] - b[0] || a[1] - b[1] || a[2] - b[2]; +}; + +export function readCompatibility() { + return JSON.parse(readFileSync(new URL('./compatibility.json', import.meta.url), 'utf8')); +} + +export function createProfiles(config = readCompatibility()) { + const pinned = /^\d+\.\d+\.\d+$/; + const ids = new Set(); + const requireVersion = (version, label) => { + if (!pinned.test(version)) throw new Error(`Pin ${label} to an exact version`); + }; + const requireId = (id) => { + if (typeof id !== 'string' || !/^[a-z0-9-]+$/.test(id) || ids.has(id)) { + throw new Error(`Invalid or duplicate profile id: ${id}`); + } + ids.add(id); + }; + requireVersion(config.cli, 'the scaffolding CLI'); + for (const key of ['bare', 'worklets', 'expo']) { + if (!Array.isArray(config[key]) || !config[key].length) + throw new Error(`No ${key} compatibility entries`); + } + const rnMinors = new Set(); + for (const rn of config.bare) { + requireVersion(rn.reactNative, `${rn.id}.reactNative`); + requireVersion(rn.blobUtil, `${rn.id}.blobUtil`); + if (rnMinors.has(minor(rn.reactNative))) + throw new Error(`Duplicate RN minor: ${rn.reactNative}`); + rnMinors.add(minor(rn.reactNative)); + requireId(rn.id); + } + const workletsMinors = new Set(); + for (const worklets of config.worklets) { + requireVersion(worklets.version, 'Worklets'); + if (workletsMinors.has(minor(worklets.version))) + throw new Error(`Duplicate Worklets minor: ${worklets.version}`); + workletsMinors.add(minor(worklets.version)); + if (!Array.isArray(worklets.reactNative) || !worklets.reactNative.length) + throw new Error(`No RN support for Worklets ${worklets.version}`); + const declared = new Set(); + for (const rn of worklets.reactNative) { + if (!rnMinors.has(rn) || declared.has(rn)) + throw new Error(`Invalid RN declaration ${rn} for Worklets ${worklets.version}`); + declared.add(rn); + } + } + const bare = [...config.bare] + .sort((a, b) => compareVersions(a.reactNative, b.reactNative)) + .flatMap((rn) => { + const compatible = config.worklets + .filter((worklets) => worklets.reactNative.includes(minor(rn.reactNative))) + .sort((a, b) => compareVersions(a.version, b.version)); + if (!compatible.length) throw new Error(`No compatible Worklets for ${rn.id}`); + return compatible.map((worklets) => { + const id = `${rn.id}-worklets-${minor(worklets.version).replaceAll('.', '-')}`; + requireId(id); + return { ...rn, id, worklets: worklets.version, family: 'bare', cli: config.cli }; + }); + }); + const expo = config.expo.map((profile) => { + requireId(profile.id); + for (const key of [ + 'reactNative', + 'worklets', + 'blobUtil', + 'expo', + 'react', + 'buildProperties', + 'babelPreset', + 'babelCore', + ]) { + requireVersion(profile[key], `${profile.id}.${key}`); + } + if ( + !config.worklets.some( + (worklets) => + worklets.version === profile.worklets && + worklets.reactNative.includes(minor(profile.reactNative)) + ) + ) { + throw new Error(`Unsupported Expo RN/Worklets pair: ${profile.id}`); + } + return { ...profile, family: 'expo', cli: config.cli }; + }); + const latestExpo = [...expo].sort((a, b) => compareVersions(a.expo, b.expo)).at(-1); + requireVersion(latestExpo.expoAsset, `${latestExpo.id}.expoAsset`); + const smoke = { ...latestExpo, id: `${latestExpo.id}-smoke`, smoke: true }; + requireId(smoke.id); + for (const [name, version] of Object.entries(config.integrations ?? {})) { + requireVersion(version, `integrations.${name}`); + } + for (const name of [ + '@sentry/react-native', + '@react-native-firebase/app', + 'react-native-vision-camera', + 'react-native-audio-api', + ]) { + requireVersion(config.integrations?.[name], `integrations.${name}`); + } + const integration = { + ...latestExpo, + id: `${latestExpo.id}-integration`, + integrations: config.integrations, + }; + requireId(integration.id); + return { bare, expo, smoke, integration }; +} + +export function findProfile(id) { + const { bare, expo, smoke, integration } = createProfiles(); + const profile = [...bare, ...expo, smoke, integration].find((profile) => profile.id === id); + if (!profile) throw new Error(`Unknown consumer profile: ${id}`); + return profile; +} + +export function createMatrix(scope = 'expo', config = readCompatibility()) { + if (!['expo', 'full'].includes(scope)) throw new Error(`Unknown matrix scope: ${scope}`); + const { bare, expo, smoke, integration } = createProfiles(config); + const profiles = + scope === 'full' ? [...bare, ...expo, smoke, integration] : [...expo, smoke, integration]; + const latestExpo = [...expo].sort((a, b) => compareVersions(a.expo, b.expo)).at(-1); + return { + scope, + matrix: { + include: [ + ...profiles.flatMap((profile) => + ['android', 'ios'].map((platform) => ({ + profile: profile.id, + platform, + id: `${profile.id}-${platform}`, + runner: platform === 'ios' ? 'macos-26' : 'ubuntu-24.04', + smoke: Boolean(profile.smoke), + aab: profile.id === latestExpo.id && platform === 'android', + })) + ), + { + profile: latestExpo.id, + platform: 'android', + id: `${latestExpo.id}-android-windows`, + runner: 'windows-2025', + smoke: false, + aab: false, + }, + ], + }, + }; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + const result = createMatrix(process.argv[2] ?? 'expo'); + console.log(JSON.stringify(result, null, 2)); + if (process.env.GITHUB_OUTPUT) { + for (const [key, value] of Object.entries(result)) { + appendFileSync( + process.env.GITHUB_OUTPUT, + `${key}=${typeof value === 'string' ? value : JSON.stringify(value)}\n` + ); + } + } + if (process.env.GITHUB_STEP_SUMMARY) { + const counts = { android: 0, ios: 0 }; + for (const cell of result.matrix.include) counts[cell.platform]++; + appendFileSync( + process.env.GITHUB_STEP_SUMMARY, + `### Consumer build matrix (${result.scope})\n\n${result.matrix.include.length} Release app builds: ${counts.android} Android and ${counts.ios} iOS. One additional job packs the shared library.\n` + ); + } +} diff --git a/.github/consumer-builds/matrix.test.mjs b/.github/consumer-builds/matrix.test.mjs new file mode 100644 index 0000000000..fd3892c20b --- /dev/null +++ b/.github/consumer-builds/matrix.test.mjs @@ -0,0 +1,168 @@ +import assert from 'node:assert/strict'; +import { execFileSync } from 'node:child_process'; +import { mkdtempSync, readFileSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { test } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import { createMatrix, createProfiles, findProfile, readCompatibility } from './matrix.mjs'; + +test('default coverage includes Expo SDKs, Windows, runtime smoke and integration apps', () => { + const { scope, matrix } = createMatrix(); + assert.equal(scope, 'expo'); + assert.deepEqual( + matrix.include.map((cell) => cell.id), + [ + 'expo-55-android', + 'expo-55-ios', + 'expo-56-android', + 'expo-56-ios', + 'expo-57-android', + 'expo-57-ios', + 'expo-58-android', + 'expo-58-ios', + 'expo-58-smoke-android', + 'expo-58-smoke-ios', + 'expo-58-integration-android', + 'expo-58-integration-ios', + 'expo-58-android-windows', + ] + ); +}); + +test('the full matrix builds every declared compatible pair on both platforms', () => { + const { matrix } = createMatrix('full'); + const { bare, expo } = createProfiles(); + assert.equal(bare.length, 16); + assert.deepEqual( + expo.map((p) => p.id), + ['expo-55', 'expo-56', 'expo-57', 'expo-58'] + ); + assert.equal(matrix.include.length, 45); + assert.equal(matrix.include.filter((cell) => cell.profile.startsWith('expo-')).length, 13); + const expected = { + 0.83: ['0.10', '0.11', '0.12'], + 0.84: ['0.10', '0.11', '0.12'], + 0.85: ['0.10', '0.11', '0.12'], + 0.86: ['0.10', '0.11', '0.12', '0.13'], + 0.87: ['0.12', '0.13'], + 0.88: ['0.13'], + }; + const minor = (version) => version.split('.').slice(0, 2).join('.'); + for (const [rn, worklets] of Object.entries(expected)) { + assert.deepEqual( + bare.filter((p) => minor(p.reactNative) === rn).map((p) => minor(p.worklets)), + worklets + ); + } + for (const profile of [...bare, ...expo]) { + assert.deepEqual( + matrix.include + .filter((cell) => cell.profile === profile.id && cell.runner !== 'windows-2025') + .map((cell) => cell.platform), + ['android', 'ios'] + ); + } +}); + +test('bare expansion does not depend on JSON entry ordering', () => { + const config = readCompatibility(); + config.bare.reverse(); + config.worklets.reverse(); + assert.deepEqual(createProfiles(config).bare, createProfiles().bare); +}); + +test('invalid declarations fail instead of silently dropping compatibility coverage', () => { + const unknown = readCompatibility(); + unknown.worklets[0].reactNative.push('0.89'); + assert.throws(() => createProfiles(unknown), /Invalid RN declaration/); + const uncovered = readCompatibility(); + for (const worklets of uncovered.worklets) + worklets.reactNative = worklets.reactNative.filter((rn) => rn !== '0.83'); + assert.throws(() => createProfiles(uncovered), /No compatible Worklets for rn-0-83/); + const expo = readCompatibility(); + expo.expo[0].worklets = '0.14.0'; + assert.throws(() => createProfiles(expo), /Unsupported Expo RN\/Worklets pair/); +}); + +test('each artifact id is unique across bare and Expo cells', () => { + const { matrix } = createMatrix('full'); + const ids = matrix.include.map((cell) => cell.id); + assert.equal(new Set(ids).size, ids.length); +}); + +test('profile lookup supplies its family and pinned CLI, and rejects typos', () => { + assert.equal(findProfile('rn-0-83-worklets-0-10').family, 'bare'); + for (const sdk of [55, 56, 57, 58]) assert.equal(findProfile(`expo-${sdk}`).family, 'expo'); + assert.match(findProfile('rn-0-88-worklets-0-13').cli, /^\d+\.\d+\.\d+$/); + assert.throws(() => findProfile('rn-0-89'), /Unknown consumer profile/); + assert.throws(() => createMatrix('typo'), /Unknown matrix scope/); +}); + +test('the CLI writes single-line JSON matrices usable by GitHub job outputs', () => { + const directory = mkdtempSync(join(tmpdir(), 'rnet-matrix-outputs-')); + const output = join(directory, 'outputs'); + const summary = join(directory, 'summary'); + try { + execFileSync(process.execPath, [fileURLToPath(new URL('./matrix.mjs', import.meta.url))], { + env: { ...process.env, GITHUB_OUTPUT: output, GITHUB_STEP_SUMMARY: summary }, + }); + const outputs = Object.fromEntries( + readFileSync(output, 'utf8') + .trim() + .split('\n') + .map((line) => { + const separator = line.indexOf('='); + return [line.slice(0, separator), line.slice(separator + 1)]; + }) + ); + assert.equal(outputs.scope, 'expo'); + assert.equal(JSON.parse(outputs.matrix).include.length, 13); + assert.match(readFileSync(summary, 'utf8'), /13 Release app builds: 7 Android and 6 iOS/); + } finally { + rmSync(directory, { recursive: true, force: true }); + } +}); + +test('Windows coverage stays on the newest Expo SDK regardless of configuration order', () => { + const config = readCompatibility(); + config.expo.reverse(); + const windows = createMatrix('full', config).matrix.include.filter( + (cell) => cell.runner === 'windows-2025' + ); + assert.deepEqual(windows, [ + { + profile: 'expo-58', + platform: 'android', + id: 'expo-58-android-windows', + runner: 'windows-2025', + smoke: false, + aab: false, + }, + ]); + const smoke = createMatrix().matrix.include.filter((cell) => cell.smoke); + assert.deepEqual( + smoke.map((cell) => cell.platform), + ['android', 'ios'] + ); + assert.ok(smoke.every((cell) => cell.profile === 'expo-58-smoke')); +}); + +test('integration pins are exact, cover both platforms and follow the newest Expo; only one cell builds AAB', () => { + const config = readCompatibility(); + config.expo.reverse(); + const matrix = createMatrix('expo', config).matrix.include; + const integration = matrix.filter((cell) => cell.profile.endsWith('-integration')); + assert.deepEqual( + integration.map((cell) => cell.platform), + ['android', 'ios'] + ); + assert.ok(integration.every((cell) => cell.profile === 'expo-58-integration')); + assert.equal(findProfile('expo-58-integration').integrations['react-native-audio-api'], '0.13.6'); + assert.deepEqual( + matrix.filter((cell) => cell.aab).map((cell) => cell.id), + ['expo-58-android'] + ); + config.integrations['@sentry/react-native'] = '^8.35.0'; + assert.throws(() => createMatrix('expo', config), /Pin integrations/); +}); diff --git a/.github/consumer-builds/prepare.mjs b/.github/consumer-builds/prepare.mjs new file mode 100644 index 0000000000..ec9b338130 --- /dev/null +++ b/.github/consumer-builds/prepare.mjs @@ -0,0 +1,246 @@ +import { spawnSync } from 'node:child_process'; +import { + copyFileSync, + existsSync, + lstatSync, + mkdirSync, + readFileSync, + realpathSync, + statSync, + writeFileSync, +} from 'node:fs'; +import { basename, dirname, join, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { findProfile } from './matrix.mjs'; +import { isInside, packageManagerCommand } from './host.mjs'; +import { prepareSmokeFixture } from './smoke-fixture.mjs'; +import { + integrationPlugins, + prepareIntegrationFixture, + verifyIntegrationFixture, +} from './integration-fixture.mjs'; + +const fixtures = dirname(fileURLToPath(import.meta.url)); +const repository = resolve(fixtures, '../..'); +const appFixtures = join(repository, 'apps/consumer-fixtures'); +const [profileId, platform, archiveArgument, directoryArgument] = process.argv.slice(2); +if ( + !['android', 'ios'].includes(platform) || + !profileId || + !archiveArgument || + !directoryArgument +) { + throw new Error( + 'Usage: node .github/consumer-builds/prepare.mjs android|ios ' + ); +} +const profile = findProfile(profileId); +const abi = profile.smoke && platform === 'android' ? 'x86_64' : 'arm64-v8a'; +const bundleIdentifier = profile.smoke + ? 'com.swmansion.executorch.consumersmoke' + : 'com.swmansion.executorch.consumerbuild'; +const archive = realpathSync(archiveArgument); +const requestedDirectory = resolve(directoryArgument); +if (!statSync(archive).isFile() || !archive.endsWith('.tgz')) { + throw new Error('The library must be a packed .tgz file, not a workspace or symlinked directory'); +} +// npm must not discover the repository's workspaces or hoisted dependencies. +mkdirSync(dirname(requestedDirectory), { recursive: true }); +const directory = join(realpathSync(dirname(requestedDirectory)), basename(requestedDirectory)); +if (isInside(repository, directory)) { + throw new Error('Create the consumer outside the repository to avoid workspace resolution'); +} +if (existsSync(directory)) throw new Error(`Refusing to overwrite ${directory}`); +if (process.env.RNET_SKIP_DOWNLOAD) + throw new Error('Unset RNET_SKIP_DOWNLOAD: this test exercises the real postinstall'); + +function run(command, args, cwd) { + console.log(`Running ${command} ${args.join(' ')} in ${cwd}`); + const selected = packageManagerCommand(command, args); + const result = spawnSync(selected.command, selected.args, { + cwd, + stdio: 'inherit', + env: process.env, + }); + if (result.error) throw result.error; + if (result.status !== 0) throw new Error(`${command} failed (${result.status ?? result.signal})`); +} + +function replaceInFile(path, pattern, replacement) { + const original = readFileSync(path, 'utf8'); + if (!pattern.test(original)) + throw new Error(`Template changed: cannot find ${pattern} in ${path}`); + writeFileSync(path, original.replace(pattern, replacement)); +} + +let manifest; +if (profile.family === 'bare') { + run( + 'npx', + [ + '--yes', + `@react-native-community/cli@${profile.cli}`, + 'init', + 'ConsumerBuild', + '--version', + profile.reactNative, + '--skip-install', + '--skip-git-init', + '--install-pods', + 'false', + '--directory', + directory, + ], + dirname(directory) + ); + manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8')); + Object.assign(manifest.dependencies, { + 'react-native-worklets': profile.worklets, + // blob-util 1.0 requires RN >=0.84. Exercise the supported RN floor here. + 'react-native-blob-util': profile.blobUtil, + }); + writeFileSync( + join(directory, 'babel.config.js'), + `module.exports = { + presets: ['module:@react-native/babel-preset'], + plugins: ['react-native-worklets/plugin'], +}; +` + ); + writeFileSync( + join(directory, 'index.js'), + `import {AppRegistry} from 'react-native'; +import App from './App'; +AppRegistry.registerComponent('ConsumerBuild', () => App); +` + ); + // Replace the template's App.tsx so Metro bundles this fixture. + copyFileSync(join(appFixtures, 'App.jsx'), join(directory, 'App.tsx')); + replaceInFile( + join(directory, 'ios/Podfile'), + /^platform :ios, min_ios_version_supported$/m, + "platform :ios, [Gem::Version.new(min_ios_version_supported), Gem::Version.new('17.0')].max.to_s" + ); + if (platform === 'android') { + replaceInFile( + join(directory, 'android/build.gradle'), + /minSdkVersion = \d+/, + 'minSdkVersion = 26' + ); + replaceInFile( + join(directory, 'android/gradle.properties'), + /^reactNativeArchitectures=.*$/m, + 'reactNativeArchitectures=arm64-v8a' + ); + replaceInFile( + join(directory, 'android/app/build.gradle'), + /def enableProguardInReleaseBuilds = false/, + 'def enableProguardInReleaseBuilds = true' + ); + } +} else { + mkdirSync(directory); + manifest = { + name: 'consumer-build', + version: '1.0.0', + private: true, + main: 'index.js', + dependencies: { + 'expo': profile.expo, + 'react': profile.react, + 'react-native': profile.reactNative, + 'expo-build-properties': profile.buildProperties, + 'react-native-worklets': profile.worklets, + 'react-native-blob-util': profile.blobUtil, + ...(profile.smoke ? { 'expo-asset': profile.expoAsset } : {}), + ...profile.integrations, + }, + devDependencies: { '@babel/core': profile.babelCore, 'babel-preset-expo': profile.babelPreset }, + }; + writeFileSync( + join(directory, 'app.json'), + JSON.stringify( + { + expo: { + name: 'ConsumerBuild', + slug: 'consumer-build', + version: '1.0.0', + ios: { + bundleIdentifier, + ...(profile.integrations ? { googleServicesFile: './GoogleService-Info.plist' } : {}), + ...(profile.smoke + ? { infoPlist: { NSAppTransportSecurity: { NSAllowsArbitraryLoads: true } } } + : {}), + }, + android: { + package: bundleIdentifier, + ...(profile.integrations ? { googleServicesFile: './google-services.json' } : {}), + }, + plugins: [ + [ + 'expo-build-properties', + { + ios: { + deploymentTarget: '17.0', + ...(profile.integrations ? { useFrameworks: 'dynamic' } : {}), + }, + android: { + minSdkVersion: 26, + buildArchs: [abi], + enableMinifyInReleaseBuilds: true, + ...(profile.smoke ? { usesCleartextTraffic: true } : {}), + }, + }, + ], + ...(profile.integrations ? integrationPlugins : []), + ], + }, + }, + null, + 2 + ) + '\n' + ); + writeFileSync( + join(directory, 'index.js'), + `import {registerRootComponent} from 'expo'; +import App from './App'; +registerRootComponent(App); +` + ); + copyFileSync(join(appFixtures, 'App.jsx'), join(directory, 'App.jsx')); + if (profile.smoke) await prepareSmokeFixture(directory); + if (profile.integrations) prepareIntegrationFixture(directory, appFixtures, bundleIdentifier); +} +copyFileSync(archive, join(directory, 'react-native-executorch.tgz')); +manifest.dependencies['react-native-executorch'] = 'file:./react-native-executorch.tgz'; +writeFileSync(join(directory, 'package.json'), JSON.stringify(manifest, null, 2) + '\n'); + +// Restrict downloads to this cell's platform, but keep all its optional native +// libraries enabled. No cache of extracted node_modules is shared between apps. +writeFileSync( + join(directory, 'consumer-profile.json'), + JSON.stringify({ ...profile, platform }, null, 2) + '\n' +); +// Emulator installs need the default downloads: the ABI-independent +// executorch.jar is distributed in the arm64 core archive. +if (platform === 'android' && profile.smoke) delete process.env.RNET_TARGET; +else process.env.RNET_TARGET = platform === 'android' ? `android-${abi}` : 'ios'; +run('npm', ['install', '--foreground-scripts', '--no-audit', '--no-fund'], directory); +const installed = join(directory, 'node_modules/react-native-executorch'); +if (lstatSync(installed).isSymbolicLink() || !isInside(directory, realpathSync(installed))) + throw new Error('Consumer installed a linked workspace instead of the tarball'); +for (const file of [ + 'lib/module/index.js', + 'lib/typescript/src/index.d.ts', + 'rne-build-config.json', +]) { + if (!existsSync(join(installed, file))) throw new Error(`Installed package is missing ${file}`); +} +if (profile.family === 'expo') { + run( + 'npx', + ['--no-install', 'expo', 'prebuild', '--platform', platform, '--no-install'], + directory + ); + if (profile.integrations) verifyIntegrationFixture(directory, platform); +} diff --git a/.github/consumer-builds/smoke-fixture.mjs b/.github/consumer-builds/smoke-fixture.mjs new file mode 100644 index 0000000000..8800fcca89 --- /dev/null +++ b/.github/consumer-builds/smoke-fixture.mjs @@ -0,0 +1,44 @@ +import { createHash, randomUUID } from 'node:crypto'; +import { copyFileSync, writeFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// Same revision and checksum as scripts/fetch-test-fixtures.sh. Never commit +// model binaries or resolve a mutable Hugging Face branch in the smoke build. +export const modelUrl = + 'https://huggingface.co/software-mansion/MediaPipe-Selfie-Segmentation-ExecuTorch/resolve/13a9494d8230279b47973b91c94b1aa902d307a6/xnnpack/selfie_segmentation_xnnpack_fp32.pte'; +export const modelChecksum = '176aba6a0719b56391586a3d19396315305c7adb5c16aafda350fecc596cebf9'; + +export async function prepareSmokeFixture(directory) { + const response = await fetch(modelUrl, { signal: AbortSignal.timeout(120000) }); + if (!response.ok) throw new Error(`Model fixture download failed: ${response.status}`); + const bytes = Buffer.from(await response.arrayBuffer()); + if (createHash('sha256').update(bytes).digest('hex') !== modelChecksum) { + throw new Error('Model fixture checksum mismatch'); + } + writeFileSync(join(directory, 'smoke-model.pte'), bytes); + writeFileSync( + join(directory, 'smoke-config.json'), + JSON.stringify( + { + token: randomUUID(), + port: 18765, + bundleIdentifier: 'com.swmansion.executorch.consumersmoke', + }, + null, + 2 + ) + '\n' + ); + copyFileSync( + join(dirname(fileURLToPath(import.meta.url)), '../../apps/consumer-fixtures/App.smoke.jsx'), + join(directory, 'App.jsx') + ); + writeFileSync( + join(directory, 'metro.config.js'), + `const {getDefaultConfig} = require('expo/metro-config'); +const config = getDefaultConfig(__dirname); +config.resolver.assetExts.push('pte'); +module.exports = config; +` + ); +} diff --git a/.github/consumer-builds/smoke-runner.mjs b/.github/consumer-builds/smoke-runner.mjs new file mode 100644 index 0000000000..4657e2906f --- /dev/null +++ b/.github/consumer-builds/smoke-runner.mjs @@ -0,0 +1,177 @@ +import assert from 'node:assert/strict'; +import { execFile, spawn } from 'node:child_process'; +import { createServer } from 'node:http'; +import { createWriteStream, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { join, resolve } from 'node:path'; +import { promisify } from 'node:util'; +import { pathToFileURL } from 'node:url'; + +const execute = promisify(execFile); + +export async function startReporter(token, port = 18765, timeout = 180000) { + let accept, reject; + const result = new Promise((resolve, fail) => { + accept = resolve; + reject = fail; + }); + // A failure may arrive while native installation/launch is still awaiting. + result.catch(() => {}); + const server = createServer((request, response) => { + if (request.method !== 'POST' || request.url !== `/result/${token}`) { + response.writeHead(404).end(); + return; + } + let body = ''; + request.on('data', (chunk) => { + body += chunk; + if (body.length > 16384) request.destroy(new Error('Smoke report exceeds 16 KB')); + }); + request.on('error', reject); + request.on('end', () => { + try { + const report = JSON.parse(body); + assert.equal(report.status, 'pass', report.error ?? 'App reported failure'); + assert.deepEqual(report.checks, ['tensor', 'worklet', 'model']); + assert.equal(report.inference?.elements, 256 * 256); + assert.ok(report.inference?.backend?.includes('XnnpackBackend')); + response.writeHead(200, { Connection: 'close' }).end('ok'); + accept(report); + } catch (error) { + response.writeHead(400, { Connection: 'close' }).end(String(error)); + reject(error); + } + }); + }); + await new Promise((resolve, reject) => { + server.once('error', reject); + server.listen(port, '127.0.0.1', resolve); + }); + let timer; + return { + port: server.address().port, + // Booting and installing are setup; only app execution uses this deadline. + waitForReport: () => { + timer ??= setTimeout( + () => reject(new Error('App did not report passing smoke assertions before the timeout')), + timeout + ); + return result; + }, + close: async () => { + clearTimeout(timer); + await new Promise((resolve) => server.close(resolve)); + }, + }; +} + +async function main() { + const [platform, artifact, consumer, logs] = process.argv.slice(2); + if (!['android', 'ios'].includes(platform) || !artifact || !consumer || !logs) { + throw new Error( + 'Usage: node smoke-runner.mjs android|ios ' + ); + } + mkdirSync(logs, { recursive: true }); + const config = JSON.parse(readFileSync(join(consumer, 'smoke-config.json'), 'utf8')); + const reporter = await startReporter(config.token, config.port); + const output = createWriteStream(join(logs, 'runtime.log')); + let logger, + udid, + bootedByUs = false; + try { + if (platform === 'android') { + await execute('adb', ['install', '-r', resolve(artifact)]); + await execute('adb', ['reverse', `tcp:${config.port}`, `tcp:${config.port}`]); + await execute('adb', ['logcat', '-c']); + logger = spawn('adb', ['logcat', '-v', 'threadtime']); + logger.stdout.pipe(output, { end: false }); + logger.stderr.pipe(output, { end: false }); + await execute('adb', ['shell', 'am', 'force-stop', config.bundleIdentifier]); + reporter.waitForReport(); + await execute('adb', [ + 'shell', + 'am', + 'start', + '-W', + '-n', + `${config.bundleIdentifier}/.MainActivity`, + ]); + } else { + const devices = JSON.parse( + (await execute('xcrun', ['simctl', 'list', 'devices', 'available', '-j'])).stdout + ); + const device = Object.entries(devices.devices) + .filter(([runtime]) => runtime.includes('.iOS-')) + .flatMap(([, devices]) => devices) + .find((device) => device.isAvailable && device.name.startsWith('iPhone')); + if (!device) throw new Error('No available iPhone simulator'); + udid = device.udid; + if (device.state !== 'Booted') { + await execute('xcrun', ['simctl', 'boot', udid]); + bootedByUs = true; + } + console.log(`Waiting up to 10 minutes for simulator ${device.name} (${udid})`); + try { + const boot = await execute('xcrun', ['simctl', 'bootstatus', udid, '-b'], { + timeout: 600000, + maxBuffer: 8 * 1024 * 1024, + }); + writeFileSync(join(logs, 'simulator-boot.log'), boot.stdout + boot.stderr); + } catch (error) { + writeFileSync( + join(logs, 'simulator-boot.log'), + `${error.stdout ?? ''}${error.stderr ?? ''}\n${error.message}\n` + ); + throw error; + } + await execute('xcrun', ['simctl', 'install', udid, resolve(artifact)]); + reporter.waitForReport(); + logger = spawn('xcrun', [ + 'simctl', + 'launch', + '--console', + '--terminate-running-process', + udid, + config.bundleIdentifier, + ]); + logger.stdout.pipe(output, { end: false }); + logger.stderr.pipe(output, { end: false }); + } + logger.on('error', (error) => output.write(`Log capture failed: ${error.message}\n`)); + const report = await reporter.waitForReport(); + writeFileSync(join(logs, 'smoke-result.json'), JSON.stringify(report, null, 2) + '\n'); + console.log( + 'PASS: native tensor, worklet typed-array round trip and bundled XNNPACK inference' + ); + } finally { + logger?.stdout.unpipe(output); + logger?.stderr.unpipe(output); + logger?.kill(); + output.end(); + await reporter.close(); + if (platform === 'android') { + await execute('adb', ['shell', 'am', 'force-stop', config.bundleIdentifier], { + timeout: 15000, + }).catch(() => {}); + await execute('adb', ['reverse', '--remove', `tcp:${config.port}`], { + timeout: 15000, + }).catch(() => {}); + } else if (udid) { + await execute('xcrun', ['simctl', 'terminate', udid, config.bundleIdentifier], { + timeout: 15000, + }).catch(() => {}); + if (bootedByUs) { + await execute('xcrun', ['simctl', 'shutdown', udid], { timeout: 15000 }).catch( + () => {} + ); + } + } + } +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + main().catch((error) => { + console.error(error); + process.exitCode = 1; + }); +} diff --git a/.github/consumer-builds/smoke-runner.test.mjs b/.github/consumer-builds/smoke-runner.test.mjs new file mode 100644 index 0000000000..6bfd7bc54b --- /dev/null +++ b/.github/consumer-builds/smoke-runner.test.mjs @@ -0,0 +1,89 @@ +import assert from 'node:assert/strict'; +import { test } from 'node:test'; +import { startReporter } from './smoke-runner.mjs'; + +const passing = { + status: 'pass', + checks: ['tensor', 'worklet', 'model'], + inference: { elements: 65536, backend: ['XnnpackBackend'] }, +}; + +test('a valid app report passes, and stale tokens cannot pass the collector', async () => { + const reporter = await startReporter('current-build', 0); + try { + const url = `http://127.0.0.1:${reporter.port}/result/`; + assert.equal( + (await fetch(url + 'previous-build', { method: 'POST', body: JSON.stringify(passing) })) + .status, + 404 + ); + assert.equal( + (await fetch(url + 'current-build', { method: 'POST', body: JSON.stringify(passing) })) + .status, + 200 + ); + assert.deepEqual(await reporter.waitForReport(), passing); + } finally { + await reporter.close(); + } +}); + +for (const report of [ + { ...passing, status: 'fail', error: 'Native assertion failed' }, + { ...passing, checks: ['tensor'] }, + { ...passing, inference: { elements: 0, backend: [] } }, +]) { + test(`CI rejects a failed or incomplete report: ${JSON.stringify(report)}`, async () => { + const reporter = await startReporter('build', 0); + try { + const rejected = assert.rejects(reporter.waitForReport()); + assert.equal( + ( + await fetch(`http://127.0.0.1:${reporter.port}/result/build`, { + method: 'POST', + body: JSON.stringify(report), + }) + ).status, + 400 + ); + await rejected; + } finally { + await reporter.close(); + } + }); +} + +test('an app crash or missing callback fails with a timeout', async () => { + const reporter = await startReporter('missing-app', 0, 25); + try { + await assert.rejects(reporter.waitForReport(), /timeout/); + } finally { + await reporter.close(); + } +}); + + +test('simulator setup does not consume the app deadline, and waiting again does not reset it', async (t) => { + t.mock.timers.enable({ apis: ['setTimeout'] }); + const reporter = await startReporter('cold-boot', 0, 100); + try { + // A cold simulator may spend minutes migrating before the app can launch. + t.mock.timers.tick(600000); + const result = reporter.waitForReport(); + let settled = false; + result.then( + () => { settled = true; }, + () => { settled = true; } + ); + t.mock.timers.tick(99); + await Promise.resolve(); + assert.equal(settled, false, 'setup time must not expire the app deadline'); + assert.equal(reporter.waitForReport(), result); + const rejected = assert.rejects(result, /timeout/); + t.mock.timers.tick(1); + await rejected; + } finally { + await reporter.close(); + t.mock.timers.reset(); + } +}); diff --git a/.github/consumer-builds/validate-aab.mjs b/.github/consumer-builds/validate-aab.mjs new file mode 100644 index 0000000000..90b6419095 --- /dev/null +++ b/.github/consumer-builds/validate-aab.mjs @@ -0,0 +1,79 @@ +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import { spawnSync } from 'node:child_process'; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { join, resolve } from 'node:path'; +import { pathToFileURL } from 'node:url'; + +const version = '1.18.3'; +const checksum = 'a099cfa1543f55593bc2ed16a70a7c67fe54b1747bb7301f37fdfd6d91028e29'; + +export function verifyBundleEntries(listing) { + const entries = new Set(listing.trim().split(/\r?\n/)); + for (const file of [ + 'BundleConfig.pb', + 'base/manifest/AndroidManifest.xml', + 'base/dex/classes.dex', + 'base/assets/index.android.bundle', + ...[ + 'RnExecutorch', + 'executorch', + 'xnnpack_executorch_backend', + 'vulkan_executorch_backend', + ].map((library) => `base/lib/arm64-v8a/lib${library}.so`), + ]) + assert.ok(entries.has(file), `AAB is missing ${file}`); +} + +function run(command, args, capture = false) { + const result = spawnSync(command, args, { + encoding: 'utf8', + stdio: capture ? 'pipe' : 'inherit', + timeout: 120000, + maxBuffer: 8 * 1024 * 1024, + }); + if (result.error) throw result.error; + if (result.status !== 0) + throw new Error(`${command} failed: ${result.stderr ?? result.signal ?? result.status}`); + return result.stdout; +} + +async function main() { + const [bundle, cache, logs] = process.argv.slice(2); + if (!bundle || !cache || !logs) + throw new Error('Usage: validate-aab.mjs '); + mkdirSync(cache, { recursive: true }); + mkdirSync(logs, { recursive: true }); + const tool = join(cache, `bundletool-all-${version}.jar`); + if (!existsSync(tool)) { + const response = await fetch( + `https://github.com/google/bundletool/releases/download/${version}/bundletool-all-${version}.jar`, + { signal: AbortSignal.timeout(120000) } + ); + if (!response.ok) throw new Error(`bundletool download failed: ${response.status}`); + const bytes = Buffer.from(await response.arrayBuffer()); + assert.equal( + createHash('sha256').update(bytes).digest('hex'), + checksum, + 'bundletool checksum mismatch' + ); + writeFileSync(tool, bytes); + } + assert.equal( + createHash('sha256').update(readFileSync(tool)).digest('hex'), + checksum, + 'Cached bundletool checksum mismatch' + ); + run('java', ['-jar', tool, 'validate', `--bundle=${resolve(bundle)}`]); + const listing = run('jar', ['tf', resolve(bundle)], true); + writeFileSync(join(logs, 'aab-files.log'), listing); + verifyBundleEntries(listing); + console.log('PASS: bundletool validation, bundled JS and arm64 native libraries'); +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + main().catch((error) => { + console.error(error); + process.exitCode = 1; + }); +} diff --git a/.github/consumer-builds/validate-aab.test.mjs b/.github/consumer-builds/validate-aab.test.mjs new file mode 100644 index 0000000000..32389e3119 --- /dev/null +++ b/.github/consumer-builds/validate-aab.test.mjs @@ -0,0 +1,27 @@ +import assert from 'node:assert/strict'; +import { test } from 'node:test'; +import { verifyBundleEntries } from './validate-aab.mjs'; + +const entries = [ + 'BundleConfig.pb', + 'base/manifest/AndroidManifest.xml', + 'base/dex/classes.dex', + 'base/assets/index.android.bundle', + ...['RnExecutorch', 'executorch', 'xnnpack_executorch_backend', 'vulkan_executorch_backend'].map( + (library) => `base/lib/arm64-v8a/lib${library}.so` + ), +]; + +test('bundle packaging rejects missing JS, dex or native libraries, including libraries in the wrong ABI', () => { + verifyBundleEntries(entries.join('\r\n')); + for (const missing of entries) { + assert.throws( + () => verifyBundleEntries(entries.filter((file) => file !== missing).join('\n')), + /AAB is missing/ + ); + } + assert.throws( + () => verifyBundleEntries(entries.join('\n').replaceAll('/arm64-v8a/', '/x86_64/')), + /AAB is missing/ + ); +}); diff --git a/.github/workflows/consumer-builds.yml b/.github/workflows/consumer-builds.yml new file mode 100644 index 0000000000..a822579732 --- /dev/null +++ b/.github/workflows/consumer-builds.yml @@ -0,0 +1,293 @@ +name: Consumer builds + +on: + pull_request: + branches: [main] + paths: + - '.github/workflows/consumer-build*.yml' + - '.github/consumer-builds/**' + - 'apps/consumer-fixtures/**' + - '.github/actions/setup/**' + - 'packages/react-native-executorch/**' + - 'package.json' + - 'yarn.lock' + - '.nvmrc' + workflow_dispatch: + inputs: + scope: + description: Version coverage + type: choice + options: [expo, full] + default: expo + # TODO: After validating Expo PR builds, consider moving regular Expo coverage + # to a daily cron job. Keep the full bare RN matrix available manually. + # schedule: + # - cron: '17 4 * * *' + +permissions: + contents: read + +concurrency: + group: consumer-builds-${{ github.ref }} + cancel-in-progress: true + +jobs: + plan: + runs-on: ubuntu-24.04 + timeout-minutes: 5 + outputs: + matrix: ${{ steps.matrix.outputs.matrix }} + scope: ${{ steps.matrix.outputs.scope }} + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc + - name: Validate consumer harness + run: | + node --check .github/consumer-builds/prepare.mjs + node --test .github/consumer-builds/*.test.mjs + - name: Generate version matrices + id: matrix + env: + MATRIX_SCOPE: ${{ inputs.scope || 'expo' }} + run: node .github/consumer-builds/matrix.mjs "$MATRIX_SCOPE" + + package: + needs: plan + runs-on: ubuntu-24.04 + timeout-minutes: 25 + env: + RNET_SKIP_DOWNLOAD: '1' + RNE_SKIP_INSTALL: '1' + GIT_LFS_SKIP_SMUDGE: '1' + steps: + - uses: actions/checkout@v6 + - uses: ./.github/actions/setup + - name: Build the same tarball used for publishing + working-directory: packages/react-native-executorch + run: ./scripts/create-package.sh + - name: Check and stage the published files + run: | + listing=packages/react-native-executorch/build.log + grep -Fx 'package/lib/module/index.js' "$listing" + grep -Fx 'package/lib/typescript/src/index.d.ts' "$listing" + grep -Fx 'package/third-party/common/phonemis/phonemis_sources.rb' "$listing" + grep -Fx 'package/LICENSE' "$listing" + if grep -E '^package/(node_modules/|third-party/(include/|android/libs/|ios/libs/))' "$listing"; then + echo 'Package contains dependencies or downloaded native artifacts' >&2 + exit 1 + fi + cp packages/react-native-executorch/react-native-executorch-*.tgz "$RUNNER_TEMP/react-native-executorch.tgz" + - uses: actions/upload-artifact@v4 + with: + name: consumer-library + path: ${{ runner.temp }}/react-native-executorch.tgz + if-no-files-found: error + retention-days: 3 + + build: + needs: [plan, package] + name: ${{ matrix.id }} + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.plan.outputs.matrix) }} + runs-on: ${{ matrix.runner }} + timeout-minutes: 90 + defaults: + run: + shell: bash + env: + CI: '1' + EXPO_NO_TELEMETRY: '1' + SENTRY_DISABLE_AUTO_UPLOAD: 'true' + CONSUMER_ABI: ${{ matrix.smoke && matrix.platform == 'android' && 'x86_64' || 'arm64-v8a' }} + steps: + - name: Set consumer paths + if: runner.os != 'Windows' + run: | + echo "CONSUMER_DIR=$RUNNER_TEMP/ConsumerBuild" >> "$GITHUB_ENV" + echo "LOG_DIR=$RUNNER_TEMP/consumer-logs" >> "$GITHUB_ENV" + - name: Set short Windows consumer paths + if: runner.os == 'Windows' + shell: pwsh + run: | + 'CONSUMER_DIR=C:\rnet\app' | Out-File $env:GITHUB_ENV -Encoding utf8 -Append + "LOG_DIR=$env:RUNNER_TEMP/consumer-logs" | Out-File $env:GITHUB_ENV -Encoding utf8 -Append + git config --global core.longpaths true + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc + - name: Validate Windows host helpers + if: runner.os == 'Windows' + run: node --test .github/consumer-builds/host.test.mjs + - uses: actions/download-artifact@v4 + with: + name: consumer-library + path: ${{ runner.temp }}/consumer-package + - name: Record toolchain + run: | + mkdir -p "$LOG_DIR" + { + uname -a + node --version + npm --version + if [[ "$RUNNER_OS" == macOS ]]; then + test "$(uname -m)" = arm64 + xcodebuild -version + ruby --version + pod --version + fi + } 2>&1 | tee "$LOG_DIR/toolchain.log" + - uses: actions/setup-java@v5 + if: matrix.platform == 'android' + with: + distribution: temurin + java-version: '17' + - name: Use the hosted runner's Android SDK + if: matrix.platform == 'android' && runner.os != 'Windows' + run: | + test -n "$ANDROID_HOME" + test -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" + echo "$ANDROID_HOME/cmdline-tools/latest/bin" >> "$GITHUB_PATH" + - name: Record Android toolchain + if: matrix.platform == 'android' && runner.os != 'Windows' + run: | + { + java -version + sdkmanager --version + } 2>&1 | tee -a "$LOG_DIR/toolchain.log" + - name: Use and record the Windows Android SDK + if: runner.os == 'Windows' + shell: pwsh + run: | + New-Item -ItemType Directory -Force $env:LOG_DIR | Out-Null + $tools = Join-Path $env:ANDROID_HOME 'cmdline-tools/latest/bin' + if (!(Test-Path (Join-Path $tools 'sdkmanager.bat'))) { throw 'Android SDK command-line tools are missing' } + $tools | Out-File $env:GITHUB_PATH -Encoding utf8 -Append + & java -version 2>&1 | Tee-Object -FilePath "$env:LOG_DIR/toolchain.log" -Append + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + & (Join-Path $tools 'sdkmanager.bat') --version 2>&1 | Tee-Object -FilePath "$env:LOG_DIR/toolchain.log" -Append + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + - name: Create and install the clean consumer + run: | + node .github/consumer-builds/prepare.mjs '${{ matrix.profile }}' '${{ matrix.platform }}' \ + "$RUNNER_TEMP/consumer-package/react-native-executorch.tgz" "$CONSUMER_DIR" \ + 2>&1 | tee "$LOG_DIR/install.log" + - name: Build Android release with R8 + if: matrix.platform == 'android' && runner.os != 'Windows' + working-directory: ${{ env.CONSUMER_DIR }}/android + run: | + ./gradlew :app:assembleRelease --no-daemon --stacktrace --max-workers=2 \ + 2>&1 | tee "$LOG_DIR/android.log" + apk=app/build/outputs/apk/release/app-release.apk + unzip -l "$apk" | tee "$LOG_DIR/apk-files.log" + for library in RnExecutorch executorch xnnpack_executorch_backend vulkan_executorch_backend; do + grep -F "lib/${CONSUMER_ABI}/lib${library}.so" "$LOG_DIR/apk-files.log" + done + cp "$apk" "$LOG_DIR/ConsumerBuild.apk" + - name: Build Android App Bundle + if: matrix.aab + working-directory: ${{ env.CONSUMER_DIR }}/android + run: | + ./gradlew :app:bundleRelease --no-daemon --stacktrace --max-workers=2 \ + 2>&1 | tee "$LOG_DIR/android-bundle.log" + cp app/build/outputs/bundle/release/app-release.aab "$LOG_DIR/ConsumerBuild.aab" + - name: Validate Android App Bundle and packaged native libraries + if: matrix.aab + run: | + node .github/consumer-builds/validate-aab.mjs "$LOG_DIR/ConsumerBuild.aab" \ + "$RUNNER_TEMP/bundletool" "$LOG_DIR" 2>&1 | tee "$LOG_DIR/aab-validation.log" + - name: Build Android release on Windows with R8 + if: runner.os == 'Windows' + shell: pwsh + working-directory: ${{ env.CONSUMER_DIR }}/android + run: | + & .\gradlew.bat :app:assembleRelease --no-daemon --stacktrace --max-workers=2 2>&1 | Tee-Object -FilePath "$env:LOG_DIR/android.log" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $apk = Join-Path $PWD 'app/build/outputs/apk/release/app-release.apk' + Add-Type -AssemblyName System.IO.Compression.ZipFile + $zip = [System.IO.Compression.ZipFile]::OpenRead($apk) + try { + $entries = @($zip.Entries | ForEach-Object { $_.FullName }) + $entries | Out-File "$env:LOG_DIR/apk-files.log" -Encoding utf8 + foreach ($library in @('RnExecutorch', 'executorch', 'xnnpack_executorch_backend', 'vulkan_executorch_backend')) { + if ($entries -notcontains "lib/arm64-v8a/lib$library.so") { throw "APK is missing $library" } + } + } finally { $zip.Dispose() } + Copy-Item $apk "$env:LOG_DIR/ConsumerBuild.apk" + - name: Install iOS pods + if: matrix.platform == 'ios' + working-directory: ${{ env.CONSUMER_DIR }}/ios + run: pod install 2>&1 | tee "$LOG_DIR/pods.log" + - name: Archive iOS release without signing + if: matrix.platform == 'ios' && !matrix.smoke + working-directory: ${{ env.CONSUMER_DIR }} + run: | + xcodebuild -workspace ios/ConsumerBuild.xcworkspace -scheme ConsumerBuild \ + -configuration Release -destination 'generic/platform=iOS' \ + -archivePath "$RUNNER_TEMP/ConsumerBuild.xcarchive" \ + -derivedDataPath "$RUNNER_TEMP/consumer-derived-data" \ + -resultBundlePath "$LOG_DIR/ios.xcresult" \ + CODE_SIGNING_ALLOWED=NO archive 2>&1 | tee "$LOG_DIR/ios.log" + app="$RUNNER_TEMP/ConsumerBuild.xcarchive/Products/Applications/ConsumerBuild.app" + test -f "$app/ConsumerBuild" + test -f "$app/main.jsbundle" + # Enforce the manifest's archive presence once #1627 lands, without + # duplicating that PR or hiding its current absence from the baseline. + if [[ -f node_modules/react-native-executorch/ios/PrivacyInfo.xcprivacy ]]; then + test -f "$app/RnExecutorchPrivacyInfo.bundle/PrivacyInfo.xcprivacy" + plutil -lint "$app/RnExecutorchPrivacyInfo.bundle/PrivacyInfo.xcprivacy" + fi + - name: Build iOS simulator smoke app + if: matrix.platform == 'ios' && matrix.smoke + working-directory: ${{ env.CONSUMER_DIR }} + run: | + xcodebuild -workspace ios/ConsumerBuild.xcworkspace -scheme ConsumerBuild \ + -configuration Release -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' \ + -derivedDataPath "$RUNNER_TEMP/consumer-derived-data" \ + CODE_SIGNING_ALLOWED=NO build 2>&1 | tee "$LOG_DIR/ios.log" + - name: Run iOS native smoke assertions + if: matrix.platform == 'ios' && matrix.smoke + run: | + node .github/consumer-builds/smoke-runner.mjs ios \ + "$RUNNER_TEMP/consumer-derived-data/Build/Products/Release-iphonesimulator/ConsumerBuild.app" \ + "$CONSUMER_DIR" "$LOG_DIR" + - name: Enable Android emulator acceleration + if: matrix.platform == 'android' && matrix.smoke + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + - name: Run Android native smoke assertions + if: matrix.platform == 'android' && matrix.smoke + uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d + with: + api-level: 34 + arch: x86_64 + target: google_apis + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: true + script: node .github/consumer-builds/smoke-runner.mjs android "${{ env.CONSUMER_DIR }}/android/app/build/outputs/apk/release/app-release.apk" "${{ env.CONSUMER_DIR }}" "${{ env.LOG_DIR }}" + - name: Collect consumer configuration + if: always() + run: | + mkdir -p "$LOG_DIR" + for file in smoke-config.json consumer-profile.json app.json metro.config.js package.json package-lock.json android/gradle.properties android/build.gradle android/app/build.gradle android/app/src/main/AndroidManifest.xml ios/Podfile ios/Podfile.lock ios/Podfile.properties.json ios/ConsumerBuild/Info.plist; do + if [[ -f "$CONSUMER_DIR/$file" ]]; then + destination="$LOG_DIR/config/$file" + mkdir -p "$(dirname "$destination")" + cp "$CONSUMER_DIR/$file" "$destination" + fi + done + if [[ -f "$CONSUMER_DIR/node_modules/react-native-executorch/rne-build-config.json" ]]; then + cp "$CONSUMER_DIR/node_modules/react-native-executorch/rne-build-config.json" "$LOG_DIR/" + fi + - uses: actions/upload-artifact@v4 + if: always() + with: + name: consumer-build-${{ matrix.id }} + path: ${{ env.LOG_DIR }} + if-no-files-found: warn + retention-days: 7 diff --git a/apps/consumer-fixtures/App.integration.jsx b/apps/consumer-fixtures/App.integration.jsx new file mode 100644 index 0000000000..eea6b58da1 --- /dev/null +++ b/apps/consumer-fixtures/App.integration.jsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { SafeAreaView, Text } from 'react-native'; +import * as Sentry from '@sentry/react-native'; +import { getApp } from '@react-native-firebase/app'; +import { Camera } from 'react-native-vision-camera'; +import { AudioContext } from 'react-native-audio-api'; +import { tensor } from 'react-native-executorch'; + +// Referencing each import keeps its JS in the Release bundle. Native modules +// must also autolink and link successfully. This app is build-only. +export default function App() { + return ( + + + {[tensor, Sentry.init, getApp, Camera, AudioContext] + .map((value) => typeof value) + .join(', ')} + + + ); +} diff --git a/apps/consumer-fixtures/App.jsx b/apps/consumer-fixtures/App.jsx new file mode 100644 index 0000000000..0a789aba34 --- /dev/null +++ b/apps/consumer-fixtures/App.jsx @@ -0,0 +1,20 @@ +import React from 'react'; +import { SafeAreaView, Text } from 'react-native'; +import { tensor } from 'react-native-executorch'; + +// Release bundling must resolve the published JS entry point and transform +// worklets. This fixture is build coverage; CI does not launch it or run a model. +function buildMarker() { + 'worklet'; + return 'Consumer build'; +} + +export default function App() { + return ( + + + {buildMarker()}: {typeof tensor} + + + ); +} diff --git a/apps/consumer-fixtures/App.smoke.jsx b/apps/consumer-fixtures/App.smoke.jsx new file mode 100644 index 0000000000..f6109a6c85 --- /dev/null +++ b/apps/consumer-fixtures/App.smoke.jsx @@ -0,0 +1,102 @@ +import React, { useEffect, useState } from 'react'; +import { SafeAreaView, Text } from 'react-native'; +import { Asset } from 'expo-asset'; +import { loadModel, math, setTelemetryEnabled, tensor, wrapAsync } from 'react-native-executorch'; +import config from './smoke-config.json'; + +function check(condition, message) { + 'worklet'; + if (!condition) throw new Error(message); +} + +async function runSmoke() { + setTelemetryEnabled(false); + const checks = []; + const input = tensor('float32', [3], new Float32Array([1, 2, 3])); + const output = tensor('float32', [3]); + try { + math.softmax(input, output); + const result = output.getData(new Float32Array(3)); + const expected = [0.09003057, 0.24472847, 0.66524096]; + check( + result.every((value, i) => Math.abs(value - expected[i]) < 1e-5), + 'Native softmax returned incorrect values' + ); + checks.push('tensor'); + } finally { + output.dispose(); + input.dispose(); + } + + const backing = new Float32Array([99, 1, 2, 3, 99]); + const view = new Float32Array(backing.buffer, 4, 3); + const values = await wrapAsync((data) => { + 'worklet'; + check( + data.length === 3 && data[0] === 1 && data[2] === 3, + 'Worklet serialization changed the typed-array view' + ); + const t = tensor('float32', [3], data); + try { + return Array.from(t.getData(new Float32Array(3))); + } finally { + t.dispose(); + } + })(view); + check(values.join(',') === '1,2,3', 'Worklet native tensor round trip failed'); + checks.push('worklet'); + + const asset = Asset.fromModule(require('./smoke-model.pte')); + await asset.downloadAsync(); + check(asset.localUri?.startsWith('file://'), 'Bundled model did not resolve to a local file'); + const modelPath = decodeURIComponent(asset.localUri.slice('file://'.length)); + const inference = await wrapAsync((path) => { + 'worklet'; + let model, src, dst; + try { + model = loadModel(path); + check( + model.backends.forward.includes('XnnpackBackend'), + 'Fixture did not load the XNNPACK backend' + ); + src = tensor('float32', [1, 3, 256, 256], new Float32Array(3 * 256 * 256)); + // A no-op inference must not pass because of a zero-initialized buffer. + dst = tensor('float32', [1, 1, 256, 256], new Float32Array(256 * 256).fill(NaN)); + model.execute('forward', [src], [dst]); + const result = dst.getData(new Float32Array(256 * 256)); + check( + result.every((v) => Number.isFinite(v) && v >= 0 && v <= 1), + 'Inference did not write finite probabilities to every output' + ); + return { elements: result.length, backend: model.backends.forward }; + } finally { + dst?.dispose(); + src?.dispose(); + model?.dispose(); + } + })(modelPath); + checks.push('model'); + return { status: 'pass', checks, inference }; +} + +export default function App() { + const [status, setStatus] = useState('Running native smoke tests'); + useEffect(() => { + runSmoke() + .catch((error) => ({ status: 'fail', error: String(error?.stack ?? error) })) + .then(async (result) => { + setStatus(JSON.stringify(result)); + await fetch(`http://127.0.0.1:${config.port}/result/${config.token}`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(result), + }); + }) + .catch((error) => setStatus(`Reporting failed: ${String(error)}`)); + }, []); + return ( + + {status} + + ); +}