Skip to content

New NPM #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 362 commits into
base: master
Choose a base branch
from
Open

New NPM #665

wants to merge 362 commits into from

Conversation

CedricGuillemet
Copy link
Contributor

@CedricGuillemet CedricGuillemet commented Jun 6, 2025

WIP

Goal

Deliver 1 single self contained package with sources (no fetch, no secondary download) for all platform, for all RN versions.
Deprecated existing (Playground, tests, build script) in favor of a single RNTA Playground and simpler tooling.

Building the new NPM

  • Gather all sources (BabylonNative and dependencies) needed by Android/iOS/Windows builds
  • Remove unncessary dependencies (bgfx examples) and generate glue CMake files
  • Bundle previous iosAndroid and Windows Packages into a single NPM along gathered sources

Testing

  • Build RNTA for iOS, Android and Windows
  • Publish an artifact so it can be tested locally

PR Changes

  • Removed old system
  • Renamed BRNPlayground -> Playground
  • Moved react-native-iosandroid and react-native-windows content into Modules/@babylonjs/react-native folder
  • Added buildBabylonNativeSourceTree gulp export to gather BN sources
  • Update Android Gradle to use fetched content and build BabylonNative instead of using static libraries

TODO

  • Android Build
  • Windows Build
  • iOS Build
  • NPM Test publish job
  • Build .ts
  • Publish testable artifacts
  • Remove bgfx example/3rdparty folders
  • Permissions
  • Env var to disable XR and/or Camera plugins (BABYLON_NATIVE_PLUGIN_NATIVECAMERA=0, BABYLON_NATIVE_PLUGIN_NATIVEXR=0)
  • Webp
    - [ ] Script to change RN version for RNTA Left to users to get a working node environment
  • Documentation/Readme
  • Missing CI scripts (publish)
  • Test Playground Android
  • Test Playground iOS
  • Test Playground Windows
  • Test Package Android
  • Test Package iOS
  • Test Package Windows
  • Link error with react-native :
ld.lld: error: undefined symbol: facebook::react::CallInvokerHolder::getCallInvoker()
  >>> referenced by BabylonNativeInterop.cpp:39 (/Users/cedricguillemet/dev/BRNAnd/Apps/Playground/node_modules/@babylonjs/react-native/android/src/main/cpp/BabylonNativeInterop.cpp:39)
  >>>               CMakeFiles/BabylonNative.dir/src/main/cpp/BabylonNativeInterop.cpp.o:(Java_com_babylonreactnative_BabylonNativeInterop_00024BabylonNative_initialize)

issue with RN 0.78. fixed with RN 0.80. not tested with previous versions. To fix (if it happens) on user side.

Notes:

  • Android debug build asserts in spirv shader compilation. It works fine in release.
  • Android XR not tested because of missing ARCore dependency. I guess it should be part of the app and not the package. To confirm!
  • ios XR working correctly

Pros/Cons of sources in package

Pros

  • smaller disk footprint. no need to clear up space : https://github.com/BabylonJS/BabylonReactNative/tree/master/.github/workflows/macos_freespace
  • 1 single NPM package for all platforms and RN versions instead of 21
  • smaller NPMs (Windows is 700Mb per RN version)
  • put breakpoints anywhere
  • simpler builds (Android is handled by CMake, no need for Windows build scripts)
  • support for ABI breaking changes
  • unity build not needed anymore (windows binary size issue not relevant)
  • gulp script is reduced in scope
  • more precise control on components used (no more BASE_KIT package)
  • same podspec for dev and NPM
  • faster PR build/publish: ~15min Vs 1h
  • asserts firing!

Cons

  • need to build BN source with same toolchain flags as BRN (but same for prebuilt static libraries)
  • slower build for users (?). need testing for that
  • Xcode builds need CMake

Sizes

Binary packages

TS : 23Kb
Windows: 102Mb (700Mb Unzipped)
iOS-Android: 21Mb (65Mb Unzipped)

Source package

13Mb (74Mb Unzipped)

@CedricGuillemet
Copy link
Contributor Author

@ryantrem Now using cmake-runtime. Its use will appear in the log : Using CMake version 3.31.0 from /Users/runner/work/BabylonReactNative/BabylonReactNative/Modules/@babylonjs/react-native/node_modules/cmake-runtime/bin/cmake

"dependencies": {
"base-64": "^0.1.0",
"semver": "^7.3.2",
"cmake-runtime": "3.31.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in devDependencies, right?

@ryantrem ryantrem self-requested a review July 16, 2025 18:59
Comment on lines +14 to +21
extraNodeModules: {
'@babylonjs/core': path.resolve(__dirname, './node_modules/@babylonjs/core'),
'@babylonjs/loaders': path.resolve(__dirname, './node_modules/@babylonjs/loaders'),
'@babylonjs/react-native': path.resolve(__dirname, './node_modules/@babylonjs/tract-native'),
'base-64': path.resolve(__dirname, './node_modules/base-64'),
'semver': path.resolve(__dirname, './node_modules/semver'),
'react-native-permissions': path.resolve(__dirname, './node_modules/react-native-permissions')
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's all this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need all the sym linking stuff anymore because metro now supports that natively?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing the app I had unresolved imports that were solved by these symlinks. Not sure why it happens or if it's the best solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a windows specific package.json? Not sure how this works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, Windows specific package.json. I could not find a configuration that worked for iOS/Android and Windows. I tried this script (with a few modifications) https://github.com/microsoft/react-native-test-app/blob/trunk/scripts/internal/set-react-version.mts but I could not find a good configuration either. At the end, a simple file copy solved the issue for the test app.

@@ -50,9 +52,11 @@ namespace BabylonNative
Babylon::JsRuntime::CreateForJavaScript(m_env, Babylon::CreateJsRuntimeDispatcher(m_env, jsiRuntime, m_jsDispatcher, m_isRunning));

// Initialize Babylon Native plugins
#ifndef BASEKIT_BUILD
#if BABYLON_NATIVE_PLUGIN_NATIVEXR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If people want these features, does it mean they have to add these defines to their project and then re-run the cmake command that is normally run at npm install time? Should these be opt-out instead of opt-in, such that by default BRN includes all BN features?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugins are opt-out using env var. For Windows/Android, no need to re-run npm install. Setting the env var and running msbuild/gradlew is enough. for iOS, pod install needs to be run again.

"dependencies": {
"@babylonjs/core": "8.14.1",
"@babylonjs/loaders": "8.14.1",
"@babylonjs/react-native": "file:../../Modules/@babylonjs/react-native",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the PackageTest directory and app are gone, can we test published packages (or locally built packages) by just installing that package into this project (temporarily overwriting the local source pakcage)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can add a step after package build to test produced packed .tgz

CedricGuillemet added a commit to BabylonJS/BabylonNative that referenced this pull request Jul 17, 2025
related to BabylonJS/BabylonReactNative#665

Some dependencies are fetched only for the platform being built.
`BABYLON_NATIVE_BUILD_SOURCETREE` variable has been added to allow
fetching independently of active platform.

---------

Co-authored-by: Drew Fillebrown <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants