Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project w/ 2 app targets loses linked libraries to 2nd app after Xcode modification #1017

Open
mthole opened this issue Feb 11, 2021 · 7 comments

Comments

@mthole
Copy link
Contributor

mthole commented Feb 11, 2021

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

  1. 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
  1. Open the App.xcodeproj, and examine the App1 and App2 targets. They both link to the libLibraryA.a and libLibraryB.a libraries. All is well.

image
image

  1. 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 the App1 and App2 targets.

  2. Examine the App1 and App2 targets. Notice that App2 is now missing both libLibraryA.a and libLibraryB.a. Sadface!

image
image

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.

@mthole
Copy link
Contributor Author

mthole commented Feb 11, 2021

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

@mthole
Copy link
Contributor Author

mthole commented Sep 22, 2021

Just wanted to bump this and say I've tested with XcodeGen 2.24.0, but the exact same behavior remains.

@kbhavyas
Copy link

Have you managed to solve it with projectreferences in Xcodegen 2.26.0?

@mccorkill1
Copy link

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.

@ajRiverav
Copy link

@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:

  1. using you starter project, I generated the pbxproj file using xcodegen.
  2. 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.
  3. 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.

@ajRiverav
Copy link

@mthole since you may be familiar with the generator for this file, does anything stand out?

@mthole
Copy link
Contributor Author

mthole commented Aug 7, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants