Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@ abstract class GenerateAutolinkingNewArchitecturesFileTask : DefaultTask() {

#pragma once

#include <ReactCommon/CallInvoker.h>
#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/TurboModule.h>
#include <React/CallInvoker.h>
#include <React/ComponentRegistry.h>
#include <React/NativeModuleCore.h>
#include <jsi/jsi.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>

namespace facebook {
namespace react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.android.build.api.variant.Variant
import com.facebook.react.ReactExtension
import com.facebook.react.internal.StubPchBuildService
import com.facebook.react.utils.ProjectUtils.getReactNativeArchitectures
import com.facebook.react.utils.ProjectUtils.isStrictCxxApiEnabled
import java.io.File
import org.gradle.api.Project

Expand Down Expand Up @@ -58,6 +59,9 @@ internal object NdkConfiguratorUtils {
if (cmakeArgs.none { it.startsWith("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES") }) {
cmakeArgs.add("-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON")
}
if (project.isStrictCxxApiEnabled && cmakeArgs.none { it.startsWith("-DRN_STRICT_API") }) {
cmakeArgs.add("-DRN_STRICT_API=ON")
}

val architectures = project.getReactNativeArchitectures()
// abiFilters are split ABI are not compatible each other, so we set the abiFilters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import com.facebook.react.utils.PropertyUtils.REACT_NATIVE_ARCHITECTURES
import com.facebook.react.utils.PropertyUtils.SCOPED_EDGE_TO_EDGE_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_HERMES_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_REACT_NATIVE_ARCHITECTURES
import com.facebook.react.utils.PropertyUtils.SCOPED_STRICT_CXX_API_ENABLED
import com.facebook.react.utils.PropertyUtils.SCOPED_USE_THIRD_PARTY_JSC
import com.facebook.react.utils.PropertyUtils.STRICT_CXX_API_ENABLED
import com.facebook.react.utils.PropertyUtils.USE_THIRD_PARTY_JSC
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
Expand Down Expand Up @@ -56,6 +58,13 @@ internal object ProjectUtils {
(project.hasProperty(SCOPED_EDGE_TO_EDGE_ENABLED) &&
project.property(SCOPED_EDGE_TO_EDGE_ENABLED).toString().toBoolean())

internal val Project.isStrictCxxApiEnabled: Boolean
get() =
(project.hasProperty(STRICT_CXX_API_ENABLED) &&
project.property(STRICT_CXX_API_ENABLED).toString().toBoolean()) ||
(project.hasProperty(SCOPED_STRICT_CXX_API_ENABLED) &&
project.property(SCOPED_STRICT_CXX_API_ENABLED).toString().toBoolean())

internal val Project.useThirdPartyJSC: Boolean
get() =
(project.hasProperty(USE_THIRD_PARTY_JSC) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ object PropertyUtils {
const val EDGE_TO_EDGE_ENABLED = "edgeToEdgeEnabled"
const val SCOPED_EDGE_TO_EDGE_ENABLED = "react.edgeToEdgeEnabled"

/**
* Public property that enforces the C++ stable API for the app's own native code by defining
* RN_STRICT_API
*/
const val STRICT_CXX_API_ENABLED = "strictCxxApiEnabled"
const val SCOPED_STRICT_CXX_API_ENABLED = "react.strictCxxApiEnabled"

/** Public property that excludes jsctooling from core */
const val USE_THIRD_PARTY_JSC = "useThirdPartyJSC"
const val SCOPED_USE_THIRD_PARTY_JSC = "react.useThirdPartyJSC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.facebook.react.utils.ProjectUtils.getReactNativeArchitectures
import com.facebook.react.utils.ProjectUtils.isEdgeToEdgeEnabled
import com.facebook.react.utils.ProjectUtils.isHermesEnabled
import com.facebook.react.utils.ProjectUtils.isNewArchEnabled
import com.facebook.react.utils.ProjectUtils.isStrictCxxApiEnabled
import com.facebook.react.utils.ProjectUtils.needsCodegenFromPackageJson
import java.io.File
import org.assertj.core.api.Assertions.assertThat
Expand Down Expand Up @@ -115,6 +116,39 @@ class ProjectUtilsTest {
assertThat(project.isEdgeToEdgeEnabled).isFalse()
}

@Test
fun isStrictCxxApiEnabled_returnsFalseByDefault() {
assertThat(createProject().isStrictCxxApiEnabled).isFalse()
}

@Test
fun isStrictCxxApiEnabled_withEnabledViaProperty_returnsTrue() {
val project = createProject()
project.extensions.extraProperties.set("strictCxxApiEnabled", "true")
assertThat(project.isStrictCxxApiEnabled).isTrue()
}

@Test
fun isStrictCxxApiEnabled_withEnabledViaScopedProperty_returnsTrue() {
val project = createProject()
project.extensions.extraProperties.set("react.strictCxxApiEnabled", "true")
assertThat(project.isStrictCxxApiEnabled).isTrue()
}

@Test
fun isStrictCxxApiEnabled_withDisabledViaProperty_returnsFalse() {
val project = createProject()
project.extensions.extraProperties.set("strictCxxApiEnabled", "false")
assertThat(project.isStrictCxxApiEnabled).isFalse()
}

@Test
fun isStrictCxxApiEnabled_withInvalidViaProperty_returnsFalse() {
val project = createProject()
project.extensions.extraProperties.set("strictCxxApiEnabled", "¯\\_(ツ)_/¯")
assertThat(project.isStrictCxxApiEnabled).isFalse()
}

@Test
fun needsCodegenFromPackageJson_withCodegenConfigInPackageJson_returnsTrue() {
val project = createProject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
add_library(common_flags INTERFACE)
target_compile_options(common_flags INTERFACE ${folly_FLAGS})

if(RN_STRICT_API)
target_compile_definitions(common_flags INTERFACE RN_STRICT_API)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE RN_STRICT_API)
endif()

# Defines the `reactnative_pch` target and `target_reuse_reactnative_pch()`, so
# the codegen targets below share a single precompiled header. Has to come after
# `common_flags`, as the precompiled header is built with the same flags as its
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include <DefaultComponentsRegistry.h>
#include <DefaultTurboModuleManagerDelegate.h>
#include <FBReactNativeSpec.h>
#include <React/ComponentRegistry.h>
#include <autolinking.h>
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>

#ifdef REACT_NATIVE_APP_CODEGEN_HEADER
#include REACT_NATIVE_APP_CODEGEN_HEADER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@

#pragma once

#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/TurboModule.h>
#include <React/Bridging.h>
#include <React/ComponentRegistry.h>
#include <React/NativeModuleCore.h>
#include <React/RendererCore.h>
#include <React/View.h>
#include <folly/dynamic.h>
#include <jsi/jsi.h>
#include <react/bridging/Bridging.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/components/view/ViewEventEmitter.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/StateData.h>
#include <react/renderer/core/propsConversions.h>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <react/renderer/core/EventBeat.h>
#include <React/RendererCore.h>

#include "EventBeatManager.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

#pragma once

#include <React/ComponentRegistry.h>
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <React/ComponentRegistry.h>

namespace facebook::react::CoreComponentsRegistry {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#pragma once

#include <React/RendererCore.h>
#include <fbjni/fbjni.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/core/EventEmitter.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#include <mutex>
#include <unordered_map>

#include <React/RendererCore.h>
#include <fbjni/fbjni.h>
#include <react/fabric/JFabricUIManager.h>
#include <react/renderer/core/Props.h>
#include <react/renderer/uimanager/primitives.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#pragma once

#include <React/RendererCore.h>
#include <fbjni/fbjni.h>
#include <react/common/mapbuffer/JReadableMapBuffer.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/core/State.h>
#include <react/uimanager/StateWrapper.h>

namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <ReactCommon/RuntimeExecutor.h>
#include <React/RuntimeExecutor.h>
#include <fbjni/fbjni.h>

namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#pragma once

#include <React/Debug.h>
#include <React/MapBuffer.h>
#include <fbjni/fbjni.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/mapbuffer/MapBuffer.h>

#include <fbjni/ByteBuffer.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@

#pragma once

#include <React/ComponentRegistry.h>
#include <React/RendererCore.h>
#include <fbjni/fbjni.h>
#include <react/fabric/ComponentFactory.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#include <string>
#include <vector>

#include <React/NativeModuleCore.h>
#include <ReactCommon/CxxReactPackage.h>
#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/TurboModule.h>
#include <ReactCommon/TurboModuleManagerDelegate.h>
#include <fbjni/fbjni.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#pragma once

#include <ReactCommon/CallInvoker.h>
#include <ReactCommon/TurboModule.h>
#include <React/CallInvoker.h>
#include <React/NativeModuleCore.h>
#include <fbjni/fbjni.h>

namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <ReactCommon/CallInvoker.h>
#include <React/CallInvoker.h>
#include <fbjni/fbjni.h>
#include <memory>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <ReactCommon/CallInvoker.h>
#include <React/CallInvoker.h>
#include <fbjni/fbjni.h>
#include <memory>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
#include <memory>
#include <unordered_map>

#include <React/NativeModuleCore.h>
#include <React/RuntimeExecutor.h>
#include <ReactCommon/CallInvokerHolder.h>
#include <ReactCommon/JavaTurboModule.h>
#include <ReactCommon/NativeMethodCallInvokerHolder.h>
#include <ReactCommon/RuntimeExecutor.h>
#include <ReactCommon/TurboModule.h>
#include <ReactCommon/TurboModuleManagerDelegate.h>
#include <react/jni/JRuntimeExecutor.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#pragma once

#include <ReactCommon/CallInvoker.h>
#include <ReactCommon/JavaTurboModule.h>
#include <React/CallInvoker.h>
#include <React/NativeModuleCore.h>
#include <fbjni/fbjni.h>
#include <memory>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/android/app/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include <DefaultTurboModuleManagerDelegate.h>
#include <FBReactNativeSpec.h>
#include <NativeCxxModuleExample.h>
#include <React/ComponentRegistry.h>
#include <ReactCommon/SampleTurboModuleJSIBindings.h>
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>

#ifdef REACT_NATIVE_APP_CODEGEN_HEADER
#include REACT_NATIVE_APP_CODEGEN_HEADER
Expand Down
Loading