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

swift: Fix compilation error when dependency adds the macOS SDK in the include dirs #13376

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

thewildtree
Copy link
Contributor

SwiftPM issue with more context: swiftlang/swift-package-manager#6439

Some dependencies can bring include paths pointing to older macOS SDK's. In this case, it was libffi pointing to SDK from 12.0. When the Foundation framework is imported in Swift, swiftc attempts to import the FFI module from the most recent version of the SDK, which causes a compilation error because of conflicting definitions between the two SDK versions.

It would error out like so:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/module.modulemap:1171:1: note: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/module.modulemap:1171:
extern module FFI "ffi/module.modulemap"
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/ffi/module.modulemap:1:8: error: redefinition of module 'FFI'
module FFI [system] {
       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/ffi/module.modulemap:1:8: note: previously defined here
module FFI [system] [extern_c] {
       ^
ninja: build stopped: subcommand failed.

I decided to do exactly what SwiftPM did: swiftlang/swift-package-manager#6772. Let's just naively look for .sdk paths in the compile args of our dependencies and replace them with the most recent one. I saw SwiftPM also patching linking arguments, but in my experience the include dirs are enough to get rid of the issue, and I couldn't replicate a scenario where linking would also be broken, so I'd rather not touch it without testing.

It's done in a very rudimentary way but works. Let me know if something fancier is needed, with proper regex or something. :)

I included a test which is confirmed to fail without the workaround added in this patch. This was not tested on anything else than macOS, but I don't expect it to make the situation worse on iOS and other darwin subplatforms.

@thewildtree thewildtree force-pushed the swift-sdk-duplicate branch from 7125cb1 to 1db8b36 Compare July 1, 2024 17:07
@nirbheek nirbheek added OS:macos Issues specific to Apple Operating Systems like MacOS and iOS pkgconfig language:swift labels Jul 1, 2024
Some dependencies can bring include paths pointing to older macOS SDK's.
In this case, it was libffi pointing to SDK from 12.0. When the
Foundation
framework is imported in Swift, swiftc attempts to import the FFI module
from the most recent version of the SDK, which causes a compilation
error
because of conflicting definitions between the two SDK versions.

SwiftPM also had this problem:
swiftlang/swift-package-manager#6772

The solution on our side is a simplified version of what SwiftPM did.
Let's naively look for .sdk paths in the compile args of our
dependencies
and replace them with the most recent one.

I included a test which is confirmed to fail without the workaround
added in this patch. This was not tested on anything else than macOS,
but I don't expect it to make the situation worse in any case.
@jpakkane
Copy link
Member

Lint failure is unrelated.

@jpakkane jpakkane merged commit 0158410 into mesonbuild:master Jan 29, 2025
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language:swift OS:macos Issues specific to Apple Operating Systems like MacOS and iOS pkgconfig
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants