11

I have an SPM project that I need to test with xcodebuild (because it has iOS resources such as XIBs). This project also supports Cocoapods so it also has .xcodeproj and .xcworkspace files.

Normally xcodebuild will automatically detect the Package.swift file and use that to build, but now it detects the Cocoapods workspace and tries to go from that instead.

I read through the documentation for xcodebuild, but couldn't find a flag to explicitly point it to the Package.swift.

Is there any equivalent to the --project or --workspace flag that I can use to tell xcodebuild to use the Package.swift file and ignore the project and workspace?

4
  • did you find a solution to this? Commented Dec 21, 2020 at 2:30
  • I ended up calling swift package generate-xcodeproj --output ./tmp to generate an Xcode project in a subdirectory first. Then I call xcodebuild build -project ./tmp/[project].xcodeproj to build the SPM specific project. Commented Dec 23, 2020 at 17:12
  • 1
    Update: Turns out that generating an xcodeproj also didn't work, because that doesn't support resources. Final solution I settled on was just to move the CocoPods project and workspace to a subfolder. Commented Jan 8, 2021 at 7:08
  • Its been a while, but wondering if anyone knows whether this is still the case? I'm trying to extend some existing build scripting that runs in a different directory than where the code lives. Today, that works just fine for projects and workspaces because you can pass the full path in, but SPM packages don't appear to support that in any way Commented Mar 25, 2022 at 18:46

2 Answers 2

7

To use xcodebuild with Swift Package Manager, you specify the scheme name: xcodebuild -scheme [SchemeName].

If there is a conflict with Cocoapods, I suggest you change the scheme names to be unique.

Sign up to request clarification or add additional context in comments.

Comments

1

As swift package generate-xcodeproj has been deprecated, the instruction to build the Swift package via command line is as follows:

  1. Determine the valid scheme from your package directory using xcodebuild -list
$xcodebuild -list | grep -A100 Schemes
    Schemes:
        MySwiftPackage
  1. Build the package using xcodebuild build -scheme <SCHEME> -sdk <SDK> -destination <DESTINATION>
#iOS
$xcodebuild build -scheme MySwiftPackage -sdk iphonesimulator16.0 macosx -destination -destination "OS=16.0,name=iPhone 13 Pro"

#Mac Catalyst
$xcodebuild build -scheme MySwiftPackage -sdk macosx -destination "generic/platform=macOS,variant=Mac Catalyst,name=Any Mac"

You can find other destination strings here.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.