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: 78f69eaac52d58f31421c37f34223da763d261d0
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 20, 2024
1 parent d9dabcb commit 6125ee3
Show file tree
Hide file tree
Showing 65 changed files with 2,738 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
5 changes: 5 additions & 0 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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 @@ -546,6 +549,7 @@ android {
"jsi",
"glog",
"fabricjni",
"featureflagsjni",
"react_render_mapbuffer",
"yoga",
"folly_runtime",
Expand Down Expand Up @@ -677,6 +681,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 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<<08ea12cf0c10faa724fd7e16c713337b>>
*/

/**
* 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: Object)

@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
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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<<92dbf3bd6e30ad982edb39de8a0ca392>>
*/

/**
* 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`.
*/

#pragma once

#include <fbjni/fbjni.h>
#include <jni.h>

namespace facebook::react {

class JReactNativeFeatureFlagsCxxInterop
: public jni::JavaClass<JReactNativeFeatureFlagsCxxInterop> {
public:
constexpr static auto kJavaDescriptor =
"Lcom/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop;";

static bool commonTestFlag(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static void override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>,
jni::alias_ref<jobject> provider);

static void reset(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static void registerNatives();
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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.
*/

#include <fbjni/fbjni.h>

#include "JReactNativeFeatureFlagsCxxInterop.h"

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
return facebook::jni::initialize(vm, [] {
facebook::react::JReactNativeFeatureFlagsCxxInterop::registerNatives();
});
}
Loading

0 comments on commit 6125ee3

Please sign in to comment.