Is it possible to codesign CLI applications as part of `swift run`?

I’m trying to work on a CLI which uses various macOS entitlements for OS APIs. Is it possible to integrate the codesign CLI into the Swift PM build process such that “it just works” when I’m using swift run or swift build?

Not sure about the Swift PM part, but directly creating a CLI app from an Xcode project will not give you access to macOS entitlements.

Things may have have changed since then, but according to my last encounter with this, you would need to create a GUI app, strip away all the GUI related bits and add your own main function.

Yes, it looks as if you have to use an Xcode project, not SwiftPM.

You can use xcodebuild from the command line, but you’ll need Xcode installed.

Yes, on Apple platform in fact Apple signs your executable, not you. but the code signing certificate (issued by Apple) is present somewhere in your Xcode, so PM in theory could use that to codesign the executable. But then if you distribute your executable outside the AppStore, you also need notarization from Apple, and this cannot be done in a simple batch processing.

On Windows you need a code signing certificate issued by a trusted certificate authority to add an Authenticode signature to your .exe or .dll file, and in theory PM could do that.

Not sure how it works on Linux.

Entitlements... These are specific for Apple platform and I don't think it will be possible to manage these via Package Manager, even in the future.

I wouldn’t make predictions about the future :). But, I don’t think it’s on anyone’s plans right now.

1 Like