Skip to content

Commit

Permalink
chore(build): Add an error message when build with missing header due…
Browse files Browse the repository at this point in the history
… to APPLICATION_EXTENSION_API_ONLY=NO (#4603)
  • Loading branch information
krystofwoldrich authored Dec 10, 2024
1 parent ceae4f3 commit 3cdbaf1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Improvements

- Improve compiler error message for missing Swift declarations due to APPLICATION_EXTENSION_API_ONLY (#4603)

## 8.42.0-beta.2

### Fixes
Expand Down
3 changes: 2 additions & 1 deletion Sentry.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Pod::Spec.new do |s|
# APPLICATION_EXTENSION_API_ONLY has a side effect of exposing all `@objc` marked entities in `Sentry-Swift.h` (regardless of access level)
# This is currently needed for Sentry module to compile. Changing this to NO will break the build.
'APPLICATION_EXTENSION_API_ONLY' => 'YES',
'SWIFT_INCLUDE_PATHS' => '${PODS_TARGET_SRCROOT}/Sources/Sentry/include'
'SWIFT_INCLUDE_PATHS' => '${PODS_TARGET_SRCROOT}/Sources/Sentry/include',
'OTHER_CFLAGS' => '$(inherited) -DAPPLICATION_EXTENSION_API_ONLY_$(APPLICATION_EXTENSION_API_ONLY)'
}
s.watchos.pod_target_xcconfig = {
'OTHER_LDFLAGS' => '$(inherited) -framework WatchKit'
Expand Down
12 changes: 0 additions & 12 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5329,7 +5329,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 63AA75C51EB8B00100D153DE /* Sentry.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_ASSIGN_ENUM = NO;
Expand All @@ -5350,7 +5349,6 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_DYLIB_INSTALL_NAME = "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)";
MODULEMAP_PRIVATE_FILE = "";
OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -5362,7 +5360,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 63AA75C51EB8B00100D153DE /* Sentry.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_ASSIGN_ENUM = NO;
Expand All @@ -5388,7 +5385,6 @@
"@loader_path/Frameworks",
);
MODULEMAP_PRIVATE_FILE = "";
OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
USE_HEADERMAP = YES;
Expand Down Expand Up @@ -5520,7 +5516,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 63AA75C51EB8B00100D153DE /* Sentry.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_ASSIGN_ENUM = NO;
Expand All @@ -5546,7 +5541,6 @@
"@loader_path/Frameworks",
);
MODULEMAP_PRIVATE_FILE = "";
OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -5646,7 +5640,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 63AA75C51EB8B00100D153DE /* Sentry.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_ASSIGN_ENUM = NO;
Expand All @@ -5672,7 +5665,6 @@
"@loader_path/Frameworks",
);
MODULEMAP_PRIVATE_FILE = "";
OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -6123,7 +6115,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 63AA75C51EB8B00100D153DE /* Sentry.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_ASSIGN_ENUM = NO;
Expand All @@ -6149,7 +6140,6 @@
"@loader_path/Frameworks",
);
MODULEMAP_PRIVATE_FILE = "";
OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
USE_HEADERMAP = YES;
Expand Down Expand Up @@ -6351,7 +6341,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 63AA75C51EB8B00100D153DE /* Sentry.xcconfig */;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_ASSIGN_ENUM = NO;
Expand All @@ -6377,7 +6366,6 @@
"@loader_path/Frameworks",
);
MODULEMAP_PRIVATE_FILE = "";
OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand Down
5 changes: 5 additions & 0 deletions Sources/Configuration/Sentry.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ PRODUCT_BUNDLE_IDENTIFIER = io.sentry.$(PRODUCT_MODULE_NAME)
MODULEMAP_FILE = $(SRCROOT)/Sources/Resources/$(PRODUCT_MODULE_NAME_$(CONFIGURATION)).modulemap
ARCHS = $(ARCHS_STANDARD) arm64e
ARCHS[sdk=*simulator] = $(ARCHS_STANDARD)

// APPLICATION_EXTENSION_API_ONLY YES causes a side effect of exposing all @objc classes to Sentry-Swift.h
// and without it the project wont compile.
APPLICATION_EXTENSION_API_ONLY = YES
OTHER_CFLAGS = -DCARTHAGE_$(CARTHAGE) -DAPPLICATION_EXTENSION_API_ONLY_$(APPLICATION_EXTENSION_API_ONLY)
21 changes: 21 additions & 0 deletions Sources/Sentry/Public/SentryDefines.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
#import <Foundation/Foundation.h>

// SentryDefines.h is a key header and will be checked early,
// ensuring this error appears first during the compile process.
//
// Setting APPLICATION_EXTENSION_API_ONLY to YES has a side effect of
// including all Swift classes in the `Sentry-Swift.h` header which is
// required for the SDK to work.
//
// https://github.com/getsentry/sentry-cocoa/issues/4426
//
// This mainly came up in RN SDK, because
// some libraries advice to users
// to set APPLICATION_EXTENSION_API_ONLY_NO
// for all cocoapods targets, instead of
// only to their pod.
// https://github.com/getsentry/sentry-react-native/issues/3908
#if APPLICATION_EXTENSION_API_ONLY_NO
# error "Set APPLICATION_EXTENSION_API_ONLY to YES in the Sentry build settings.\
Setting the flag to YES is required for the SDK to work.\
For more information, visit https://docs.sentry.io/platforms/apple/troubleshooting/#unknown-receiver-somereceiver-use-of-undeclared-identifier-someidentifier
#endif

#ifdef __cplusplus
# define SENTRY_EXTERN extern "C" __attribute__((visibility("default")))
#else
Expand Down

0 comments on commit 3cdbaf1

Please sign in to comment.