Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NDEBUG macro not present in Release builds #5366

Merged
merged 10 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "LayoutAnimationsManager.h"
#include "CollectionUtils.h"
#include "ReanimatedMacros.h"
#include "Shareables.h"

#ifndef NDEBUG
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/LayoutAnimations/LayoutAnimationsManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "LayoutAnimationType.h"
#include "ReanimatedMacros.h"
#include "Shareables.h"

#ifndef NDEBUG
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/NativeModules/NativeReanimatedModule.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "NativeReanimatedModule.h"
#include "ReanimatedMacros.h"

#ifdef RCT_NEW_ARCH_ENABLED
#if REACT_NATIVE_MINOR_VERSION >= 72
Expand Down
2 changes: 2 additions & 0 deletions Common/cpp/NativeModules/NativeReanimatedModule.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "ReanimatedMacros.h"

#ifdef RCT_NEW_ARCH_ENABLED
#include <react/renderer/uimanager/UIManager.h>
#endif
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "RNRuntimeDecorator.h"
#include "ReanimatedMacros.h"
#ifndef NDEBUG
#include "ReanimatedVersion.h"
#endif // NDEBUG
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ReanimatedHermesRuntime.h"
#include "ReanimatedMacros.h"

// Only include this file in Hermes-enabled builds as some platforms (like tvOS)
// don't support hermes and it causes the compilation to fail.
Expand Down
2 changes: 2 additions & 0 deletions Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "ReanimatedMacros.h"

// JS_RUNTIME_HERMES is only set on Android so we have to check __has_include
// on iOS.
#if __APPLE__ && \
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/ReanimatedRuntime/WorkletRuntimeDecorator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "WorkletRuntimeDecorator.h"
#include "JSISerializer.h"
#include "ReanimatedJSIUtils.h"
#include "ReanimatedMacros.h"
#include "Shareables.h"

#ifdef ANDROID
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/SharedItems/Shareables.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Shareables.h"
#include "ReanimatedMacros.h"

using namespace facebook;

Expand Down
1 change: 1 addition & 0 deletions Common/cpp/SharedItems/Shareables.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <utility>
#include <vector>
#include "ReanimatedMacros.h"

#include "WorkletRuntimeRegistry.h"

Expand Down
3 changes: 2 additions & 1 deletion Common/cpp/Tools/JSLogger.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "ReanimatedMacros.h"
#ifndef NDEBUG

#include "JSLogger.h"
#include <memory>
#include "JSLogger.h"

