Skip to content

Commit

Permalink
Implement new feature flag system
Browse files Browse the repository at this point in the history
Differential Revision: D52806730

fbshipit-source-id: e2fd11b6c0d4b32fd902b7a253ecbda2729f8442
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 21, 2024
1 parent 6e1f917 commit 5aca704
Show file tree
Hide file tree
Showing 68 changed files with 2,758 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ internal object NdkConfiguratorUtils {
// Due to a bug in AGP, they fire a warning on console as both the JNI
// and the prefab .so files gets considered. See more on:
"**/libfabricjni.so",
"**/libfeatureflagsjni.so",
"**/libfolly_runtime.so",
"**/libglog.so",
"**/libjsi.so",
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/React-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Pod::Spec.new do |s|
s.dependency "React-jsi"
s.dependency "React-jsiexecutor"
s.dependency "React-utils"
s.dependency "React-featureflags"
s.dependency "SocketRocket", socket_rocket_version
s.dependency "React-runtimescheduler"
s.dependency "Yoga"
Expand Down
9 changes: 9 additions & 0 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ val preparePrefab by
Pair(File(buildDir, "generated/source/codegen/jni/").absolutePath, "")),
PrefabPreprocessingEntry(
"react_debug", Pair("../ReactCommon/react/debug/", "react/debug/")),
PrefabPreprocessingEntry(
"react_featureflags",
Pair("../ReactCommon/react/featureflags/", "react/featureflags/")),
PrefabPreprocessingEntry(
"react_render_componentregistry",
Pair(
Expand Down Expand Up @@ -135,6 +138,9 @@ val preparePrefab by
"glog", Pair(File(buildDir, "third-party-ndk/glog/exported/").absolutePath, "")),
PrefabPreprocessingEntry(
"fabricjni", Pair("src/main/jni/react/fabric", "react/fabric/")),
PrefabPreprocessingEntry(
"featureflagsjni",
Pair("src/main/jni/react/featureflags", "react/featureflags/")),
PrefabPreprocessingEntry(
"react_render_mapbuffer",
Pair("../ReactCommon/react/renderer/mapbuffer/", "react/renderer/mapbuffer/")),
Expand Down Expand Up @@ -532,6 +538,7 @@ android {
"runtimeexecutor",
"react_codegen_rncore",
"react_debug",
"react_featureflags",
"react_utils",
"react_render_componentregistry",
"react_newarchdefaults",
Expand All @@ -546,6 +553,7 @@ android {
"jsi",
"glog",
"fabricjni",
"featureflagsjni",
"react_render_mapbuffer",
"yoga",
"folly_runtime",
Expand Down Expand Up @@ -677,6 +685,7 @@ android {
create("jsi") { headers = File(prefabHeadersDir, "jsi").absolutePath }
create("glog") { headers = File(prefabHeadersDir, "glog").absolutePath }
create("fabricjni") { headers = File(prefabHeadersDir, "fabricjni").absolutePath }
create("featureflagsjni") { headers = File(prefabHeadersDir, "featureflagsjni").absolutePath }
create("react_render_mapbuffer") {
headers = File(prefabHeadersDir, "react_render_mapbuffer").absolutePath
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ add_library(rrc_view ALIAS ReactAndroid::rrc_view)
add_library(jsi ALIAS ReactAndroid::jsi)
add_library(glog ALIAS ReactAndroid::glog)
add_library(fabricjni ALIAS ReactAndroid::fabricjni)
add_library(featureflagsjni ALIAS ReactAndroid::featureflagsjni)
add_library(react_render_mapbuffer ALIAS ReactAndroid::react_render_mapbuffer)
add_library(yoga ALIAS ReactAndroid::yoga)
add_library(folly_runtime ALIAS ReactAndroid::folly_runtime)
Expand All @@ -90,6 +91,7 @@ add_library(fbjni ALIAS fbjni::fbjni)

target_link_libraries(${CMAKE_PROJECT_NAME}
fabricjni # prefab ready
featureflagsjni # prefab ready
fbjni # via 3rd party prefab
folly_runtime # prefab ready
glog # prefab ready
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.
*
* @generated SignedSource<<941c7eb38bebe95c3b038de7bf3ae912>>
*/

/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* `packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json`.
*
* To regenerate this code, run
* `packages/react-native/scripts/featureflags/update.js`.
*/

package com.facebook.react.internal.featureflags

object ReactNativeFeatureFlags {
var accessor = ReactNativeFeatureFlagsAccessor()

/**
* Common flag for testing. Do NOT modify.
*/
fun commonTestFlag() = accessor.commonTestFlag()

/**
* Overrides the feature flags with the ones provided by the given provider.
*/
fun override(provider: ReactNativeFeatureFlagsProvider) =
ReactNativeFeatureFlagsCxxInterop.override(provider as Any)

/**
* Removes the overridden feature flags and returns default values again.
*/
fun reset() {
ReactNativeFeatureFlagsCxxInterop.reset()
accessor = ReactNativeFeatureFlagsAccessor()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.
*
* @generated SignedSource<<e90fe3ecb417f22607ac92b7fb19e85c>>
*/

/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* `packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json`.
*
* To regenerate this code, run
* `packages/react-native/scripts/featureflags/update.js`.
*/

package com.facebook.react.internal.featureflags

class ReactNativeFeatureFlagsAccessor {
var commonTestFlagCache: Boolean? = null

fun commonTestFlag(): Boolean {
var cached = commonTestFlagCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.commonTestFlag()
commonTestFlagCache = cached
}
return cached
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.
*
* @generated SignedSource<<667e03a6b8ae493f3c75f1a831184055>>
*/

/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* `packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json`.
*
* To regenerate this code, run
* `packages/react-native/scripts/featureflags/update.js`.
*/

package com.facebook.react.internal.featureflags

import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.soloader.SoLoader

@DoNotStrip
object ReactNativeFeatureFlagsCxxInterop {
init {
SoLoader.loadLibrary("reactfeatureflagsjni")
}

@DoNotStrip @JvmStatic external fun commonTestFlag(): Boolean

@DoNotStrip @JvmStatic external fun override(provider: Any)

@DoNotStrip @JvmStatic external fun reset()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.
*
* @generated SignedSource<<35de3b0df307b57616b1da2c31d0e918>>
*/

/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* `packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json`.
*
* To regenerate this code, run
* `packages/react-native/scripts/featureflags/update.js`.
*/

package com.facebook.react.internal.featureflags

open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvider {
// We could use JNI to get the defaults from C++,
// but that is more expensive than just duplicating the defaults here.

override fun commonTestFlag(): Boolean = false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*
* @generated SignedSource<<9f38db38c05560c89d27ce8c70000332>>
*/

/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* `packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json`.
*
* To regenerate this code, run
* `packages/react-native/scripts/featureflags/update.js`.
*/

package com.facebook.react.internal.featureflags

interface ReactNativeFeatureFlagsProvider {
fun commonTestFlag(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_react_common_subdir(hermes/inspector-modern)
add_react_common_subdir(react/renderer/runtimescheduler)
add_react_common_subdir(react/debug)
add_react_common_subdir(react/config)
add_react_common_subdir(react/featureflags)
add_react_common_subdir(react/renderer/animations)
add_react_common_subdir(react/renderer/attributedstring)
add_react_common_subdir(react/renderer/componentregistry)
Expand Down Expand Up @@ -118,6 +119,7 @@ add_react_android_subdir(src/main/jni/react/uimanager)
add_react_android_subdir(src/main/jni/react/mapbuffer)
add_react_android_subdir(src/main/jni/react/reactnativeblob)
add_react_android_subdir(src/main/jni/react/fabric)
add_react_android_subdir(src/main/jni/react/featureflags)
add_react_android_subdir(src/main/jni/react/newarchdefaults)
add_react_android_subdir(src/main/jni/react/hermes/reactexecutor)
add_react_android_subdir(src/main/jni/react/hermes/instrumentation/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ target_link_libraries(
mapbufferjni
react_codegen_rncore
react_debug
react_featureflags
react_render_animations
react_render_attributedstring
react_render_componentregistry
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.

cmake_minimum_required(VERSION 3.13)

file(GLOB featureflagsjni_SRCS CONFIGURE_DEPENDS *.cpp)

add_library(
featureflagsjni
SHARED
${featureflagsjni_SRCS}
)

target_include_directories(featureflagsjni PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(
featureflagsjni
fb
fbjni
react_featureflags
reactnativejni
)

target_compile_options(
featureflagsjni
PRIVATE
-DLOG_TAG=\"ReactNative\"
-fexceptions
-frtti
-std=c++20
-Wall
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.
*
* @generated SignedSource<<0c0fd104af5903288313b9e33fcc3da4>>
*/

/**
* IMPORTANT: Do NOT modify this file directly.
*
* To change the definition of the flags, edit
* `packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.json`.
*
* To regenerate this code, run
* `packages/react-native/scripts/featureflags/update.js`.
*/

#include "JReactNativeFeatureFlagsCxxInterop.h"
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/featureflags/ReactNativeFeatureFlagsProviderHolder.h>

namespace facebook::react {

bool JReactNativeFeatureFlagsCxxInterop::commonTestFlag(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::commonTestFlag();
}

void JReactNativeFeatureFlagsCxxInterop::override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/,
jni::alias_ref<jobject> provider) {
ReactNativeFeatureFlags::override(
std::make_unique<ReactNativeFeatureFlagsProviderHolder>(provider));
}

void JReactNativeFeatureFlagsCxxInterop::reset(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
ReactNativeFeatureFlags::reset();
}

void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
javaClassLocal()->registerNatives({
makeNativeMethod(
"override", JReactNativeFeatureFlagsCxxInterop::override),
makeNativeMethod("reset", JReactNativeFeatureFlagsCxxInterop::reset),
makeNativeMethod(
"commonTestFlag",
JReactNativeFeatureFlagsCxxInterop::commonTestFlag),
});
}

} // namespace facebook::react
Loading

0 comments on commit 5aca704

Please sign in to comment.