Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/react-native-fantom/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
updateSnapshotsAndGetJestSnapshotResult,
} from './snapshotUtils';
import {
getBuckModeForPlatform,
getBuckModesForPlatform,
getDebugInfoFromCommandResult,
getShortHash,
runBuck2,
Expand Down Expand Up @@ -76,7 +76,7 @@ function generateBytecodeBundle({
const hermesCompilerCommandResult = runBuck2(
[
'run',
getBuckModeForPlatform(isOptimizedMode),
...getBuckModesForPlatform(isOptimizedMode),
'//xplat/hermes/tools/hermesc:hermesc',
'--',
'-emit-binary',
Expand Down Expand Up @@ -178,7 +178,9 @@ module.exports = async function runTest(

const rnTesterCommandResult = runBuck2([
'run',
getBuckModeForPlatform(testConfig.mode === FantomTestConfigMode.Optimized),
...getBuckModesForPlatform(
testConfig.mode === FantomTestConfigMode.Optimized,
),
'//xplat/ReactNative/react-native-cxx/samples/tester:tester',
'--',
'--bundlePath',
Expand Down
21 changes: 15 additions & 6 deletions packages/react-native-fantom/runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,30 @@ import {SourceMapConsumer} from 'source-map';

const BUCK_ISOLATION_DIR = 'react-native-fantom-buck-out';

export function getBuckModeForPlatform(enableRelease: boolean = false): string {
export function getBuckModesForPlatform(
enableRelease: boolean = false,
): $ReadOnlyArray<string> {
const mode = enableRelease ? 'opt' : 'dev';

let osPlatform;
switch (os.platform()) {
case 'linux':
return `@//arvr/mode/linux/${mode}`;
osPlatform = `@//arvr/mode/linux/${mode}`;
break;
case 'darwin':
return os.arch() === 'arm64'
? `@//arvr/mode/mac-arm/${mode}`
: `@//arvr/mode/mac/${mode}`;
osPlatform =
os.arch() === 'arm64'
? `@//arvr/mode/mac-arm/${mode}`
: `@//arvr/mode/mac/${mode}`;
break;
case 'win32':
return `@//arvr/mode/win/${mode}`;
osPlatform = `@//arvr/mode/win/${mode}`;
break;
default:
throw new Error(`Unsupported platform: ${os.platform()}`);
}

return ['@//xplat/mode/react-force-cxx-platform', osPlatform];
}

type SpawnResultWithOriginalCommand = {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native-fantom/runner/warmup/warmup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import {
getBuckModeForPlatform,
getBuckModesForPlatform,
getDebugInfoFromCommandResult,
runBuck2,
} from '../utils';
Expand Down Expand Up @@ -96,7 +96,7 @@ async function warmUpMetro(isOptimizedMode: boolean): Promise<void> {
function warmUpHermesCompiler(isOptimizedMode: boolean): void {
const buildHermesCompilerCommandResult = runBuck2([
'build',
getBuckModeForPlatform(isOptimizedMode),
...getBuckModesForPlatform(isOptimizedMode),
'//xplat/hermes/tools/hermesc:hermesc',
]);

Expand All @@ -110,7 +110,7 @@ function warmUpHermesCompiler(isOptimizedMode: boolean): void {
function warmUpRNTesterCLI(isOptimizedMode: boolean): void {
const buildRNTesterCommandResult = runBuck2([
'build',
getBuckModeForPlatform(isOptimizedMode),
...getBuckModesForPlatform(isOptimizedMode),
'//xplat/ReactNative/react-native-cxx/samples/tester:tester',
]);

Expand Down
17 changes: 5 additions & 12 deletions packages/react-native-fantom/src/getFantomRenderedOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @oncall react_native
*/

import FantomModule from './specs/NativeFantomModule';
// $FlowExpectedError[untyped-import]
import micromatch from 'micromatch';
import * as React from 'react';
Expand All @@ -19,12 +20,6 @@ export type RenderOutputConfig = {
includeLayoutMetrics?: boolean,
};

// match RenderFormatOptions.h
type NativeRenderFormatOptions = {
includeRoot: boolean,
includeLayoutMetrics: boolean,
};

type FantomJsonObject = {
type: string,
props: {[key: string]: string},
Expand Down Expand Up @@ -117,14 +112,12 @@ export default function getFantomRenderedOutput(
includeLayoutMetrics = false,
...fantomConfig
} = config;
const nativeConfig: NativeRenderFormatOptions = {
includeRoot,
includeLayoutMetrics,
};

return new FantomRenderedOutput(
JSON.parse(
global.$$JSTesterModuleName$$.getRenderedOutput(surfaceId, nativeConfig),
FantomModule.getRenderedOutput(surfaceId, {
includeRoot,
includeLayoutMetrics,
}),
),
fantomConfig,
);
Expand Down
13 changes: 6 additions & 7 deletions packages/react-native-fantom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
import type {MixedElement} from 'react';

import getFantomRenderedOutput from './getFantomRenderedOutput';
import FantomModule from './specs/NativeFantomModule';
import ReactFabric from 'react-native/Libraries/Renderer/shims/ReactFabric';

let globalSurfaceIdCounter = 1;
Expand All @@ -34,23 +35,21 @@ class Root {

render(element: MixedElement) {
if (!this.#hasRendered) {
global.$$JSTesterModuleName$$.startSurface(this.#surfaceId);
FantomModule.startSurface(this.#surfaceId);
this.#hasRendered = true;
}

ReactFabric.render(element, this.#surfaceId, () => {}, true);
}

getMountingLogs(): Array<string> {
return global.$$JSTesterModuleName$$.getMountingManagerLogs(
this.#surfaceId,
);
return FantomModule.getMountingManagerLogs(this.#surfaceId);
}

destroy() {
// TODO: check for leaks.
global.$$JSTesterModuleName$$.stopSurface(this.#surfaceId);
global.$$JSTesterModuleName$$.flushMessageQueue();
FantomModule.stopSurface(this.#surfaceId);
FantomModule.flushMessageQueue();
}

getRenderedOutput(config: RenderOutputConfig = {}): FantomRenderedOutput {
Expand Down Expand Up @@ -81,7 +80,7 @@ export function runTask(task: () => void | Promise<void>) {

try {
flushingQueue = true;
global.$$JSTesterModuleName$$.flushMessageQueue();
FantomModule.flushMessageQueue();
} finally {
flushingQueue = false;
}
Expand Down
29 changes: 29 additions & 0 deletions packages/react-native-fantom/src/specs/NativeFantomModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/

import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';

import {TurboModuleRegistry} from 'react-native';

// match RenderFormatOptions.h
export type RenderFormatOptions = {
includeRoot: boolean,
includeLayoutMetrics: boolean,
};

interface Spec extends TurboModule {
startSurface: (surfaceId: number) => void;
stopSurface: (surfaceId: number) => void;
getMountingManagerLogs: (surfaceId: number) => Array<string>;
flushMessageQueue: () => void;
getRenderedOutput: (surfaceId: number, config: RenderFormatOptions) => string;
}

export default TurboModuleRegistry.getEnforcing<Spec>('Fantom') as Spec;
Loading