namespace reanimated {

Expand Down
1 change: 1 addition & 0 deletions Common/cpp/Tools/JSLogger.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "ReanimatedMacros.h"
#ifndef NDEBUG

#pragma once
Expand Down
27 changes: 27 additions & 0 deletions Common/cpp/Tools/ReanimatedMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

/*
We need this macro due to migration from DEBUG to NDEBUG macro. XCode does only
inject DEBUG out-of-the-box for Apps (unless the user removes that) so NDEBUG
has to be added manually. Unfortunately, as of now we have no way of injecting
NDEBUG into user's App on iOS without asking him to do: `PRODUCTION=1 pod
install`. However, since
https://github.com/facebook/react-native/commit/93fdcbaed0f69b268e1ae708a52df9463aae2d53
RN user's are no longer asked to do `PRODUCTION=1` and NDEBUG is injected by RN
automatically (on Fabric only). Therefore, we do the following:
- on Android we just look-up NDEBUG
- on iOS we look-up NDEBUG (we still inject it in .podspec when `PRODUCTION=1`)
- if NDEBUG is not defined we check if Fabric is disabled
- if Fabric is disabled, we check for out-of-the-box DEBUG
- if DEBUG isn't defined it's almost safe to assume a release build
*/

#ifndef NDEBUG
#ifdef __APPLE__
tjzel marked this conversation as resolved.
Show resolved Hide resolved
#ifndef RCT_NEW_ARCH_ENABLED
#ifndef DEBUG
#define NDEBUG 1
#endif // DEBUG
#endif // RCT_NEW_ARCH_ENABLED
#endif // __APPLE__
#endif // NDEBUG
1 change: 1 addition & 0 deletions Common/cpp/Tools/ReanimatedVersion.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ReanimatedVersion.h"
#include <regex>
#include <string>
#include "ReanimatedMacros.h"

#ifdef REANIMATED_VERSION
#define STRINGIZE(x) #x
Expand Down
1 change: 1 addition & 0 deletions Common/cpp/Tools/ReanimatedVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <jsi/jsi.h>
#include <string>
#include "ReanimatedMacros.h"

using namespace facebook;

Expand Down
2 changes: 2 additions & 0 deletions Common/cpp/Tools/SingleInstanceChecker.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "ReanimatedMacros.h"

#ifndef NDEBUG

#include <cxxabi.h>
Expand Down
6 changes: 5 additions & 1 deletion Example/ios/ReanimatedExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,10 @@
baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-ReanimatedExample-ReanimatedExampleTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = ReanimatedExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -621,6 +624,7 @@
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
Expand Down
3 changes: 2 additions & 1 deletion Example/ios/ReanimatedExample/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "AppDelegate.h"
#import "RNReanimated/ReanimatedMacros.h"

#import <React/RCTBundleURLProvider.h>

Expand All @@ -16,7 +17,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#ifndef NDEBUG
#ifdef DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
Expand Down
2 changes: 2 additions & 0 deletions Example/ios/ReanimatedExampleTests/ReanimatedExampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#import <React/RCTLog.h>
#import <React/RCTRootView.h>

#import <RNReanimated/ReanimatedMacros.h>

#define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React"

Expand Down
6 changes: 5 additions & 1 deletion FabricExample/ios/FabricExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@
baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-FabricExample-FabricExampleTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = FabricExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -616,6 +619,7 @@
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
Expand Down
3 changes: 2 additions & 1 deletion FabricExample/ios/FabricExample/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "AppDelegate.h"

#import <RNReanimated/ReanimatedMacros.h>
#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate
Expand All @@ -16,7 +17,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#ifndef NDEBUG
#ifdef DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
Expand Down
2 changes: 2 additions & 0 deletions FabricExample/ios/FabricExampleTests/FabricExampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#import <React/RCTLog.h>
#import <React/RCTRootView.h>

#import <RNReanimated/ReanimatedMacros.h>

#define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React"

Expand Down
6 changes: 5 additions & 1 deletion MacOSExample/ios/MacOSExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,10 @@
baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-MacOSExample-MacOSExampleTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = MacOSExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -567,6 +570,7 @@
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
Expand Down
3 changes: 2 additions & 1 deletion MacOSExample/ios/MacOSExample/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "AppDelegate.h"

#import <RNReanimated/ReanimatedMacros.h>
#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate
Expand All @@ -16,7 +17,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#ifndef NDEBUG
#ifdef DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
Expand Down
2 changes: 2 additions & 0 deletions MacOSExample/ios/MacOSExampleTests/MacOSExampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#import <React/RCTLog.h>
#import <React/RCTRootView.h>

#import <RNReanimated/ReanimatedMacros.h>

#define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React"

Expand Down
1 change: 1 addition & 0 deletions MacOSExample/macos/MacOSExample-macOS/AppDelegate.mm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "AppDelegate.h"

#import <RNReanimated/ReanimatedMacros.h>
#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate
Expand Down
1 change: 1 addition & 0 deletions MacOSExample/macos/MacOSExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION,
);
Expand Down
11 changes: 9 additions & 2 deletions TVOSExample/ios/TVOSExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,10 @@
baseConfigurationReference = 36771B2C8C43AC6099096637 /* Pods-TVOSExample-TVOSExampleTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = TVOSExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand Down Expand Up @@ -726,6 +729,7 @@
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
"COCOAPODS=1",
"DEBUG=1",
);
INFOPLIST_FILE = TVOSExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand Down Expand Up @@ -912,7 +916,10 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
tjzel marked this conversation as resolved.
Show resolved Hide resolved
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down Expand Up @@ -85,4 +85,4 @@
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
</Scheme>
6 changes: 3 additions & 3 deletions TVOSExample/ios/TVOSExample/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

#if !TARGET_OS_TV
if (@available(iOS 13.0, *)) {
rootView.backgroundColor = [UIColor systemBackgroundColor];
rootView.backgroundColor = [UIColor systemBackgroundColor];
} else
#endif
{
rootView.backgroundColor = [UIColor whiteColor];
rootView.backgroundColor = [UIColor whiteColor];
}

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
Expand Down Expand Up @@ -87,7 +87,7 @@ - (NSDictionary *)prepareInitialProps

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#ifndef NDEBUG
#ifdef DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
Expand Down
2 changes: 2 additions & 0 deletions TVOSExample/ios/TVOSExampleTests/TVOSExampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#import <React/RCTLog.h>
#import <React/RCTRootView.h>

#import <RNReanimated/ReanimatedMacros.h>

#define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React"

Expand Down
1 change: 1 addition & 0 deletions android/src/main/cpp/LayoutAnimations.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "LayoutAnimations.h"
#include "FeaturesConfig.h"
#include "Logger.h"
#include "ReanimatedMacros.h"

namespace reanimated {

Expand Down
1 change: 1 addition & 0 deletions android/src/main/cpp/LayoutAnimations.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <memory>
#include <string>
#include "JNIHelper.h"
#include "ReanimatedMacros.h"

namespace reanimated {

Expand Down
1 change: 1 addition & 0 deletions android/src/main/cpp/NativeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#ifndef NDEBUG
#include "ReanimatedVersion.h"
#endif // NDEBUG
#include "ReanimatedMacros.h"
#include "WorkletRuntime.h"
#include "WorkletRuntimeCollector.h"

Expand Down
1 change: 1 addition & 0 deletions android/src/main/cpp/NativeProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "JNIHelper.h"
#include "LayoutAnimations.h"
#include "NativeReanimatedModule.h"
#include "ReanimatedMacros.h"
#include "UIScheduler.h"

namespace reanimated {
Expand Down
Loading