-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
ClangImporter looks in the wrong path for the libc and new C++ module maps when -sdk
is specified
#74696
Comments
The C++ module maps are not compiler resources, but are part of the Swift SDK ("Platform Swift Modules"). They are auxiliary content that is overlaid on the Platform SDK. We wouldn't want to treat this as a compiler resource as we would be unable to release a SDK update to fix modularisation issues without re-rolling the full compiler. The C++ modulemaps should be pulled from |
I'm not an expert in Android, so I'm not sure what is the right solution here. The Cxx and CxxStdlib modules were intentionally moved out of the SDK and into the Swift toolchain, because they are version-locked to the Swift compiler. Those modules are evolving quickly along with the compiler support for C++ interoperability, and are tightly integrated with the compiler logic that auto-conforms certain C++ types to Swift protocols like |
@egorzhdan right, there's no ABI stability currently for that module. But the final place once that is achieved would be the SDK. The module maps however do not have any real association with the compiler version. Those are associated with the platform and being provided by Swift, seems proper to be in the Swift SDK. |
@compnerd, that's fine if you make that change once you start changing what We can switch to your compatibility path plan later, whenever you make those changes to the meaning of
@egorzhdan, this bug has nothing to do with Android- as I stated above, "there was nothing specific to Android here"- so my repro command and output above is on Fedora linux compiling natively for linux x86_64, while this C++ shim module map appears to be used on Darwin also. To explain the problem succinctly without all the repro detail above, non-Darwin platforms generally do not have full SDKs, ie a path containing both the C/C++ headers and Swift modules, so one specifies both However, some linux distros and the Termux app do provide Swift toolchain packages, so in that case, they do have a full SDK, but often with older Swift modules and runtime libraries. In such a scenario, care must be taken to always give Similarly, the As for the separate issue of whether these C++ module maps don't belong in the platform SDK "because they are version-locked to the Swift compiler," the Swift modules are also version-locked to a Swift version and are in the platform SDK, so I agree with @compnerd that I don't think that is the main distinction. @etcwilde, perhaps you'd like to chime in. |
@compnerd Yeap, that is right. Eventually we would move Cxx and CxxStdlib to the SDK. |
@finagolfin Not quite, you can build a top-of-tree Swift compiler and use it with an SDK from Xcode. This wouldn't be possible with the Cxx and CxxStdlib modules.
That sounds reasonable to me. |
…-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.
OK, the Swift 5.10.1 compiler finally shipped as part of Fedora 40, so here's the repro command and same build error I saw in Termux on there, after installing the system Swift package with I downloaded the latest trunk snapshot toolchain and patched the stdlib CMake config, to work around a bug with building a standalone stdlib:
Finally, running this
My compiler fix in #74814 got this same file building again on Android, and should do the same on Fedora and other platforms. |
-sdk
is specified, possibly the libc module map also-sdk
is specified
-sdk
is specified-sdk
is specified
…-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.
…-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.
…-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 #74696.
Description
I was just building the latest June 13 trunk source snapshot natively on Android in the Termux app, when I ran into a compilation error while trying to build
CxxStdlib
for the first time, which was only recently enabled for Android too, 273edcf.For some background, the Termux app has an Android C/C++ sysroot installed at
/data/data/com.termux/files/
, ie C/C++ header files are found in/data/data/com.termux/files/usr/include/
, and I have a Swift 5.10.1 toolchain installed there too, so the Swift modules can also be found in/data/data/com.termux/files/usr/lib/swift/android/
. This constitutes a full Swift 5.10.1 SDK, as the C/C++ headers/libraries and Swift modules/libraries are all together in a single sysroot.Well, this caused problems, as the build of the trunk 6.1 Swift toolchain was picking up the wrong
libcxxshim.modulemap
, ie the one from the full Swift 5.10.1 SDK not the newly generated one inbuild/Ninja-Release/swift-android-aarch64/
, which caused a compilation error as one of those shim headers was recently updated. I worked around this bug by removing that C++ interop module map from the 5.10.1 SDK.Since there was nothing specific to Android here, I just tried to reproduce this issue in Fedora 40 x86_64. However, it turns out Fedora 40 is still installing Swift 5.8.1 in the system, so I could not reproduce, as
libcxxshim.modulemap
was installed inusr/lib/swift/linux/x86_64/
back then while a more recent 5.10 toolchain looks inusr/lib/swift/linux/
for that C++ module map:So I simply moved those shims over to test for this bug,
mv /usr/lib/swift/linux/x86_64/lib* /usr/lib/swift/linux/
, and found that I could reproduce on linux also:Note the wrong 5.8.1 C++ module map used in the above output from the 5.10.1 repro command below,
-fmodule-map-file=/usr/lib/swift/linux/libcxxshim.modulemap
, despite the frontend explicitly specifying the right resource directory,-resource-dir /home/finagolfin/swift-5.10.1-RELEASE-fedora39/usr/lib/swift
.I just checked and the Fedora system package was finally updated to 5.10.1 last week, with the Fedora 40 build currently undergoing testing before deployment, so this bug will start hitting Fedora installs soon. It only happens when the
-sdk /
flag is explicitly passed in, which SwiftPM doesn't appear to for normal package builds, but the new SDK bundles and building a new stdlib as part of a fresh toolchain build do pass in. @tachoknight, perhaps you can run the repro command below on Fedora 41 with your new 5.10.1 package installed and confirm.The issue is the
getActualModuleMap()
function in ClangImporter, which first looks in-sdk
for these module maps, then in-resource-dir
. That is not the precedence used everywhere else in the compiler, ie-resource-dir
is always given precedence normally.With more distros starting to package Swift in the system and SDK bundles starting to be used, this bug will start hitting more people.
Reproduction
Only the
-cxx-interoperability-mode=default -sdk /
flags and an installed system toolchain are required, the other flags simply dump verbose output to show what's going on.Expected behavior
-resource-dir
is always given precedence in the compiler for other files, but not for these module maps. The compiler might also be using the wrongglibc.modulemap
andlibstdcxx.modulemap
, but it simply does not dump those paths in the verbose output. Whatever happens with this bug, the compiler should be modified to dump those paths in verbose mode, so we can easily check them.Environment
I tested with Swift 5.10, but the code goes back to 5.8.
Additional information
I should also note that a new cross-compilation model is planned. In that new scenario, it depends if these module maps are considered compiler resources or "Platform Swift Modules." If the former, they should then only be looked for in
-resource-dir
at that point, and if the latter, only in-sdk
, ie not looked for in both asgetActualModuleMap()
currently does.Pinging @zoecarver, who originally wrote this code in #59754 years ago, and @egorzhdan, who subsequently moved some of it around. @compnerd may want to chime in on whether these C++ module maps are compiler resources and how they should be handled under his new cross-compilation model.
The text was updated successfully, but these errors were encountered: