Skip to content

Commit

Permalink
feat: add rn-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Nov 15, 2024
1 parent e83d047 commit c493eac
Show file tree
Hide file tree
Showing 28 changed files with 693,605 additions and 5 deletions.
40 changes: 38 additions & 2 deletions ios/LibrariesBenchmark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
00E356EB1AD99517003FC87E /* Frameworks */,
00E356EC1AD99517003FC87E /* Resources */,
F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */,
767AA0D12DDE1C16BD60BDB7 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -184,6 +185,7 @@
13B07F8E1A680F5B00A75B9A /* Resources */,
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
E235C05ADACE081382539298 /* [CP] Copy Pods Resources */,
03AE2B6A5D89A4CEAFA87C2B /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -267,6 +269,40 @@
shellPath = /bin/sh;
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
};
03AE2B6A5D89A4CEAFA87C2B /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-LibrariesBenchmark/Pods-LibrariesBenchmark-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-LibrariesBenchmark/Pods-LibrariesBenchmark-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-LibrariesBenchmark/Pods-LibrariesBenchmark-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
767AA0D12DDE1C16BD60BDB7 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-LibrariesBenchmark-LibrariesBenchmarkTests/Pods-LibrariesBenchmark-LibrariesBenchmarkTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-LibrariesBenchmark-LibrariesBenchmarkTests/Pods-LibrariesBenchmark-LibrariesBenchmarkTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-LibrariesBenchmark-LibrariesBenchmarkTests/Pods-LibrariesBenchmark-LibrariesBenchmarkTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -570,7 +606,7 @@
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
USE_HERMES = false;
USE_HERMES = true;
};
name = Debug;
};
Expand Down Expand Up @@ -652,7 +688,7 @@
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = false;
USE_HERMES = true;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
2 changes: 2 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ target 'LibrariesBenchmark' do
:app_path => "#{Pod::Config.instance.installation_root}/.."
)

pod 'ReactNativeWebAssemblyHost', :path => "../wasm/_generated/@host"

pod 'Resources', :path => './Resources'

