From 063c2b4668b279ccbca639f98f7a0a5c4d7c5690 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 11 Aug 2022 04:37:35 -0700 Subject: [PATCH] Enable -Wpedantic for targets inside ReactCommon Summary: React Native is compiled downstream with MSVC, meaning the introduction of code depending on language extensions specific to gcc/clang may cause breakage. We can enable `-Wpedantic` to flag any behavior not officially supported by the specified C++ standard. This will includes rules beyond what MSVC has trouble with, but seems to not have too many "noisy warnings". This change enables -Wpedantic in BUCK targets within ReactCommon. This makes the OSS C++ build for Android/iOS slightly more permissive than the internal build, A followup is to add the changes to OSS build logic as well, to avoid contributors seeing more errors upon internal submission. (checking with cortinico on how to do this for Android). react-native-windows uses a higher warning level than `-Wall`, which is an additional cause of compilation failures, but is not addressed as part of this change. Changelog: [Internal][Changed] - Enable -Wpedantic for targets inside ReactCommon Reviewed By: rshest Differential Revision: D38457812 fbshipit-source-id: 014da1ac0b7ad8f78154e6e447ed58def6bd0d47 --- React/Base/RCTAssert.h | 8 ++--- .../src/main/jni/react/jni/JCallback.h | 7 ++++ ReactCommon/butter/BUCK | 1 + ReactCommon/callinvoker/BUCK | 1 + ReactCommon/cxxreact/BUCK | 4 +++ ReactCommon/cxxreact/JSBundleType.h | 11 ++++--- ReactCommon/jsi/BUCK | 3 ++ ReactCommon/jsinspector/BUCK | 1 + ReactCommon/logger/BUCK | 1 + ReactCommon/react/bridging/BUCK | 2 ++ ReactCommon/react/config/BUCK | 1 + ReactCommon/react/debug/BUCK | 1 + ReactCommon/react/nativemodule/core/BUCK | 1 + ReactCommon/react/nativemodule/samples/BUCK | 1 + ReactCommon/react/renderer/animations/BUCK | 1 + .../react/renderer/attributedstring/BUCK | 1 + .../react/renderer/componentregistry/BUCK | 1 + .../renderer/componentregistry/native/BUCK | 1 + .../react/renderer/components/image/BUCK | 1 + .../renderer/components/inputaccessory/BUCK | 1 + .../components/legacyviewmanagerinterop/BUCK | 1 + .../react/renderer/components/modal/BUCK | 1 + .../renderer/components/progressbar/BUCK | 1 + .../react/renderer/components/root/BUCK | 1 + .../renderer/components/safeareaview/BUCK | 1 + .../react/renderer/components/scrollview/BUCK | 1 + .../react/renderer/components/slider/BUCK | 1 + .../react/renderer/components/switch/BUCK | 1 + .../react/renderer/components/text/BUCK | 1 + .../react/renderer/components/textinput/BUCK | 1 + .../components/textinput/iostextinput/BUCK | 1 + .../components/unimplementedview/BUCK | 1 + .../react/renderer/components/view/BUCK | 1 + .../components/view/propsConversions.h | 32 +++++++++---------- ReactCommon/react/renderer/core/BUCK | 1 + ReactCommon/react/renderer/debug/BUCK | 1 + ReactCommon/react/renderer/element/BUCK | 1 + ReactCommon/react/renderer/graphics/BUCK | 1 + ReactCommon/react/renderer/imagemanager/BUCK | 1 + ReactCommon/react/renderer/leakchecker/BUCK | 1 + ReactCommon/react/renderer/mapbuffer/BUCK | 1 + ReactCommon/react/renderer/mounting/BUCK | 1 + .../react/renderer/runtimescheduler/BUCK | 1 + ReactCommon/react/renderer/scheduler/BUCK | 1 + ReactCommon/react/renderer/telemetry/BUCK | 1 + .../react/renderer/templateprocessor/BUCK | 1 + .../react/renderer/textlayoutmanager/BUCK | 1 + ReactCommon/react/renderer/timeline/BUCK | 1 + ReactCommon/react/renderer/uimanager/BUCK | 1 + ReactCommon/react/test_utils/BUCK | 1 + ReactCommon/react/utils/BUCK | 1 + ReactCommon/reactperflogger/BUCK | 1 + ReactCommon/runtimeexecutor/BUCK | 1 + tools/build_defs/oss/rn_defs.bzl | 21 +++++++++++- 54 files changed, 108 insertions(+), 26 deletions(-) diff --git a/React/Base/RCTAssert.h b/React/Base/RCTAssert.h index e7cb4a003bc9ce..e088fa9582b1f0 100644 --- a/React/Base/RCTAssert.h +++ b/React/Base/RCTAssert.h @@ -159,18 +159,18 @@ RCT_EXTERN NSString *RCTFormatStackTrace(NSArray *> */ #if DEBUG -#define RCTAssertThread(thread, format...) \ +#define RCTAssertThread(thread, ...) \ _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") RCTAssert( \ [(id)thread isKindOfClass:[NSString class]] ? [RCTCurrentThreadName() isEqualToString:(NSString *)thread] \ : [(id)thread isKindOfClass:[NSThread class]] ? [NSThread currentThread] == (NSThread *)thread \ : dispatch_get_current_queue() == (dispatch_queue_t)thread, \ - format); \ + __VA_ARGS__); \ _Pragma("clang diagnostic pop") #else -#define RCTAssertThread(thread, format...) \ - do { \ +#define RCTAssertThread(thread, ...) \ + do { \ } while (0) #endif diff --git a/ReactAndroid/src/main/jni/react/jni/JCallback.h b/ReactAndroid/src/main/jni/react/jni/JCallback.h index 504ad92281f365..da480384d9e897 100644 --- a/ReactAndroid/src/main/jni/react/jni/JCallback.h +++ b/ReactAndroid/src/main/jni/react/jni/JCallback.h @@ -30,9 +30,16 @@ class JCxxCallbackImpl : public jni::HybridClass { "Lcom/facebook/react/bridge/CxxCallbackImpl;"; static void registerNatives() { +#if __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" +#endif javaClassStatic()->registerNatives({ makeNativeMethod("nativeInvoke", JCxxCallbackImpl::invoke), }); +#if __clang__ +#pragma clang diagnostic pop +#endif } private: diff --git a/ReactCommon/butter/BUCK b/ReactCommon/butter/BUCK index e2a65707f06915..4f8b5690b9ae39 100644 --- a/ReactCommon/butter/BUCK +++ b/ReactCommon/butter/BUCK @@ -29,6 +29,7 @@ rn_xplat_cxx_library( ], prefix = "butter", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/callinvoker/BUCK b/ReactCommon/callinvoker/BUCK index 0cd39207d8754a..b11ebbf2440e65 100644 --- a/ReactCommon/callinvoker/BUCK +++ b/ReactCommon/callinvoker/BUCK @@ -10,6 +10,7 @@ rn_xplat_cxx_library( ], prefix = "ReactCommon", ), + compiler_flags_pedantic = True, labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", "supermodule:xplat/default/public.react_native.infra", diff --git a/ReactCommon/cxxreact/BUCK b/ReactCommon/cxxreact/BUCK index 0f23dd8fea8ce2..933d91b45c891b 100644 --- a/ReactCommon/cxxreact/BUCK +++ b/ReactCommon/cxxreact/BUCK @@ -12,6 +12,7 @@ rn_xplat_cxx_library( ], prefix = "cxxreact", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = get_apple_compiler_flags(), force_static = True, labels = [ @@ -36,6 +37,7 @@ rn_xplat_cxx_library( [("", "JSBigString.h")], prefix = "cxxreact", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = get_apple_compiler_flags(), force_static = True, labels = [ @@ -60,6 +62,7 @@ rn_xplat_cxx_library( compiler_flags = [ "-fno-omit-frame-pointer", ], + compiler_flags_pedantic = True, fbobjc_compiler_flags = get_apple_compiler_flags(), labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", @@ -118,6 +121,7 @@ rn_xplat_cxx_library( ) for header in CXXREACT_PUBLIC_HEADERS ]), + compiler_flags_pedantic = True, fbandroid_preprocessor_flags = get_android_inspector_flags(), fbobjc_compiler_flags = get_apple_compiler_flags(), fbobjc_force_static = True, diff --git a/ReactCommon/cxxreact/JSBundleType.h b/ReactCommon/cxxreact/JSBundleType.h index a9cdbc806a78dc..0dee53c0be9130 100644 --- a/ReactCommon/cxxreact/JSBundleType.h +++ b/ReactCommon/cxxreact/JSBundleType.h @@ -36,16 +36,19 @@ enum struct ScriptTag { * bytes from a bundle in a way that gives access to that information. */ FOLLY_PACK_PUSH + +struct FOLLY_PACK_ATTR Magic32 { + uint32_t value; + uint32_t reserved_; +}; + struct FOLLY_PACK_ATTR BundleHeader { BundleHeader() { std::memset(this, 0, sizeof(BundleHeader)); } union { - struct { - uint32_t value; - uint32_t reserved_; - } magic32; + Magic32 magic32; uint64_t magic64; }; uint32_t version; diff --git a/ReactCommon/jsi/BUCK b/ReactCommon/jsi/BUCK index 7186cad79e24fa..2b4ee4c4293c2d 100644 --- a/ReactCommon/jsi/BUCK +++ b/ReactCommon/jsi/BUCK @@ -19,6 +19,7 @@ rn_xplat_cxx_library( "-Wdelete-non-virtual-dtor", "-Wwrite-strings", ], + compiler_flags_pedantic = True, cxx_compiler_flags = [ "-Wglobal-constructors", "-Wmissing-prototypes", @@ -43,6 +44,7 @@ rn_xplat_cxx_library( exported_headers = [ "jsi/JSIDynamic.h", ], + compiler_flags_pedantic = True, fbobjc_force_static = True, labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", @@ -68,6 +70,7 @@ rn_xplat_cxx_library( "JSCRuntime.h", ], apple_sdks = (IOS, MACOSX), + compiler_flags_pedantic = True, fbobjc_compiler_flags = [ "-Os", ], diff --git a/ReactCommon/jsinspector/BUCK b/ReactCommon/jsinspector/BUCK index 24e63a862a7067..1747b1870a6430 100644 --- a/ReactCommon/jsinspector/BUCK +++ b/ReactCommon/jsinspector/BUCK @@ -26,6 +26,7 @@ rn_xplat_cxx_library( ], prefix = "jsinspector", ), + compiler_flags_pedantic = True, fbandroid_preferred_linkage = "shared", labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", diff --git a/ReactCommon/logger/BUCK b/ReactCommon/logger/BUCK index 09b5f65e1a7309..532f75a500cf28 100644 --- a/ReactCommon/logger/BUCK +++ b/ReactCommon/logger/BUCK @@ -26,6 +26,7 @@ rn_xplat_cxx_library( ], prefix = "logger", ), + compiler_flags_pedantic = True, fbandroid_preferred_linkage = "shared", labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", diff --git a/ReactCommon/react/bridging/BUCK b/ReactCommon/react/bridging/BUCK index 72e1dac38a84c3..52a1eb1e5f0ad2 100644 --- a/ReactCommon/react/bridging/BUCK +++ b/ReactCommon/react/bridging/BUCK @@ -7,6 +7,7 @@ rn_xplat_cxx_library( exported_headers = glob(["*.h"]), compiler_flags_enable_exceptions = True, compiler_flags_enable_rtti = True, + compiler_flags_pedantic = True, labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", "supermodule:xplat/default/public.react_native.infra", @@ -28,6 +29,7 @@ rn_xplat_cxx_library( name = "testlib", header_namespace = "react/bridging", exported_headers = glob(["tests/*.h"]), + compiler_flags_pedantic = True, platforms = (ANDROID, APPLE, CXX), visibility = ["PUBLIC"], exported_deps = [ diff --git a/ReactCommon/react/config/BUCK b/ReactCommon/react/config/BUCK index 767c3a8b0125b6..cf77bda2070dac 100644 --- a/ReactCommon/react/config/BUCK +++ b/ReactCommon/react/config/BUCK @@ -20,6 +20,7 @@ rn_xplat_cxx_library( ), compiler_flags_enable_exceptions = True, compiler_flags_enable_rtti = True, # for ReactNativeConfig + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/debug/BUCK b/ReactCommon/react/debug/BUCK index 756cd3dcfa0a5c..b3784149348f42 100644 --- a/ReactCommon/react/debug/BUCK +++ b/ReactCommon/react/debug/BUCK @@ -29,6 +29,7 @@ rn_xplat_cxx_library( ], prefix = "react/debug", ), + compiler_flags_pedantic = True, exported_platform_linker_flags = [ ( "^android.*", diff --git a/ReactCommon/react/nativemodule/core/BUCK b/ReactCommon/react/nativemodule/core/BUCK index 1f46f068049151..99fa52fe49bb69 100644 --- a/ReactCommon/react/nativemodule/core/BUCK +++ b/ReactCommon/react/nativemodule/core/BUCK @@ -15,6 +15,7 @@ rn_xplat_cxx_library( compiler_flags = [ "-Wno-global-constructors", ], + compiler_flags_pedantic = True, fbandroid_deps = [ react_native_target("jni/react/jni:jni"), FBJNI_TARGET, diff --git a/ReactCommon/react/nativemodule/samples/BUCK b/ReactCommon/react/nativemodule/samples/BUCK index b11b13c7488eed..d0578aa0d399d0 100644 --- a/ReactCommon/react/nativemodule/samples/BUCK +++ b/ReactCommon/react/nativemodule/samples/BUCK @@ -12,6 +12,7 @@ rn_xplat_cxx_library( ], prefix = "ReactCommon", ), + compiler_flags_pedantic = True, fbandroid_deps = [ react_native_target("jni/react/jni:jni"), FBJNI_TARGET, diff --git a/ReactCommon/react/renderer/animations/BUCK b/ReactCommon/react/renderer/animations/BUCK index 8c4ad8f448f3a0..034f7aaaf8f128 100644 --- a/ReactCommon/react/renderer/animations/BUCK +++ b/ReactCommon/react/renderer/animations/BUCK @@ -34,6 +34,7 @@ rn_xplat_cxx_library( compiler_flags = [ "-lm", ], + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/attributedstring/BUCK b/ReactCommon/react/renderer/attributedstring/BUCK index 028c78c822b1a5..d1a324573d5182 100644 --- a/ReactCommon/react/renderer/attributedstring/BUCK +++ b/ReactCommon/react/renderer/attributedstring/BUCK @@ -31,6 +31,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/attributedstring", ), + compiler_flags_pedantic = True, fbandroid_deps = [ react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), ], diff --git a/ReactCommon/react/renderer/componentregistry/BUCK b/ReactCommon/react/renderer/componentregistry/BUCK index 6b8b907041c9ab..afc4c72698ef42 100644 --- a/ReactCommon/react/renderer/componentregistry/BUCK +++ b/ReactCommon/react/renderer/componentregistry/BUCK @@ -30,6 +30,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/componentregistry", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/componentregistry/native/BUCK b/ReactCommon/react/renderer/componentregistry/native/BUCK index 72507b951e8091..c0c3200ca14df3 100644 --- a/ReactCommon/react/renderer/componentregistry/native/BUCK +++ b/ReactCommon/react/renderer/componentregistry/native/BUCK @@ -29,6 +29,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/componentregistry/native", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/components/image/BUCK b/ReactCommon/react/renderer/components/image/BUCK index a26a74dc9ee7dd..b793dc52158635 100644 --- a/ReactCommon/react/renderer/components/image/BUCK +++ b/ReactCommon/react/renderer/components/image/BUCK @@ -29,6 +29,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/image", ), + compiler_flags_pedantic = True, fbandroid_deps = [ react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), ], diff --git a/ReactCommon/react/renderer/components/inputaccessory/BUCK b/ReactCommon/react/renderer/components/inputaccessory/BUCK index 6e26a77b96a8d5..bd511c03120c33 100644 --- a/ReactCommon/react/renderer/components/inputaccessory/BUCK +++ b/ReactCommon/react/renderer/components/inputaccessory/BUCK @@ -24,6 +24,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/inputaccessory", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/BUCK b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/BUCK index 749b0958532e6a..86ed78698668c7 100644 --- a/ReactCommon/react/renderer/components/legacyviewmanagerinterop/BUCK +++ b/ReactCommon/react/renderer/components/legacyviewmanagerinterop/BUCK @@ -27,6 +27,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/legacyviewmanagerinterop", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/components/modal/BUCK b/ReactCommon/react/renderer/components/modal/BUCK index fb7ccbc840daa4..685739886b6e7b 100644 --- a/ReactCommon/react/renderer/components/modal/BUCK +++ b/ReactCommon/react/renderer/components/modal/BUCK @@ -31,6 +31,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/modal", ), + compiler_flags_pedantic = True, fbandroid_deps = [ react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), ], diff --git a/ReactCommon/react/renderer/components/progressbar/BUCK b/ReactCommon/react/renderer/components/progressbar/BUCK index c255c2cd4ede89..8f13f5cbef974a 100644 --- a/ReactCommon/react/renderer/components/progressbar/BUCK +++ b/ReactCommon/react/renderer/components/progressbar/BUCK @@ -32,6 +32,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/progressbar", ), + compiler_flags_pedantic = True, cxx_tests = [":tests"], fbandroid_deps = [ react_native_target("jni/react/jni:jni"), diff --git a/ReactCommon/react/renderer/components/root/BUCK b/ReactCommon/react/renderer/components/root/BUCK index 69f2036924fe03..9b8050c8af270e 100644 --- a/ReactCommon/react/renderer/components/root/BUCK +++ b/ReactCommon/react/renderer/components/root/BUCK @@ -29,6 +29,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/root", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), labels = [ diff --git a/ReactCommon/react/renderer/components/safeareaview/BUCK b/ReactCommon/react/renderer/components/safeareaview/BUCK index f0837d54ada75e..a967655f902b8b 100644 --- a/ReactCommon/react/renderer/components/safeareaview/BUCK +++ b/ReactCommon/react/renderer/components/safeareaview/BUCK @@ -24,6 +24,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/safeareaview", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/components/scrollview/BUCK b/ReactCommon/react/renderer/components/scrollview/BUCK index 20d52e1e84c172..ab49fcc7ea6cc3 100644 --- a/ReactCommon/react/renderer/components/scrollview/BUCK +++ b/ReactCommon/react/renderer/components/scrollview/BUCK @@ -32,6 +32,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/scrollview", ), + compiler_flags_pedantic = True, fbandroid_deps = [ react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), ], diff --git a/ReactCommon/react/renderer/components/slider/BUCK b/ReactCommon/react/renderer/components/slider/BUCK index 59bd982faeee4e..bfbdb595fa5cad 100644 --- a/ReactCommon/react/renderer/components/slider/BUCK +++ b/ReactCommon/react/renderer/components/slider/BUCK @@ -33,6 +33,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/slider", ), + compiler_flags_pedantic = True, cxx_tests = [":tests"], fbandroid_deps = [ react_native_target("jni/react/jni:jni"), diff --git a/ReactCommon/react/renderer/components/switch/BUCK b/ReactCommon/react/renderer/components/switch/BUCK index 33d4f9170377d8..1ee6c08ea4967f 100644 --- a/ReactCommon/react/renderer/components/switch/BUCK +++ b/ReactCommon/react/renderer/components/switch/BUCK @@ -34,6 +34,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/androidswitch", ), + compiler_flags_pedantic = True, cxx_tests = [":tests"], fbandroid_deps = [ react_native_target("jni/react/jni:jni"), diff --git a/ReactCommon/react/renderer/components/text/BUCK b/ReactCommon/react/renderer/components/text/BUCK index 00e9e735d35c66..c21bba01bf7728 100644 --- a/ReactCommon/react/renderer/components/text/BUCK +++ b/ReactCommon/react/renderer/components/text/BUCK @@ -36,6 +36,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/text", ), + compiler_flags_pedantic = True, cxx_tests = [":tests"], fbandroid_deps = [ react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), diff --git a/ReactCommon/react/renderer/components/textinput/BUCK b/ReactCommon/react/renderer/components/textinput/BUCK index a6d1767b918292..0205d2c81f128f 100644 --- a/ReactCommon/react/renderer/components/textinput/BUCK +++ b/ReactCommon/react/renderer/components/textinput/BUCK @@ -33,6 +33,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/androidtextinput", ), + compiler_flags_pedantic = True, cxx_tests = [":tests"], fbandroid_deps = [ react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), diff --git a/ReactCommon/react/renderer/components/textinput/iostextinput/BUCK b/ReactCommon/react/renderer/components/textinput/iostextinput/BUCK index 548ad6ade82146..ecd9ecc205f196 100644 --- a/ReactCommon/react/renderer/components/textinput/iostextinput/BUCK +++ b/ReactCommon/react/renderer/components/textinput/iostextinput/BUCK @@ -33,6 +33,7 @@ rn_xplat_cxx_library( # TODO(shergin) T26519801 Figure out better directories structure prefix = "react/renderer/components/iostextinput", ), + compiler_flags_pedantic = True, cxx_tests = [":tests"], fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), diff --git a/ReactCommon/react/renderer/components/unimplementedview/BUCK b/ReactCommon/react/renderer/components/unimplementedview/BUCK index c90681d7ac4bf8..6ae78ce5c8d1aa 100644 --- a/ReactCommon/react/renderer/components/unimplementedview/BUCK +++ b/ReactCommon/react/renderer/components/unimplementedview/BUCK @@ -29,6 +29,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/unimplementedview", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), labels = [ diff --git a/ReactCommon/react/renderer/components/view/BUCK b/ReactCommon/react/renderer/components/view/BUCK index 57552ca79fa12e..3ed2447e3dfb21 100644 --- a/ReactCommon/react/renderer/components/view/BUCK +++ b/ReactCommon/react/renderer/components/view/BUCK @@ -35,6 +35,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/components/view", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/components/view/propsConversions.h b/ReactCommon/react/renderer/components/view/propsConversions.h index f045dd3b9bc664..1bf357a4a79f84 100644 --- a/ReactCommon/react/renderer/components/view/propsConversions.h +++ b/ReactCommon/react/renderer/components/view/propsConversions.h @@ -657,8 +657,8 @@ static inline void fromRawValue( attrIterator->second.hasType()); result = NativeDrawable{ - .kind = NativeDrawable::Kind::ThemeAttr, - .themeAttr = (std::string)attrIterator->second, + NativeDrawable::Kind::ThemeAttr, + (std::string)attrIterator->second, }; } else if (type == "RippleAndroid") { auto color = map.find("color"); @@ -666,21 +666,19 @@ static inline void fromRawValue( auto rippleRadius = map.find("rippleRadius"); result = NativeDrawable{ - .kind = NativeDrawable::Kind::Ripple, - .ripple = - NativeDrawable::Ripple{ - .color = color != map.end() && color->second.hasType() - ? (int32_t)color->second - : std::optional{}, - .borderless = borderless != map.end() && - borderless->second.hasType() - ? (bool)borderless->second - : false, - .rippleRadius = rippleRadius != map.end() && - rippleRadius->second.hasType() - ? (Float)rippleRadius->second - : std::optional{}, - }, + NativeDrawable::Kind::Ripple, + std::string{}, + NativeDrawable::Ripple{ + color != map.end() && color->second.hasType() + ? (int32_t)color->second + : std::optional{}, + borderless != map.end() && borderless->second.hasType() + ? (bool)borderless->second + : false, + rippleRadius != map.end() && rippleRadius->second.hasType() + ? (Float)rippleRadius->second + : std::optional{}, + }, }; } else { LOG(ERROR) << "Unknown native drawable type: " << type; diff --git a/ReactCommon/react/renderer/core/BUCK b/ReactCommon/react/renderer/core/BUCK index 0e079897c475cc..01fbf2aab9b9b2 100644 --- a/ReactCommon/react/renderer/core/BUCK +++ b/ReactCommon/react/renderer/core/BUCK @@ -32,6 +32,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/core", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/debug/BUCK b/ReactCommon/react/renderer/debug/BUCK index d103d00f3b6ae0..e0c512c8c3e109 100644 --- a/ReactCommon/react/renderer/debug/BUCK +++ b/ReactCommon/react/renderer/debug/BUCK @@ -33,6 +33,7 @@ rn_xplat_cxx_library( ), compiler_flags_enable_exceptions = True, compiler_flags_enable_rtti = True, # DebugStringConvertible + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/element/BUCK b/ReactCommon/react/renderer/element/BUCK index 860b323355b842..f9e0214f6e8b7c 100644 --- a/ReactCommon/react/renderer/element/BUCK +++ b/ReactCommon/react/renderer/element/BUCK @@ -31,6 +31,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/element", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/graphics/BUCK b/ReactCommon/react/renderer/graphics/BUCK index 11617a7c884daa..6c48783875f8d2 100644 --- a/ReactCommon/react/renderer/graphics/BUCK +++ b/ReactCommon/react/renderer/graphics/BUCK @@ -36,6 +36,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/graphics", ), + compiler_flags_pedantic = True, cxx_exported_headers = subdir_glob( [ ("platform/cxx/react/renderer/graphics", "**/*.h"), diff --git a/ReactCommon/react/renderer/imagemanager/BUCK b/ReactCommon/react/renderer/imagemanager/BUCK index bba253a74f9ef5..0497729695760d 100644 --- a/ReactCommon/react/renderer/imagemanager/BUCK +++ b/ReactCommon/react/renderer/imagemanager/BUCK @@ -30,6 +30,7 @@ rn_xplat_cxx_library( [("", "*.h")], prefix = "react/renderer/imagemanager", ), + compiler_flags_pedantic = True, contacts = ["oncall+react_native@xmail.facebook.com"], cxx_srcs = glob(["platform/cxx/**/*.cpp"]), # FIXME: android relies on stubs implemented for the cxx platform diff --git a/ReactCommon/react/renderer/leakchecker/BUCK b/ReactCommon/react/renderer/leakchecker/BUCK index a43bcc961c9dcd..86789137376260 100644 --- a/ReactCommon/react/renderer/leakchecker/BUCK +++ b/ReactCommon/react/renderer/leakchecker/BUCK @@ -30,6 +30,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/leakchecker", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/mapbuffer/BUCK b/ReactCommon/react/renderer/mapbuffer/BUCK index a20926efa5872b..8ab0305959f2f8 100644 --- a/ReactCommon/react/renderer/mapbuffer/BUCK +++ b/ReactCommon/react/renderer/mapbuffer/BUCK @@ -29,6 +29,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/mapbuffer", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/mounting/BUCK b/ReactCommon/react/renderer/mounting/BUCK index 67e926a93d2ebb..a563c6ef638544 100644 --- a/ReactCommon/react/renderer/mounting/BUCK +++ b/ReactCommon/react/renderer/mounting/BUCK @@ -32,6 +32,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/mounting", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/runtimescheduler/BUCK b/ReactCommon/react/renderer/runtimescheduler/BUCK index 7db6aa11bbf87c..80310efd096989 100644 --- a/ReactCommon/react/renderer/runtimescheduler/BUCK +++ b/ReactCommon/react/renderer/runtimescheduler/BUCK @@ -31,6 +31,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/runtimescheduler", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/scheduler/BUCK b/ReactCommon/react/renderer/scheduler/BUCK index 2d10b223f875b5..210680a696d2ca 100644 --- a/ReactCommon/react/renderer/scheduler/BUCK +++ b/ReactCommon/react/renderer/scheduler/BUCK @@ -30,6 +30,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/scheduler", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/telemetry/BUCK b/ReactCommon/react/renderer/telemetry/BUCK index d1a1da1f31397f..523b8acc93a0e2 100644 --- a/ReactCommon/react/renderer/telemetry/BUCK +++ b/ReactCommon/react/renderer/telemetry/BUCK @@ -32,6 +32,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/telemetry", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/templateprocessor/BUCK b/ReactCommon/react/renderer/templateprocessor/BUCK index eefba5b9e7494c..1b2dd3283cb7d9 100644 --- a/ReactCommon/react/renderer/templateprocessor/BUCK +++ b/ReactCommon/react/renderer/templateprocessor/BUCK @@ -31,6 +31,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/templateprocessor", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/renderer/textlayoutmanager/BUCK b/ReactCommon/react/renderer/textlayoutmanager/BUCK index ae63b1e7a1c127..a17477b5c84221 100644 --- a/ReactCommon/react/renderer/textlayoutmanager/BUCK +++ b/ReactCommon/react/renderer/textlayoutmanager/BUCK @@ -36,6 +36,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/textlayoutmanager", ), + compiler_flags_pedantic = True, cxx_exported_headers = subdir_glob( [ ("platform/cxx", "*.h"), diff --git a/ReactCommon/react/renderer/timeline/BUCK b/ReactCommon/react/renderer/timeline/BUCK index a5d5e7f7983993..b030a8822458bf 100644 --- a/ReactCommon/react/renderer/timeline/BUCK +++ b/ReactCommon/react/renderer/timeline/BUCK @@ -31,6 +31,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/timeline", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_labels = ["supermodule:ios/isolation/infra.react_native"], fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), diff --git a/ReactCommon/react/renderer/uimanager/BUCK b/ReactCommon/react/renderer/uimanager/BUCK index b701dbdb57e2f5..d18cd57acd870a 100644 --- a/ReactCommon/react/renderer/uimanager/BUCK +++ b/ReactCommon/react/renderer/uimanager/BUCK @@ -31,6 +31,7 @@ rn_xplat_cxx_library( ], prefix = "react/renderer/uimanager", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), force_static = True, diff --git a/ReactCommon/react/test_utils/BUCK b/ReactCommon/react/test_utils/BUCK index 7c520f97297ca0..44defda18d92d1 100644 --- a/ReactCommon/react/test_utils/BUCK +++ b/ReactCommon/react/test_utils/BUCK @@ -27,6 +27,7 @@ rn_xplat_cxx_library( ], prefix = "react/test_utils", ), + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_frameworks = ["Foundation"], fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), diff --git a/ReactCommon/react/utils/BUCK b/ReactCommon/react/utils/BUCK index 3132286ad155d4..270a1cea441ae4 100644 --- a/ReactCommon/react/utils/BUCK +++ b/ReactCommon/react/utils/BUCK @@ -34,6 +34,7 @@ rn_xplat_cxx_library( ], prefix = "react/utils", ), + compiler_flags_pedantic = True, fbandroid_deps = [ react_native_target("java/com/facebook/react/common/mapbuffer/jni:jni"), react_native_xplat_target("react/renderer/mapbuffer:mapbuffer"), diff --git a/ReactCommon/reactperflogger/BUCK b/ReactCommon/reactperflogger/BUCK index 2adcfa47635e70..70ad1c5fb4d7b8 100644 --- a/ReactCommon/reactperflogger/BUCK +++ b/ReactCommon/reactperflogger/BUCK @@ -11,6 +11,7 @@ rn_xplat_cxx_library( compiler_flags = [ "-Wno-global-constructors", ], + compiler_flags_pedantic = True, labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", "supermodule:xplat/default/public.react_native.infra", diff --git a/ReactCommon/runtimeexecutor/BUCK b/ReactCommon/runtimeexecutor/BUCK index e6342f31dbae0f..babd0f922c9ec3 100644 --- a/ReactCommon/runtimeexecutor/BUCK +++ b/ReactCommon/runtimeexecutor/BUCK @@ -28,6 +28,7 @@ rn_xplat_cxx_library( exported_headers = { "ReactCommon/RuntimeExecutor.h": "ReactCommon/RuntimeExecutor.h", }, + compiler_flags_pedantic = True, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_frameworks = ["Foundation"], fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), diff --git a/tools/build_defs/oss/rn_defs.bzl b/tools/build_defs/oss/rn_defs.bzl index b28ee634c0c929..935facd95820cc 100644 --- a/tools/build_defs/oss/rn_defs.bzl +++ b/tools/build_defs/oss/rn_defs.bzl @@ -89,7 +89,12 @@ def get_react_native_ios_target_sdk_version(): return REACT_NATIVE_TARGET_IOS_SDK # Building is not supported in OSS right now -def rn_xplat_cxx_library(name, compiler_flags_enable_exceptions = False, compiler_flags_enable_rtti = False, **kwargs): +def rn_xplat_cxx_library( + name, + compiler_flags_enable_exceptions = False, + compiler_flags_enable_rtti = False, + compiler_flags_pedantic = False, + **kwargs): visibility = kwargs.get("visibility", []) kwargs = { k: v @@ -108,10 +113,24 @@ def rn_xplat_cxx_library(name, compiler_flags_enable_exceptions = False, compile # OSS builds cannot have platform-specific flags here, so these are the same # for all platforms. kwargs["compiler_flags"] = kwargs.get("compiler_flags", []) + kwargs["fbobjc_compiler_flags"] = kwargs.get("fbobjc_compiler_flags", []) + kwargs["fbandroid_compiler_flags"] = kwargs.get("fbandroid_compiler_flags", []) + kwargs["compiler_flags"] = ["-std=c++17"] + kwargs["compiler_flags"] kwargs["compiler_flags"] = ["-Wall"] + kwargs["compiler_flags"] kwargs["compiler_flags"] = ["-Werror"] + kwargs["compiler_flags"] + # -Wpedantic catches usage of nonstandard language extensions that may not + # be supported by other compilers (e.g. MSVC) + if compiler_flags_pedantic: + kwargs["compiler_flags"] = ["-Wpedantic"] + kwargs["compiler_flags"] + + # Do not enable the flag for Apple in targets which also build Objective C++ + if any([file.endswith(".mm") for file in (kwargs.get("srcs", []) + kwargs.get("ios_srcs", []))]): + kwargs["fbobjc_compiler_flags"] = ["-Wno-pedantic"] + kwargs["fbobjc_compiler_flags"] + else: + kwargs["compiler_flags"] = ["-Wno-pedantic"] + kwargs["compiler_flags"] + # For now, we allow turning off RTTI and exceptions for android builds only if compiler_flags_enable_exceptions: kwargs["compiler_flags"] = ["-fexceptions"] + kwargs["compiler_flags"]