Search code examples
swiftxcodeazure-devopsopenapiopenapi-generator

Commandline build failed for swift-openapi-generator - Both Locally and on Azure DevOps Pipeline


I am usig Azure DevOps Pipeline to build my Xcode project where I am facing this problem. Xcode version in use is 15.0.1

I have followed the official tutorial here to setup swift-openapi-generator in our project, and it has worked fine when run from within Xcode. Xcode builds the models and client just as it should. However it fails on command line when I run:

xcodebuild -sdk iphoneos -configuration Release -workspace /Users/zeeshan/Development/MyProjext/myproject.xcodeproj/project.xcworkspace -scheme elvis -destination platform=iOS Simulator,name=MyiPhone,OS=17.0.1 build CODE_SIGNING_ALLOWED=NO with error as in the screenshot below.

enter image description here

This command line is what we have been using for a while on our Azure DevOps Pipeline for CI so we know the command line works. It started failing only after swift-openapi-generator was added as per its official tutorial.

There is no documentation about this error message, and the only couple of sources online which somewhat point to the issue, ask to remove _OpenAPIGeneratorCore from the Build Phase Link with Binary settings, but this is not the case since _OpenAPIGeneratorCore was never there in the Link with Binary.

Error message in the log says: error: _OpenAPIGeneratorCore is only to be used by swift-openapi-generator itself—your target should not link this library or the command line tool directly.

I didn't link my target to _OpenAPIGeneratorCore, unless Xcode did it automatically in which case I don't see where to unlink it.

I have tried everything and nothing has worked. Seems like the command line build needs to have an option to trust and enable the swift-openapi-generator library, and I don't know how to accomplish this. Has anyone else encountered this issue and found a solution?

Attached screenshots from the project:

enter image description here enter image description here enter image description here


Solution

  • So after many trial and errors, I figured out that the solution to this problem was to have in the Target Build Settings the Base SDK and Supported Platforms set to iOS only and not to both macOS and iOS. I tested this by creating two brand new projects with following the swift-openapi-generator totorial for each of them to make sure this is true for both the new projects. As soon as you add macOS, which is added by default by Xcode 15 for a new project, the commandline build starts to fail.

    The default: enter image description here

    The fix: enter image description here

    This change accordingly updates the project.pbxproj file to reflect these changes and this results the command line build work fine both locally and in Azure DevOps Pipeline.

    enter image description here