Skip to content

Commit d291a7e

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Allow disabling RTTI/exceptions for android builds; disable by default on Android
Summary: For fbandroid builds only, disable RTTI and exceptions by default. Changelog: [Internal] Reviewed By: philIip Differential Revision: D31632757 fbshipit-source-id: cfe0e43486df19fcaacc2b5b818b9d00ec2d427f
1 parent e494e4b commit d291a7e

File tree

8 files changed

+44
-34
lines changed

8 files changed

+44
-34
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/jni/BUCK

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ rn_xplat_cxx_library(
1111
],
1212
prefix = "react/fabric",
1313
),
14-
compiler_flags_enable_exceptions = True,
15-
compiler_flags_enable_rtti = True, # dynamic_cast used within Binding.cpp
14+
compiler_flags_enable_exceptions = False,
15+
compiler_flags_enable_rtti = False, # for YogaLayoutableShadowNode?
1616
fbandroid_allow_jni_merging = True,
1717
labels = ["supermodule:xplat/default/public.react_native.infra"],
1818
platforms = ANDROID,

ReactCommon/react/config/BUCK

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ rn_xplat_cxx_library(
1818
],
1919
prefix = "react/config",
2020
),
21+
compiler_flags_enable_exceptions = True,
22+
compiler_flags_enable_rtti = True, # for ReactNativeConfig
2123
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
2224
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
2325
force_static = True,

ReactCommon/react/renderer/components/view/BUCK

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ rn_xplat_cxx_library(
3535
],
3636
prefix = "react/renderer/components/view",
3737
),
38+
compiler_flags_enable_exceptions = False,
39+
compiler_flags_enable_rtti = False, # YogaLayoutableShadowNode
3840
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
3941
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
4042
force_static = True,

ReactCommon/react/renderer/core/BUCK

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ rn_xplat_cxx_library(
3232
],
3333
prefix = "react/renderer/core",
3434
),
35-
compiler_flags_enable_exceptions = True,
36-
compiler_flags_enable_rtti = True, # Needed for DebugStringConvertible - need to find a non-RTTI way to do this / enable RTTI for debug builds only
35+
compiler_flags_enable_exceptions = False,
36+
compiler_flags_enable_rtti = False, # Needed for DebugStringConvertible - need to find a non-RTTI way to do this / enable RTTI for debug builds only. Also EventBeat/AsyncEventBeat
3737
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
3838
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
3939
force_static = True,

