summaryrefslogtreecommitdiff
path: root/test cases/swift
diff options
context:
space:
mode:
authorPiotr BrzeziƄski <piotr@centricular.com>2024-07-01 18:55:13 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2025-01-29 22:46:34 +0200
commit01584101b7e66c37fa5963eb7d7057e3301ea06e (patch)
treead06c1bd912f9b5a09ae0e1ae0b505763edfade6 /test cases/swift
parentae1bb2f87b88a66591a152038f4271b83d575a92 (diff)
downloadmeson-01584101b7e66c37fa5963eb7d7057e3301ea06e.tar.gz
swift: Fix duplicate SDK include paths causing a compile error
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: https://github.com/swiftlang/swift-package-manager/pull/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.
Diffstat (limited to 'test cases/swift')
-rw-r--r--test cases/swift/9 sdk path from dep/foo.swift4
-rw-r--r--test cases/swift/9 sdk path from dep/meson.build12
2 files changed, 16 insertions, 0 deletions
diff --git a/test cases/swift/9 sdk path from dep/foo.swift b/test cases/swift/9 sdk path from dep/foo.swift
new file mode 100644
index 000000000..6ca38879f
--- /dev/null
+++ b/test cases/swift/9 sdk path from dep/foo.swift
@@ -0,0 +1,4 @@
+// This import is needed for swiftc to implictly import the FFI module
+// which will in turn conflict with the dependency's include path and error out
+// if we don't manually replace all SDK paths with the newest one.
+import Foundation
diff --git a/test cases/swift/9 sdk path from dep/meson.build b/test cases/swift/9 sdk path from dep/meson.build
new file mode 100644
index 000000000..4cc44bc72
--- /dev/null
+++ b/test cases/swift/9 sdk path from dep/meson.build
@@ -0,0 +1,12 @@
+project('swift sdk include dir test', 'swift')
+
+bar_dep = declare_dependency(
+ # Simulates including 'libffi' from brew as a dep via pkg-config
+ # Without a workaround that replaces all SDK paths with the most recent one,
+ # a compile error will occur due to conflicting definitions of the FFI module.
+ compile_args: '-I/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/ffi',
+)
+
+foo = static_library('foo', 'foo.swift',
+ dependencies: [bar_dep],
+)