Building Swift Package Manager project with xcodebuild, how to ignore xcodeproj and xcworkspace?
Asked Answered
B

2

10

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?

Buckles answered 26/10, 2020 at 15:49 Comment(4)
did you find a solution to this?Donnie
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.Buckles
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.Buckles
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 wayShugart
I
6

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.

Incomprehensive answered 16/1, 2021 at 21:44 Comment(0)
M
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.

Mathamathe answered 26/9, 2023 at 14:16 Comment(1)
#60245659Uncap

© 2022 - 2025 — McMap. All rights reserved.