Skip to content

Create a pure C++ Turbo Module without wrappers #630

Closed
@ospfranco

Description

@ospfranco

Description

I want to create a pure C++ module without ObjC/Kotlin wrappers. This library has a really simple way to load the Turbo Module.

However on the latest version it seems builder-bob has started to customize and patch the Turbo Module generation which is causing me a lot of troubles. I've tried replicating the setup of BcryptCpp but I get different errors.

First I had to remove the codegen step from pre-actions on the scheme. Related to #628. It seems the script messes with codegen as well. Then when I remove the outputDir from the codegenConfig in package.json I start getting duplicated symbols error as well as failing pod install:

~/Developer/react-native-opacity/example (main*) » yarn pods                   osp@ospm3
Found 1 module for target `OpacityExample`
link_native_modules! {:ios_packages=>[{:configurations=>[], :name=>"react-native-opacity", :path=>"../..", :podspec_path=>"/Users/osp/Developer/react-native-opacity/react-native-opacity.podspec", :script_phases=>[]}], :ios_project_root_path=>"/Users/osp/Developer/react-native-opacity/example/ios", :react_native_path=>"../node_modules/react-native"}
Auto-linking React Native module for target `OpacityExample`: react-native-opacity
Framework build type is static library
[Codegen] Adding script_phases to ReactCodegen.
[Codegen] Generating ./build/generated/ios/ReactCodegen.podspec.json
[Codegen] Analyzing /Users/osp/Developer/react-native-opacity/example/package.json
[Codegen] Searching for codegen-enabled libraries in the app.
[Codegen] The "codegenConfig" field is not defined in package.json. Assuming there is nothing to generate at the app level.
[Codegen] Searching for codegen-enabled libraries in the project dependencies.
[Codegen] Found react-native


[Codegen] >>>>> Searching for codegen-enabled libraries in react-native.config.js
[Codegen] Found react-native-opacity
[Codegen] Processing FBReactNativeSpec
[Codegen] Searching for podspec in the project dependencies.
[Codegen] Processing rncore
[Codegen] Searching for podspec in the project dependencies.
[Codegen] Processing RNOpacitySpec
[Codegen] Searching for podspec in the project dependencies.
[Codegen] Supported Apple platforms: ios for RNOpacitySpec
[Codegen] Generating Native Code for FBReactNativeSpec - ios
[Codegen] Generated artifacts: /Users/osp/Developer/react-native-opacity/example/ios/build/generated/ios
[Codegen - rncore] Skipping iOS code generation for rncore as it has been generated already.
[Codegen] Generating Native Code for RNOpacitySpec - ios
[Codegen] Generated artifacts: /Users/osp/Developer/react-native-opacity/example/ios/build/generated/ios
[Codegen] Creating component provider.
[Codegen] Generated provider in: /Users/osp/Developer/react-native-opacity/example/node_modules/react-native/React/Fabric
[Codegen] Done.
Analyzing dependencies
Downloading dependencies
ℹ Building target codegen
✔ Generated native code with codegen
/Users/osp/Developer/react-native-opacity/node_modules/react-native-builder-bob/lib/utils/patchCodegen.js:23
  let codegenAndroidPath = packageJson.codegenConfig.outputDir.android;
                                                               ^

TypeError: Cannot read properties of undefined (reading 'android')
    at patchCodegen (/Users/osp/Developer/react-native-opacity/node_modules/react-native-builder-bob/lib/utils/patchCodegen.js:23:64)
    at build (/Users/osp/Developer/react-native-opacity/node_modules/react-native-builder-bob/lib/targets/codegen.js:34:36)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async buildTarget (/Users/osp/Developer/react-native-opacity/node_modules/react-native-builder-bob/lib/index.js:421:7)

Node.js v18.20.2
Generating Pods project
Setting USE_HERMES build settings
Setting REACT_NATIVE_PATH build settings
Setting SWIFT_ACTIVE_COMPILATION_CONDITIONS build settings
[Ccache]: Removing Ccache from CC, LD, CXX & LDPLUSPLUS build settings
[SPM] Cleaning old SPM dependencies from Pods project
[SPM] Adding SPM dependencies to Pods project
[Privacy Manifest Aggregation] Appending aggregated reasons to existing PrivacyInfo.xcprivacy file.
[Privacy Manifest Aggregation] Reading .xcprivacy files to aggregate all used Required Reason APIs.
Setting CLANG_CXX_LANGUAGE_STANDARD to c++20 on /Users/osp/Developer/react-native-opacity/example/ios/OpacityExample.xcodeproj
Pod install took 8 [s] to run
Integrating client project
Pod installation complete! There are 65 dependencies from the Podfile and 65 total pods installed.

With the following package.json config:

  "codegenConfig": {
    "name": "RNOpacitySpec",
    "type": "modules",
    "jsSrcsDir": "src"
  },
  "create-react-native-library": {
    "type": "module-new",
    "languages": "cpp",
    "version": "0.41.1"
  }

Some times I can get it to work. After clearing the build and derived data folder. But other times I don't.

Not necessarily that I disagree with the direction builder-bob is trying to help package creation. But the scripts that modify/patch the codegen process should be robust enough

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

C++ Turbo Module with Vanilla app

Link to repro

Will create one later

Environment

info Fetching system and libraries information...
System:
  OS: macOS 15.0
  CPU: (11) arm64 Apple M3 Pro
  Memory: 1.52 GB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.2
    path: ~/.local/share/mise/installs/node/18/bin/node
  Yarn:
    version: 3.6.1
    path: ~/.local/share/mise/installs/node/18/bin/yarn
  npm:
    version: 10.5.0
    path: ~/.local/share/mise/installs/node/18/bin/npm
  Watchman:
    version: 2024.06.24.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/osp/.local/share/mise/installs/ruby/3/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
    System Images:
      - android-33 | Google Play ARM 64 v8a
    Android NDK: 26.1.10909125
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 16.0/16A242
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions