Xcode 13 App + command line tool problems

I am attempting to add a command-line tool I wrote to bundle into a macOS app's Resources folder but I can't seem to get everything working together quite right.

Initially I added the command line tool as an additional target in the macOS app Xcode project. This worked well for development, but when I archived the built app, I no longer had the normal app distribution options because the archive included the command-line tool product.

So I thought "no problem, I really want this tool separated out as its own project anyway" so I created a swift package with an executable target. I was able to add the package to my app project, and select it as a build dependency, but I could not select the executable target in the Copy Bundle Resources or Copy Files build phase. When I manually added the executable built from the swift package, I could no longer notarize the app because the tool wasn't built with hardened runtime.

So I created a new command-line tool Xcode project, copied the files, and added the project to the main app's workspace. I can select the subproject's target as a dependency. I could not select anything from that subproject for the Copy Bundle Resources phase, but I was able to select the target when I added a Copy Files build phase. However, what gets archived is both the app and a separate copy of the command line tool, so in the Organizer I don't have the option to "Distribute App".

For now I manually added the built command line tool to the app project. This sucks but less than having to dig up a notarization script and updating it to handle manual notarization. But it this seems like something Xcode should handle properly so I must be missing something.

Jim

So I finally settled on using a swift package to handle the command line tool project, which I added to the main app project using the package dependencies. This package executable product could be set as a dependency, and I added a run script build phase to sign the tool and embed it in the main app's Resources folder.

The SPM executable product needs to be signed with --options=runtime to be embedded in a notarized macOS app. The script is pretty simple:

#!/bin/bash
devID="Developer ID Application: Me Myself (ASDF1234)"
toolPath="${BUILT_PRODUCTS_DIR}/MyTool"
codesign --force --options=runtime --sign "${devID}" "${toolPath}"
cp "${toolPath}" "${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/Resources"

Xcode 13 App + command line tool problems
 
 
Q