XcodeGen
XcodeGen copied to clipboard
Project w/ 2 app targets loses linked libraries to 2nd app after Xcode modification
I have a moderately complex XcodeGen set up involving multiple internal libraries/frameworks and produces multiple application targets. It works great, until you try to modify the project in Xcode (e.g. by adding a new file). Xcode then ends up stripping the libraries from all but the first application target(!)
Simplified Reproduction
I've created a simplified example project to illustrate the issue: XcodeGenBugExample.zip
- Download the .zip, use
make
to run xcodegen on the 3 included projects
➜ XcodeGenBugExample
make
⚙️ Generating plists...
⚙️ Generating project...
⚙️ Writing project...
Created project at /Users/mthole/XcodeGenTest/LibraryA/LibraryA.xcodeproj
⚙️ Generating plists...
⚙️ Generating project...
⚙️ Writing project...
Created project at /Users/mthole/XcodeGenTest/LibraryB/LibraryB.xcodeproj
⚙️ Generating plists...
⚙️ Generating project...
⚙️ Writing project...
Created project at /Users/mthole/XcodeGenTest/App/App.xcodeproj
- Open the App.xcodeproj, and examine the
App1
andApp2
targets. They both link to thelibLibraryA.a
andlibLibraryB.a
libraries. All is well.
-
Go and add a new .swift file to the App target. (Or do a number of other Xcode operations that trigger whatever re-evaluation is happening...). I added
File.swift
to theApp1
andApp2
targets. -
Examine the
App1
andApp2
targets. Notice thatApp2
is now missing bothlibLibraryA.a
andlibLibraryB.a
. Sadface!
We expect App1 and App2 to still be linked to both libraries. Mysteriously, only App1 is!?
Next Steps
I've been using Xcode 12.4. If anyone has any ideas, I'm happy to help investigate further here.
This seems to be related to projectReferences
. If I smash everything into a single .xcodeproj, I cannot reproduce this. (That's not a tenable workaround for my real life use case, unfortunately.)
e.g. a project defined like this behaves as expected
name: App
options:
minimumXcodeGenVersion: 2.18
xcodeVersion: 12.4
deploymentTarget:
iOS: 13.0
targets:
App1:
type: application
platform: iOS
sources:
- path: App.swift
dependencies:
- target: LibraryA
- target: LibraryB
App2:
type: application
platform: iOS
sources:
- path: App.swift
dependencies:
- target: LibraryA
- target: LibraryB
LibraryA:
type: library.static
platform: iOS
sources:
- path: ../LibraryA
LibraryB:
type: library.static
platform: iOS
sources:
- path: ../LibraryB
Just wanted to bump this and say I've tested with XcodeGen 2.24.0, but the exact same behavior remains.
Have you managed to solve it with projectreferences in Xcodegen 2.26.0?
I also want to bump this. I have a similar project structure and am seeing the same behavior described in this issue. I'm running Xcode 14.2 and Xcodegen 2.35.0.
@mthole I am investigating this. Unfortunately, I am not familiar -yet- with Xcodegen's source code. I did try a sort of brute force approach to understanding the issue.
I performed several tests to that effect and this one stands out:
- using you starter project, I generated the pbxproj file using xcodegen.
- I removed and added back the two libs in BUILD PHASES' section "Link Binary with Libraries" for target APP2. I did nothing else. This resulted in Xcode modifying the pbxproj.
- I added a new file. This resulted in no lost references. This tells me that something about that pbxproj is causing Xcode to not strip the libraries references.
Here is a patch that shows the changes made by Xcode in step 2.
The next step would be to identify what is wrong in the xcodegen-generated pbxproj.
@mthole since you may be familiar with the generator for this file, does anything stand out?
@mthole since you may be familiar with the generator for this file, does anything stand out?
Sorry, nothing jumps out immediately. I've lost most of the context I had here back in 2021.