diff --git a/ReactCommon/React-Fabric.podspec b/ReactCommon/React-Fabric.podspec index e439a5d7e634b1..ee46e5f291b6a5 100644 --- a/ReactCommon/React-Fabric.podspec +++ b/ReactCommon/React-Fabric.podspec @@ -235,7 +235,8 @@ Pod::Spec.new do |s| s.subspec "debug_core" do |ss| ss.dependency folly_dep_name, folly_version ss.compiler_flags = folly_compiler_flags - ss.source_files = "react/debug/**/*.{m,mm,cpp,h}" + ss.source_files = "react/debug/*.h", + "react/debug/ios/**/*.{m,mm,cpp,h}" ss.exclude_files = "react/debug/tests" ss.header_dir = "react/debug" end diff --git a/ReactCommon/react/debug/BUCK b/ReactCommon/react/debug/BUCK index 20c7a930f8c50e..ef141d97dd01aa 100644 --- a/ReactCommon/react/debug/BUCK +++ b/ReactCommon/react/debug/BUCK @@ -14,10 +14,6 @@ APPLE_COMPILER_FLAGS = get_apple_compiler_flags() rn_xplat_cxx_library( name = "debug", - srcs = glob( - ["**/*.cpp"], - exclude = glob(["tests/**/*.cpp"]), - ), headers = glob( ["**/*.h"], exclude = glob(["tests/**/*.h"]), @@ -40,8 +36,10 @@ rn_xplat_cxx_library( # for android react_native_assert "-llog", ], + fbandroid_srcs = glob(["android/**/*.cpp"]), fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), + fbobjc_srcs = glob(["ios/**/*.mm"]), force_static = True, labels = [ "pfh:ReactNative_CommonInfrastructurePlaceholder", diff --git a/ReactCommon/react/debug/CMakeLists.txt b/ReactCommon/react/debug/CMakeLists.txt index ccfc69872e7340..a985ac20a1c713 100644 --- a/ReactCommon/react/debug/CMakeLists.txt +++ b/ReactCommon/react/debug/CMakeLists.txt @@ -16,7 +16,7 @@ add_compile_options( -DLOG_TAG=\"Fabric\") -file(GLOB react_debug_SRC CONFIGURE_DEPENDS *.cpp) +file(GLOB react_debug_SRC CONFIGURE_DEPENDS android/*.cpp) add_library(react_debug SHARED ${react_debug_SRC}) target_include_directories(react_debug PUBLIC ${REACT_COMMON_DIR}) diff --git a/ReactCommon/react/debug/react_native_assert.cpp b/ReactCommon/react/debug/android/react_native_assert.cpp similarity index 76% rename from ReactCommon/react/debug/react_native_assert.cpp rename to ReactCommon/react/debug/android/react_native_assert.cpp index abcdc5e8fbc015..0c7c558ecc7dd6 100644 --- a/ReactCommon/react/debug/react_native_assert.cpp +++ b/ReactCommon/react/debug/android/react_native_assert.cpp @@ -5,17 +5,10 @@ * LICENSE file in the root directory of this source tree. */ -#ifdef __ANDROID__ - #include +#include -// Provide a prototype to silence missing prototype warning in release -// mode. -extern "C" void react_native_assert_fail( - const char *func, - const char *file, - int line, - const char *expr); +#ifdef REACT_NATIVE_DEBUG extern "C" void react_native_assert_fail( const char *func, @@ -42,4 +35,4 @@ extern "C" void react_native_assert_fail( expr); } -#endif // __ANDROID__ +#endif diff --git a/ReactCommon/react/debug/ios/react_native_assert.mm b/ReactCommon/react/debug/ios/react_native_assert.mm new file mode 100644 index 00000000000000..ad9397e37e27a5 --- /dev/null +++ b/ReactCommon/react/debug/ios/react_native_assert.mm @@ -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. + */ + +#import +#import +#import + +#ifdef REACT_NATIVE_DEBUG + +extern "C" void react_native_assert_fail(const char *func, const char *file, int line, const char *expr) +{ + // flush logs because some might be lost on iOS if an assert is hit right after + // this. If you are trying to debug something actively and have added lots of + // LOG statements to track down an issue, there is race between flushing the + // final logs and stopping execution when the assert hits. Thus, if we know an + // assert will fail, we force flushing to happen right before the assert. + LOG(ERROR) << "react_native_assert failure: " << expr; + google::FlushLogFiles(google::GLOG_INFO /*min_severity*/); + + NSCAssert(false, @"%s:%d: function %s: assertion failed (%s)", file, line, func, expr); +} + +#endif diff --git a/ReactCommon/react/debug/react_native_assert.h b/ReactCommon/react/debug/react_native_assert.h index 9ee5ce631c3d0d..57eda382cb993f 100644 --- a/ReactCommon/react/debug/react_native_assert.h +++ b/ReactCommon/react/debug/react_native_assert.h @@ -28,9 +28,8 @@ #else // REACT_NATIVE_DEBUG -#ifdef __ANDROID__ - -#include +#define react_native_assert(e) \ + ((e) ? (void)0 : react_native_assert_fail(__func__, __FILE__, __LINE__, #e)) #ifdef __cplusplus extern "C" { @@ -44,27 +43,4 @@ void react_native_assert_fail( } #endif // __cpusplus -#define react_native_assert(e) \ - ((e) ? (void)0 : react_native_assert_fail(__func__, __FILE__, __LINE__, #e)) - -#else // __ANDROID__ - -#include -#include - -// For all platforms, but iOS+Xcode especially: flush logs because some might be -// lost on iOS if an assert is hit right after this. If you are trying to debug -// something actively and have added lots of LOG statements to track down an -// issue, there is race between flushing the final logs and stopping execution -// when the assert hits. Thus, if we know an assert will fail, we force flushing -// to happen right before the assert. -#define react_native_assert(cond) \ - if (!(cond)) { \ - LOG(ERROR) << "react_native_assert failure: " << #cond; \ - google::FlushLogFiles(google::GLOG_INFO); \ - assert(cond); \ - } - -#endif // platforms besides __ANDROID__ - #endif // REACT_NATIVE_DEBUG