ReactCommon/react/renderer/core/LayoutableShadowNode.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@
1717
namespace facebook {
1818
namespace react {
1919

20+
LayoutableShadowNode::LayoutableShadowNode(
21+
ShadowNodeFragment const &fragment,
22+
ShadowNodeFamily::Shared const &family,
23+
ShadowNodeTraits traits)
24+
: ShadowNode(fragment, family, traits), layoutMetrics_({}) {}
25+
26+
LayoutableShadowNode::LayoutableShadowNode(
27+
ShadowNode const &sourceShadowNode,
28+
ShadowNodeFragment const &fragment)
29+
: ShadowNode(sourceShadowNode, fragment),
30+
layoutMetrics_(static_cast<LayoutableShadowNode const &>(sourceShadowNode)
31+
.layoutMetrics_) {}
32+
2033
LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
2134
ShadowNodeFamily const &descendantNodeFamily,
2235
LayoutableShadowNode const &ancestorNode,
@@ -118,19 +131,6 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
118131
return layoutMetrics;
119132
}
120133

121-
LayoutableShadowNode::LayoutableShadowNode(
122-
ShadowNodeFragment const &fragment,
123-
ShadowNodeFamily::Shared const &family,
124-
ShadowNodeTraits traits)
125-
: ShadowNode(fragment, family, traits), layoutMetrics_({}) {}
126-
127-
LayoutableShadowNode::LayoutableShadowNode(
128-
ShadowNode const &sourceShadowNode,
129-
ShadowNodeFragment const &fragment)
130-
: ShadowNode(sourceShadowNode, fragment),
131-
layoutMetrics_(static_cast<LayoutableShadowNode const &>(sourceShadowNode)
132-
.layoutMetrics_) {}
133-
134134
ShadowNodeTraits LayoutableShadowNode::BaseTraits() {
135135
auto traits = ShadowNodeTraits{};
136136
traits.set(ShadowNodeTraits::Trait::LayoutableKind);
@@ -202,16 +202,6 @@ Float LayoutableShadowNode::lastBaseline(Size size) const {
202202
return 0;
203203
}
204204

205-
void LayoutableShadowNode::layoutTree(
206-
LayoutContext layoutContext,
207-
LayoutConstraints layoutConstraints) {
208-
// Default implementation does nothing.
209-
}
210-
211-
void LayoutableShadowNode::layout(LayoutContext layoutContext) {
212-
// Default implementation does nothing.
213-
}
214-
215205
ShadowNode::Shared LayoutableShadowNode::findNodeAtPoint(
216206
ShadowNode::Shared node,
217207
Point point) {

ReactCommon/react/renderer/core/LayoutableShadowNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class LayoutableShadowNode : public ShadowNode {
7070
*/
7171
virtual void layoutTree(
7272
LayoutContext layoutContext,
73-
LayoutConstraints layoutConstraints);
73+
LayoutConstraints layoutConstraints)=0;
7474

7575
/*
7676
* Measures the node (and node content, probably recursively) with
@@ -101,7 +101,7 @@ class LayoutableShadowNode : public ShadowNode {
101101
* - Calculate and assign `LayoutMetrics` for the children;
102102
* - Call itself recursively on every child if needed.
103103
*/
104-
virtual void layout(LayoutContext layoutContext);
104+
virtual void layout(LayoutContext layoutContext)=0;
105105

106106
/*
107107
* Returns layout metrics computed during previous layout pass.

ReactCommon/react/renderer/debug/BUCK

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ rn_xplat_cxx_library(
3131
],
3232
prefix = "react/renderer/debug",
3333
),
34+
compiler_flags_enable_exceptions = True,
35+
compiler_flags_enable_rtti = True, # DebugStringConvertible
3436
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
3537
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
3638
force_static = True,

tools/build_defs/oss/rn_defs.bzl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_react_native_preprocessor_flags():
8080
return []
8181

8282
# Building is not supported in OSS right now
83-
def rn_xplat_cxx_library(name, compiler_flags_enable_exceptions = True, compiler_flags_enable_rtti = True, **kwargs):
83+
def rn_xplat_cxx_library(name, compiler_flags_enable_exceptions = False, compiler_flags_enable_rtti = False, **kwargs):
8484
visibility = kwargs.get("visibility", [])
8585
kwargs = {
8686
k: v
@@ -97,17 +97,31 @@ def rn_xplat_cxx_library(name, compiler_flags_enable_exceptions = True, compiler
9797
# or being overridden in compiler_flags, it's very likely that the flag is set
9898
# app-wide or that we're otherwise in some special mode.
9999
kwargs["compiler_flags"] = kwargs.get("compiler_flags", [])
100+
kwargs["fbobjc_compiler_flags"] = kwargs.get("fbobjc_compiler_flags", [])
101+
kwargs["fbandroid_compiler_flags"] = kwargs.get("fbandroid_compiler_flags", [])
102+
kwargs["windows_compiler_flags"] = kwargs.get("windows_compiler_flags", [])
100103
kwargs["compiler_flags"] = ["-std=c++17"] + kwargs["compiler_flags"]
101104
kwargs["compiler_flags"] = ["-Wall"] + kwargs["compiler_flags"]
102105
kwargs["compiler_flags"] = ["-Werror"] + kwargs["compiler_flags"]
106+
107+
# RTTI and exceptions allowed for ObjC/iOS, macos, Windows unconditionally for now
108+
kwargs["fbobjc_compiler_flags"] = ["-fexceptions"] + kwargs["fbobjc_compiler_flags"]
109+
kwargs["windows_compiler_flags"] = ["-fno-exceptions"] + kwargs["windows_compiler_flags"]
110+
kwargs["fbobjc_compiler_flags"] = ["-frtti"] + kwargs["fbobjc_compiler_flags"]
111+
kwargs["windows_compiler_flags"] = ["-frtti"] + kwargs["windows_compiler_flags"]
112+
113+
# For now, we allow turning off RTTI and exceptions for android builds only
103114
if compiler_flags_enable_exceptions:
104-
kwargs["compiler_flags"] = ["-fexceptions"] + kwargs["compiler_flags"]
115+
kwargs["fbandroid_compiler_flags"] = ["-fexceptions"] + kwargs["fbandroid_compiler_flags"]
105116
else:
106-
kwargs["compiler_flags"] = ["-fno-exceptions"] + kwargs["compiler_flags"]
117+
# TODO: fbjni currently DOES NOT WORK with -fno-exceptions, which breaks MOST RN Android modules
118+
kwargs["fbandroid_compiler_flags"] = ["-fexceptions"] + kwargs["fbandroid_compiler_flags"]
119+
#kwargs["fbandroid_compiler_flags"] = ["-fno-exceptions"] + kwargs["fbandroid_compiler_flags"]
120+
107121
if compiler_flags_enable_rtti:
108-
kwargs["compiler_flags"] = ["-frtti"] + kwargs["compiler_flags"]
122+
kwargs["fbandroid_compiler_flags"] = ["-frtti"] + kwargs["fbandroid_compiler_flags"]
109123
else:
110-
kwargs["compiler_flags"] = ["-fno-rtti"] + kwargs["compiler_flags"]
124+
kwargs["fbandroid_compiler_flags"] = ["-fno-rtti"] + kwargs["fbandroid_compiler_flags"]
111125

112126
native.cxx_library(
113127
name = name,

0 commit comments

Comments
 (0)