target 'LibrariesBenchmarkTests' do
Expand Down
77 changes: 76 additions & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,27 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-wgpu (0.1.20):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- React-nativeconfig (0.76.1)
- React-NativeModulesApple (0.76.1):
- glog
Expand Down Expand Up @@ -1572,6 +1593,48 @@ PODS:
- React-logger (= 0.76.1)
- React-perflogger (= 0.76.1)
- React-utils (= 0.76.1)
- ReactNativeWebAssembly (0.1.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- ReactNativeWebAssemblyHost (0.0.1):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- Resources (0.0.1-dev)
- SocketRocket (0.7.1)
- Yoga (0.0.0)
Expand Down Expand Up @@ -1617,6 +1680,7 @@ DEPENDENCIES:
- "react-native-basis-universal (from `../node_modules/@callstack/react-native-basis-universal`)"
- react-native-blob-util (from `../node_modules/react-native-blob-util`)
- "react-native-draco (from `../node_modules/@callstack/react-native-draco`)"
- react-native-wgpu (from `../node_modules/react-native-wgpu`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
Expand Down Expand Up @@ -1644,6 +1708,8 @@ DEPENDENCIES:
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCodegen (from `build/generated/ios`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- ReactNativeWebAssembly (from `../node_modules/react-native-wasm`)
- "ReactNativeWebAssemblyHost (from `../wasm/_generated/@host`)"
- Resources (from `./Resources`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -1729,6 +1795,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-blob-util"
react-native-draco:
:path: "../node_modules/@callstack/react-native-draco"
react-native-wgpu:
:path: "../node_modules/react-native-wgpu"
React-nativeconfig:
:path: "../node_modules/react-native/ReactCommon"
React-NativeModulesApple:
Expand Down Expand Up @@ -1783,6 +1851,10 @@ EXTERNAL SOURCES:
:path: build/generated/ios
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
ReactNativeWebAssembly:
:path: "../node_modules/react-native-wasm"
ReactNativeWebAssemblyHost:
:path: "../wasm/_generated/@host"
Resources:
:path: "./Resources"
Yoga:
Expand Down Expand Up @@ -1827,6 +1899,7 @@ SPEC CHECKSUMS:
react-native-basis-universal: 1abeaf6e06aee516ab17cfa6a1b80e83a5e43461
react-native-blob-util: e6a3b23a99ac2c3d9fa48722db049a1e1808efc2
react-native-draco: 1c96e89e0f6dc4b4bef27adf5d9a7dc2abf68c0a
react-native-wgpu: 6a6a47ec5431c097af9c50185c6cf104d54ca72c
React-nativeconfig: 93fe8c85a8c40820c57814e30f3e44b94c995a7b
React-NativeModulesApple: b3e076fd0d7b73417fe1e8c8b26e3c57ae9b74aa
React-perflogger: 1c55bcd3c392137cbaf0d21d8bb87ce9a0cebb15
Expand Down Expand Up @@ -1854,10 +1927,12 @@ SPEC CHECKSUMS:
React-utils: 5362bd16a9563f9916e7a56c011ddc533507650f
ReactCodegen: 865bafc5c17ec2181620ced1a32c39c38ab2951d
ReactCommon: 422e364463f33e336fc4db196aeb50fd801d90d6
ReactNativeWebAssembly: ca1d70efa7f7e07f8dcb38e53758bdf0becb062d
ReactNativeWebAssemblyHost: d50cc3dff3fe27709589ecad9c8fcefd46f1b805
Resources: 2994776ece0cdf59fee39153b044695f516f6988
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: db69236006b8b1c6d55ab453390c882306cbf219

PODFILE CHECKSUM: f19e135a3290ed3a94b2ab3ed51b831743e48ac1
PODFILE CHECKSUM: f8152c6fc2377e9046492f6e81125bca41a1aa36

COCOAPODS: 1.15.2
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
"name": "LibrariesBenchmark",
"version": "0.0.1",
"private": true,
"description": "IR Engine Benchmark",
"repository": {
"type": "git",
"url": "git+https://github.com/callstack/react-native-wasm.git"
},
"homepage": "https://github.com/callstack/react-native-wasm#readme",
"author": "Callstack (https://github.com/callstack)",
"license": "MIT",
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
Expand All @@ -17,11 +25,14 @@
"dependencies": {
"@callstack/react-native-basis-universal": "0.2.1",
"@callstack/react-native-draco": "0.2.0",
"@dimforge/rapier3d-compat": "0.11.2",
"base-64": "^1.0.0",
"react": "18.3.1",
"react-native": "0.76.1",
"react-native-blob-util": "^0.19.11",
"react-native-wgpu": "^0.1.19"
"react-native-wasm": "file:.yalc/react-native-wasm",
"react-native-wgpu": "^0.1.19",
"text-encoding-polyfill": "^0.6.7"
},
"devDependencies": {
"@babel/core": "^7.25.2",
Expand Down
6 changes: 6 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { BenchmarkHarness, BenchmarkDescriptor } from './react-native-benchmarking-library';
import { advancedDracoBenchmark, simpleDracoBenchmark } from './benchmarks/draco';
import { basisTranscoding, encoding } from './benchmarks/basis';
import { rapierWorldSimulation } from './benchmarks/rapier';


function App(): React.JSX.Element {
Expand Down Expand Up @@ -36,6 +37,11 @@ function App(): React.JSX.Element {
benchmarkType: 'headless',
benchmarkFn: basisTranscoding(iterations),
},
{
title: 'Rapier: Basic Simulation',
benchmarkType: 'headless',
benchmarkFn: rapierWorldSimulation(iterations),
},
]);
}, [numIterations]);

Expand Down
56 changes: 56 additions & 0 deletions src/benchmarks/rapier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import WebAssembly from 'react-native-wasm';
global.WebAssembly = WebAssembly;
import 'text-encoding-polyfill'; // Required for `rapier3d-compat`
import RAPIER, {
World,
ColliderDesc,
RigidBodyDesc,
} from '@dimforge/rapier3d-compat';


export const rapierWorldSimulation =
(iterations: number) => async (): Promise<void> => {
try {
await RAPIER.init();
const gravity = { x: 0.0, y: -9.81, z: 0.0 };
const world = new World(gravity);

// Create a ground plane
const groundColliderDesc = ColliderDesc.cuboid(10.0, 0.1, 10.0);
world.createCollider(groundColliderDesc);

// Create a dynamic rigid-body with a cube collider
const rigidBodyDesc = RigidBodyDesc.dynamic().setTranslation(
0.0,
5.0,
0.0
);
const rigidBody = world.createRigidBody(rigidBodyDesc);

const colliderDesc = ColliderDesc.cuboid(0.5, 0.5, 0.5);
world.createCollider(colliderDesc, rigidBody);

// Simulation loop
const timeStep = 1 / 60;
function simulate() {
world.step();

// Get the position of the cube
const position = rigidBody.translation();
console.log(
`Cube position: x=${position.x.toFixed(2)}, y=${position.y.toFixed(2)}, z=${position.z.toFixed(2)}`
);

// Continue simulation if cube is above ground
if (position.y > 0.5) {
setTimeout(() => simulate(), timeStep * 1000);
}
}

// Start the simulation
simulate();
} catch (error) {
console.error(error);
}
};

5 changes: 4 additions & 1 deletion src/utils/readFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import RNFetchBlob from 'react-native-blob-util';
import {decode as atob} from 'base-64';


export const readFile = async (path: string): Promise<Uint8Array> => {
export const readFile = async (path: string, base64: boolean = false): Promise<Uint8Array> => {
const filePath = RNFetchBlob.fs.asset(path);
const data = await RNFetchBlob.fs.readFile(filePath, 'base64');
if (base64) {
return data;
}
const byteCharacters = atob(data);
const byteNumbers = new Array(byteCharacters.length);
for (let i = 0; i < byteCharacters.length; i++) {
Expand Down
Loading

0 comments on commit c493eac

Please sign in to comment.