Skip to content

Commit a75e615

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Centralize C++ compiler flags in rn_defs.bzl
Summary: Centralize C++ compiler flags in rn_defs.bzl. There is really no reason for these Cxx libraries to specify their own compiler flags: nearly 100% of them are identical, and the copypasta makes it difficult to make repo-wide changes (like upgrading C++ versions, etc). This is now causing build failures until everything is migrated properly, and there are two flags (enable_rtti and enable_exceptions) that MUST have the same value and can be configured per-module, as needed. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D31631767 fbshipit-source-id: 84f0441eb0ad09219e97d13babe0707d25f08472
1 parent 678f2cb commit a75e615

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

tools/build_defs/oss/rn_defs.bzl

+26-4
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,39 @@ 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, **kwargs):
84-
new_kwargs = {
83+
def rn_xplat_cxx_library(name, compiler_flags_enable_exceptions = True, compiler_flags_enable_rtti = True, **kwargs):
84+
visibility = kwargs.get("visibility", [])
85+
kwargs = {
8586
k: v
8687
for k, v in kwargs.items()
8788
if k.startswith("exported_")
8889
}
8990

91+
# RTTI and exceptions must either be both on, or both off
92+
if compiler_flags_enable_exceptions != compiler_flags_enable_rtti:
93+
fail("Must enable or disable both exceptions and RTTI; they cannot be mismatched. See this post for details: https://fb.workplace.com/groups/iosappsize/permalink/2277094415672494/")
94+
95+
# These are the default compiler flags for ALL React Native Cxx targets.
96+
# For all of these, we PREPEND to compiler_flags: if these are already set
97+
# or being overridden in compiler_flags, it's very likely that the flag is set
98+
# app-wide or that we're otherwise in some special mode.
99+
kwargs["compiler_flags"] = kwargs.get("compiler_flags", [])
100+
kwargs["compiler_flags"] = ["-std=c++17"] + kwargs["compiler_flags"]
101+
kwargs["compiler_flags"] = ["-Wall"] + kwargs["compiler_flags"]
102+
kwargs["compiler_flags"] = ["-Werror"] + kwargs["compiler_flags"]
103+
if compiler_flags_enable_exceptions:
104+
kwargs["compiler_flags"] = ["-fexceptions"] + kwargs["compiler_flags"]
105+
else:
106+
kwargs["compiler_flags"] = ["-fno-exceptions"] + kwargs["compiler_flags"]
107+
if compiler_flags_enable_rtti:
108+
kwargs["compiler_flags"] = ["-frtti"] + kwargs["compiler_flags"]
109+
else:
110+
kwargs["compiler_flags"] = ["-fno-rtti"] + kwargs["compiler_flags"]
111+
90112
native.cxx_library(
91113
name = name,
92-
visibility = kwargs.get("visibility", []),
93-
**new_kwargs
114+
visibility = visibility,
115+
**kwargs
94116
)
95117

96118
rn_xplat_cxx_library2 = rn_xplat_cxx_library

0 commit comments

Comments
 (0)