diff --git a/CHANGELOG.md b/CHANGELOG.md index 1917eb784b3..d0dd335680e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Sentry.podspec b/Sentry.podspec index 5de0712a748..d550d86a319 100644 --- a/Sentry.podspec +++ b/Sentry.podspec @@ -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' diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 60898b55ea9..fad17aaa0dd 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -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; @@ -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; @@ -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; @@ -5388,7 +5385,6 @@ "@loader_path/Frameworks", ); MODULEMAP_PRIVATE_FILE = ""; - OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -6149,7 +6140,6 @@ "@loader_path/Frameworks", ); MODULEMAP_PRIVATE_FILE = ""; - OTHER_CFLAGS = "-DCARTHAGE_$(CARTHAGE)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; USE_HEADERMAP = YES; @@ -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; @@ -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; diff --git a/Sources/Configuration/Sentry.xcconfig b/Sources/Configuration/Sentry.xcconfig index 5bda006b0a1..f4e5181152f 100644 --- a/Sources/Configuration/Sentry.xcconfig +++ b/Sources/Configuration/Sentry.xcconfig @@ -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) diff --git a/Sources/Sentry/Public/SentryDefines.h b/Sources/Sentry/Public/SentryDefines.h index a6e9e6be2a8..3634ebc8aba 100644 --- a/Sources/Sentry/Public/SentryDefines.h +++ b/Sources/Sentry/Public/SentryDefines.h @@ -1,5 +1,26 @@ #import +// 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