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

Set 'ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES' to YES in Debug mode #8172

Conversation

icecrystal23
Copy link
Contributor

This works around a bug in Xcode 10 where unit test targets don't correctly embed the necessary Swift libraries into unit test targets.

@icecrystal23 icecrystal23 force-pushed the embed-swift-libs-in-debug-frameworks branch 2 times, most recently from 23bc25a to 6810804 Compare October 10, 2018 18:08
@dnkoutso
Copy link
Contributor

@amorde isn't this maybe fixed with updated xcodeproj gem settings?

@icecrystal23 icecrystal23 force-pushed the embed-swift-libs-in-debug-frameworks branch from 6810804 to d1bbbac Compare October 10, 2018 18:53
@icecrystal23
Copy link
Contributor Author

@dnkoutso Does the xcodeproj gem generate some of the build settings for CocoaPods?

@icecrystal23
Copy link
Contributor Author

I tried updating the spec submodule to fix the tests, but I think that caused other failures

@amorde
Copy link
Member

amorde commented Oct 10, 2018

hmm, the only thing that changed with my fix to Xcodeproj were Swift optimization settings, I didn't see any changes related to this

@amorde
Copy link
Member

amorde commented Oct 10, 2018

but yes @icecrystal23 Xcodeproj defines the default build settings for the different targets (ex. App, Framework, static library, watch extension, etc.)

@icecrystal23
Copy link
Contributor Author

Should I make this fix in there, then?

@amorde
Copy link
Member

amorde commented Oct 10, 2018

haven't had a chance to take a deeper look at this - what does Xcode do if you were to mimic the setup using Xcode's UI? As in creating the targets manually within Xcode

@icecrystal23
Copy link
Contributor Author

The Xcode UI does not set this setting. This is actually a workaround for a bug in Xcode 10 (I had a bug filed with Apple, and they told me to use this workaround... I'm not sure if I convinced them that it is their bug or not). It only seems to affect unit test targets. For some reason, Xcode 10 fails to recognize which Swift standard libraries are required for frameworks embedded in unit test targets.

@icecrystal23
Copy link
Contributor Author

icecrystal23 commented Oct 10, 2018

We had been working around this with a post_install hook for our projects, but then I started seeing the same unit test failure when I tried to push one of our internal CocoaPod libraries to our internal spec repo.

@amorde
Copy link
Member

amorde commented Oct 10, 2018

I see, thanks for the background info. Do you have an openradar link?

If this is a workaround for an Xcode bug I feel like it should be in CocoaPods instead of Xcodeproj but don't feel strongly either way

@installer.send(:add_target).resolved_build_setting('ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES').should == {
'Release' => nil,
'Debug' => 'YES',
'Test' => nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like Test would need the fix as well, no? is the fix only applied to Debug configurations so that it only applies to unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was only applied to Debug mostly so it doesn't affect Release mode and app size. I don't actually know what the Test configuration is typically used for; we don't use that one ourselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CocoaPods has the concept of build configurations which behave similar to the standard Debug & Release (can't seem to find any docs on it atm) so I think this would need to be applied to any Debug-like configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way to tell which configurations are supposed to behave like Debug?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the debug? method on Xcodeproj::Project::Object::XCBuildConfiguration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the implementation to use the debug? check, but it still results in Test being nil for this test

@icecrystal23
Copy link
Contributor Author

@amorde http://www.openradar.me/radar?id=4970867087900672
Apple claims it is related to mismatched Swift versions, but my sample project to them had all Swift versions set to 4. They say it works if I set the Swift versions to all 4.2; I didn't validate that case since the Pod I was testing with doesn't work with 4.2 and I didn't have time to update it to do so.

@amorde
Copy link
Member

amorde commented Oct 10, 2018

Thanks for the radar link, sounds like this is something specific about mismatched Swift versions and test bundles.

I think the change might be too broad here since it will apply to any target (not just targets which have associated test bundles). I'd like another dev to weigh in on this as I feel like I'm missing part of the picture here

@amorde
Copy link
Member

amorde commented Oct 11, 2018

Also realized this seems related: #8139

@mgrebenets
Copy link

We've got this problem and our Swift version is currently set to 4.0 for all targets.
Moving to 4.2 will take some minor effort due to all renamings in Swift, so we can't quickly verify how it works with 4.2.

@icecrystal23 icecrystal23 force-pushed the embed-swift-libs-in-debug-frameworks branch from d1bbbac to acae0ba Compare October 15, 2018 21:45
@amorde
Copy link
Member

amorde commented Oct 25, 2018

Haven't forgotten about this - if anyone needs a workaround while this is in review:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
        config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
    end
  end
end

Edit: @icecrystal23 has a more comprehensive workaround here #8139 (comment)

@lukecharman
Copy link

Has it still being forgotten about? :)

@amorde
Copy link
Member

amorde commented Nov 17, 2018

I'm hesitant to put specific workarounds like this in if it's something that Xcode will fix, especially given it's specific to certain Swift versions and its something we might have to keep around for a while or immediately remove on the next Xcode patch

@amorde
Copy link
Member

amorde commented Feb 10, 2019

Looks like this is fixed in the latest Xcode beta, so I'm going to close this. Still, thanks for the PR!

@amorde amorde closed this Feb 10, 2019
@icecrystal23
Copy link
Contributor Author

We're seeing similar issues again in Xcode 11 betas (as noted in #8139 ). The workaround is simple and only affects DEBUG builds. Can you reconsider accepting this PR?

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

Successfully merging this pull request may close these issues.

None yet

6 participants