apple/swift-protobuf

Mark SwiftProtobuf as safe for use in application extensions (set Require Only App-Extension-Safe API to YES)

Closed this issue · 3 comments

tkafka commented

I am using SwiftProtobuf in a custom framework (for sharing app code among app targets) that is marked with Require Only App-Extension-Safe API = YES, so that I can use it in WidgetKit and Notification app extensions.

During build, I am getting this warning about SwiftProtobuf not being marked as Require Only App-Extension-Safe API = YES (which forces compile time checks to make sure the library isn't touching eg. UIApplication and other objects which aren't available in app extensions).

Can this flag be added to SwiftProtobuf? I believe it isn't using any of the app objects anyway.

Thanks for consideration!

Please be sure to include:

  • what OS you are developing on (Linux or macOS, including the version): 13.4.1
  • for macOS, what version of Xcode you are using (xcodebuild -version): 15.0 beta 2
  • what version of Swift is your code set to compile with (i.e. from project
    settings, etc.): 5.9
  • what branch/tag of SwiftProtobuf you are using (1.0.0, etc.): 1.22.0 release
  • if you are getting compile errors, please be sure include all errors/warnings,
    sometimes the error before the one you are stuck on is important.:
Linking against a dylib which is not safe for use in application extensions: (path hidden)/Library/Developer/Xcode/DerivedData/AppName-eksxezdcznqhaibhzaurdwsgkvku/Build/Products/Debug-iphonesimulator/PackageFrameworks/SwiftProtobuf_7CEE9AB92C12BC6B_PackageProduct.framework/SwiftProtobuf_7CEE9AB92C12BC6B_PackageProduct
Lukasa commented

I do not believe that SwiftPM enables setting this flag.

It might make sense to ask how to enable this with SwiftPM dependencies in the Apple developer forums or something like that since it is more a tooling question not specific to any one library.

tkafka commented

I have done some research, and adding this to the targets should work (and causes no build issues), according to https://stackoverflow.com/a/75928528/38729

swiftSettings: [
	/// giving you a nice red compile error in Xcode on the spot if you try to use some unsafe API
	.unsafeFlags(["-Xfrontend", "-application-extension"])
],
linkerSettings: [
	/// tells the linker 'this is an extension safe package' so you won't get warnings if you link the package to an extension target or another framework that is extension safe
	.unsafeFlags(["-Xlinker", "-application_extension"])
]