How do I add swift-argument-parser to a command line target on an existing Xcode project?

I am trying to add a Mac command line tool target to an existing SwiftUI project, and use the swift-argument-parser framework in that command line tool.

I get build errors after adding the swift-argument-parser to my project.

Here are the minimum reproducible example steps that trigger this problem:

  1. Create new Multiplatform app “Test”
  2. File>New>Target macOS command line tool named “TestCmd”
  3. Select Scheme “TestCmd” and verify that it runs successfully.
  4. Select TestCmd target
  5. File>Add Package dependencies>swift-argument-parser Add both ArgumentParser and generate-manual packages to TestCmd target
  6. Run from TestCmd scheme.

This yields a whole stream of errors:

Library not loaded: @rpath/ArgumentParser.framework/Versions/A/ArgumentParser

Reason: tried: ‘/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/ArgumentParser.framework/Versions/A/ArgumentParser' (no such file), ‘/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (code signature in <9CBB1F37-8A3F-32FC-9744-3108CEF0D6A5> ‘/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (code signature in <9CBB1F37-8A3F-32FC-9744-3108CEF0D6A5> '/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/System/Volumes/Preboot/Cryptexes/OS/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (no such file), '/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (code signature in <9CBB1F37-8A3F-32FC-9744-3108CEF0D6A5> '/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/System/Volumes/Preboot/Cryptexes/OS~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (no such file)

Searching on the string "not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs" yields some posts about signing a Mac product for distribution on Apple's developer forums.

I will eventually want to code sign the command line tool target so I can share it/distribute it on the App Store, but for now, I just want to develop the @#$@#$ command locally.

Question: How do I add the swift-argument-parser SPM package to my nascent command line tool so I can start writing my command?

I can upload the above minimum project to GitHub if it would be helpful, but it takes less than a minute to reproduce the errors above.

(I'm using Xcode 15.0, running on an M2 Mac with macOS Sonoma 14.0, if that matters.)

Post not yet marked as solved Up vote post of Duncan C Down vote post of Duncan C
500 views

Replies

I'm having precisely the same problem. Will let you know if I make any progress. The issue seems to be related to code signatures. The error message shows that Xcode found @rpath/ArgumentParser.framework/Versions/A/ArgumentParser (@rpath in this case points to the Debug directory of my app) but finds it with a signature other than mine. Well, of course that will be true; I didn't sign the package because someone else wrote it.

What happens if you disable Hardened Runtime in your project?

  • Well, disabling it solved my problem and reenabling it does not crash the app...

Add a Comment

Hi Thanks for the helpful comment about hardened runtime. this worked for me so I tried turning back on all the bits of hardened runtime and then turning them off one by one

The actual bit of hardened runtime that you need to disable in Xcode is Disable Library Validation This says it "allows an application to load plug ins or frameworks signed by other developers" which seems to make sense.

This is so crazy. Is it normal to have the "Disable Library Validation" option turned on? Is it best practice? It's the only way I can get my little CLI app to build after I included swift-argument-parser.

Seems like there's some incongruity with the security policy and with using SPM. I certainly don't want to hate developing on Apple's platforms, but everything that has happened since the Swift announcement, every year, there's more and more little paper cuts you have to dance around in order for things to just get out of your way so you can do some actual thinking and building. I really, truly, do not want to have such a negative attitude, but I'm sitting here wondering how this is even an oversight. I'm sitting here wondering if I should be building this as a web app just to avoid this mess.

In any case, checking that option to on allows the cli app to build and run.