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

Patch *.sdk paths from pkgConfig files to the current SDK #6772

Merged
merged 6 commits into from Oct 4, 2023

Conversation

fwcd
Copy link
Contributor

@fwcd fwcd commented Aug 2, 2023

This fixes #6439 by replacing all *.sdk paths obtained from pkgConfigs with the current SDK.

Motivation:

Using Homebrew-packaged libraries such as Cairo in a system library target on macOS currently causes build failures if the user compiles the Swift package with an Xcode toolchain (see swift-systemlib-demo and its CI builds for a minimal example), the build output often looks similar to this:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/ffi/module.modulemap:1:8: error: redefinition of module 'FFI'
module FFI [system] [extern_c] {
       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ffi/module.modulemap:1:8: note: previously defined here
module FFI [system] [extern_c] {

The problem is that Homebrew's pre-compiled libraries sometimes bake the Command Line Tools-paths (/Library/Developer/CommandLineTools/SDKs/...) into their pkgConfig files, which can clash with the current SDK's headers.

See #6439 for details.

Modifications:

As per @neonichu's suggestion in #6439 (comment), this patches the include (-I) and library (-L) paths parsed from pkgConfig files by replacing any *.sdk path with the current SDK.

Thus a flag such as

-I/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/usr/include/ffi

would be mapped to

-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk

when compiling with the macOS 13.3 SDK.

Result:

The swift-systemlib-demo package now compiles on macOS.

@MaxDesiatov
Copy link
Member

@fwcd sorry about the delay with the review, would you mind resolving the conflicts?

@fwcd
Copy link
Contributor Author

fwcd commented Oct 4, 2023

Sure, I've rebased it onto main!

@MaxDesiatov
Copy link
Member

@swift-ci test

@MaxDesiatov
Copy link
Member

@swift-ci test windows

@MaxDesiatov MaxDesiatov enabled auto-merge (squash) October 4, 2023 19:04
@MaxDesiatov
Copy link
Member

@swift-ci test windows

@MaxDesiatov MaxDesiatov merged commit 058574d into apple:main Oct 4, 2023
5 checks passed
@fwcd fwcd deleted the patch-pkgconfig-sdk-path branch October 4, 2023 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants