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

[6.0][ClangImporter] Make sure the -resource-dir is checked before the -sdk, as done everywhere else in the compiler #76199

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

finagolfin
Copy link
Member

@finagolfin finagolfin commented Sep 1, 2024

Explanation: The frontend currently looks in -sdk for a C/C++ sysroot and -resource-dir for Swift modules, with the former implicitly set to / and the latter always explicitly passed in by swift-driver. However, a "full SDK" contains both C/C++ headers and Swift modules, so in that case and if -sdk is explicitly passed in, this ClangImporter was looking in the full SDK first and wrongly using those Swift module maps, rather than the ones in -resource-dir.

Scope: When does that actually happen? Suppose you have Swift 5.10 installed in the system and are trying to build Swift 6.0 from source. In that scenario, the CMake config explicitly passes -sdk / and the Swift 6 compiler wrongly uses the old Swift 5.10 C and C++ module maps and fails. This could also affect some SDK bundles, say if one linux distro triple's Swift modules are placed in the common SDK itself, while others are put in separate -resource-dir paths, since compiling SDK bundles passes in an explicit -sdk.

It does not affect simply building Swift packages with a local SwiftPM 6.0 while the implicit system SDK path of / has a system Swift 5.10 installed, as no explicit -sdk is passed to build those packages.

Issue: #74696

Original PRs: #74814 and #76119

Risk: Low, since this only affects the few listed scenarios where the -sdk flag is explicitly passed to the compiler

Testing: Passed all CI on trunk and my and others' testing locally. @compnerd did report an issue with his new Android SDK with an earlier version of this patch, so I'll wait on his further testing and approval before asking to merge this.

Reviewer: @egorzhdan

…-sdk`, as done everywhere else in the compiler

Otherwise, these module maps can be pulled from a system SDK instead when
building a fresh Swift stdlib, fixes swiftlang#74696.
…dir` before `-sdk`, as changed in swiftlang#74814

Also, dump the module map paths when `-Xfrontend -dump-clang-diagnostics` is
passed in, both so we can check that manually and in these tests, and fix
another Frontend test to be more specific now that this other output trips it up.
@finagolfin finagolfin requested a review from a team as a code owner September 1, 2024 05:13
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Sep 2, 2024
Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

This might be a breaking change for certain setups, I don't think we can land this kind of change in a bugfix release.

@finagolfin
Copy link
Member Author

This might be a breaking change for certain setups

Such as?

I don't think we can land this kind of change in a bugfix release.

Ideally, we'd get it into Swift 6.0.0 also, once it's accepted into this branch.

@DougGregor
Copy link
Member

This might be a breaking change for certain setups

Such as?

I think the answer is that we don't know, but past experience has shown that changing search paths can break configurations that we hadn't heard about.

This does look like the right set of changes to make, but I'm somewhat concerned that the issue @compnerd hit with #74814 isn't known to be resolved.

@finagolfin
Copy link
Member Author

finagolfin commented Sep 3, 2024

I think the answer is that we don't know, but past experience has shown that changing search paths can break configurations that we hadn't heard about.

OK, I looked into it and Saleem added this first SDK lookup five years ago in 370aa9d, precisely to look for these module maps in full SDKs that are causing the problems now. I think this was to paper over the frontend not looking for Swift modules in full SDKs altogether, as I reported earlier this year in swiftlang/swift-driver#1562, and @artemcm's Frontend pull for that is how it should've been fixed instead.

I don't think most compilation scenarios set the -sdk flag, as I noted in the writeup about Risk, so the only question is whether this is worth fixing for the niche scenarios I listed where the current lookup order is broken despite the potential unknown niche scenarios that depend on the current lookup order.

I'm somewhat concerned that the issue @compnerd hit with #74814 isn't known to be resolved.

That was with an earlier version of this patch, but since this merged version was made available a couple weeks ago, their CI has been broken or they have been traveling, so we have not received any notice on this patch.

I suspect this patch works fine, but as I said above, I'm still waiting on them to verify.

@finagolfin
Copy link
Member Author

@shahmishal, we're going on three weeks with no response here, can we get this in? I suspect the reason Saleem had an issue with an earlier version of this patch is that I made a mistake initially, which Egor then found and we corrected.

This has been in trunk for a month now without any reported issues and distros like Fedora have to pull it in for their 6.0 build.

@DougGregor
Copy link
Member

@swift-ci please test

@finagolfin
Copy link
Member Author

Ping @shahmishal or @DougGregor, this passed the 6.0 CI, just need a decision now.

@finagolfin
Copy link
Member Author

Ping, this has been in trunk for four months now and in the downstream 6.0 release of Fedora for the last month: I think we have a pretty good body of evidence that it is unlikely to break anything.

@finagolfin
Copy link
Member Author

Ping @DougGregor, with the next patch release coming up, can you make a decision on this? I consider this a small fix for more advanced build scenarios, but I leave it up to you release managers if it's worth backporting.

@timothyklim
Copy link

timothyklim commented Nov 25, 2024

Suppose you have Swift 5.10 installed in the system and are trying to build Swift 6.0 from source. In that scenario, the CMake config explicitly passes -sdk / and #74696 (comment)

This bug caused me a lot of hours to be able to make a build for NixOS

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Yeah, we should take this. Thank you!

@DougGregor DougGregor merged commit 5aec83c into swiftlang:release/6.0 Dec 2, 2024
5 checks passed
@finagolfin finagolfin deleted the release/6.0 branch December 2, 2024 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants