Description
Is it reproducible with SwiftPM command-line tools: swift build
, swift test
, swift package
etc?
- Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands,
swift build
,swift test
,swift package
etc.
Description
I'm trying to build a library package for iOS. Building static library works fine, but dynamic library is linked incorrectly: linker uses macOS SDK instead of iOS SDK. Object files are compiled correctly though. The issue manifests regardless of device or simulator build.
It seems that the --sysroot
flag passed to the linker is related. If I replace it with -isysroot
in manual invocation, the lib is linked correctly.
So far I wasn't able to find a workaround, things I've tried:
-Xlinker -isysroot -Xlinker "$(xcrun --sdk iphoneos --show-sdk-path)"
-Xlinker -syslibroot -Xlinker "$(xcrun --sdk iphoneos --show-sdk-path)"
-Xlinker -platform_version -Xlinker ios -Xlinker 12.0 -Xlinker $(xcrun --sdk iphoneos --show-sdk-version)
-Xswiftc "-sdk" -Xswiftc "$(xcrun --sdk iphoneos --show-sdk-path)" -Xswiftc "-target" -Xswiftc "arm64-apple-ios12.0" -Xcc "-isysroot" -Xcc "$(xcrun --sdk iphoneos --show-sdk-path)" -Xcc "-target" -Xcc "arm64-apple-ios12.0"
(took from Packages that depends on binary targets cannot be build with iOS/iOS Simulator SDKs #6571)
Expected behavior
iOS SDK is passed to the linker invocation, the dynamic library contains correct values when checked with otool
/ vtool
Actual behavior
linker prints warning:
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone' [-Wincompatible-sysroot]
and the sdk
field in vtool
output prints macOS SDK version, not the iOS SDK.
Steps to reproduce
the simplest test project:
public func f() {
print("hello")
}
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "Hello",
products: [
.library(
name: "Hello",
type: .dynamic,
targets: ["Hello"]),
],
targets: [
.target(
name: "Hello",
path: "."),
]
)
Build:
swift build --triple arm64-apple-ios12.0 --sdk "$(xcrun --sdk iphoneos --show-sdk-path)" --product Hello -v
Click to expand log
Building for debugging...
Write auxiliary file /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/swift-version-5BDAB9E9C0126B9D.txt
Write auxiliary file /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/sources
/Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -module-name Hello -emit-dependencies -emit-module -emit-module-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules/Hello.swiftmodule -output-file-map /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/output-file-map.json -parse-as-library -incremental -c @/Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/sources -I /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules -target arm64-apple-ios12.0 -v -enable-batch-mode -index-store-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/index/store -Onone -enable-testing -j6 -DSWIFT_PACKAGE -DDEBUG -module-cache-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/ModuleCache -parseable-output -parse-as-library -emit-objc-header -emit-objc-header-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/Hello-Swift.h -color-diagnostics -swift-version 6 -sdk /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -F /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -L /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -g -Xcc -isysroot -Xcc /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -Xcc -F -Xcc /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -package-name test_spm
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-ios12.0
/Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/kambala/dev/ios/test-spm/Hello.swift -target arm64-apple-ios12.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -I /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules -I /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/kambala/dev/ios/test-spm -Xcc -isysroot -Xcc /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -Xcc -F -Xcc /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name Hello -package-name test_spm -disable-clang-spi -target-sdk-version 18.2 -target-sdk-name iphoneos18.2 -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -emit-module-doc-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules/Hello.swiftdoc -emit-module-source-info-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules/Hello.swiftsourceinfo -emit-objc-header-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/Hello-Swift.h -emit-dependencies-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/Hello.emit-module.d -parse-as-library -o /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules/Hello.swiftmodule -emit-abi-descriptor-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules/Hello.abi.json
/Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/kambala/dev/ios/test-spm/Hello.swift -emit-dependencies-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/Hello.d -emit-reference-dependencies-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/Hello.swiftdeps -target arm64-apple-ios12.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -I /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules -I /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/kambala/dev/ios/test-spm -Xcc -isysroot -Xcc /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -Xcc -F -Xcc /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -Xcc -fPIC -Xcc -g -module-name Hello -package-name test_spm -disable-clang-spi -target-sdk-version 18.2 -target-sdk-name iphoneos18.2 -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -parse-as-library -o /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/Hello.swift.o -index-store-path /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/index/store -index-system-modules
Write auxiliary file /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.product/Objects.LinkFileList
/Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -v -L /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug -o /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/libHello.dylib -module-name Hello -emit-library -Xlinker -install_name -Xlinker @rpath/libHello.dylib -Xlinker -rpath -Xlinker @loader_path @/Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.product/Objects.LinkFileList -target arm64-apple-ios12.0 -Xlinker -add_ast_path -Xlinker /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules/Hello.swiftmodule -sdk /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk -F /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -L /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -g
Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-ios12.0
/Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -dynamiclib /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Hello.build/Hello.swift.o -F /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks --sysroot /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk --target=arm64-apple-ios12.0 -force_load /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCompatibility50.a -force_load /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCompatibility51.a -force_load /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCompatibilityConcurrency.a -force_load /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCompatibility56.a /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCompatibilityPacks.a -L /Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk/usr/lib/swift -rpath /usr/lib/swift -L /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug -L /Applications/Xcode-16.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -Xlinker -install_name -Xlinker @rpath/libHello.dylib -Xlinker -rpath -Xlinker @loader_path -Xlinker -add_ast_path -Xlinker /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/Modules/Hello.swiftmodule -o /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/libHello.dylib
clang: warning: using sysroot for 'MacOSX' but targeting 'iPhone' [-Wincompatible-sysroot]
/Applications/Xcode-16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/libHello.dylib -o /Users/kambala/dev/ios/test-spm/.build/arm64-apple-ios/debug/libHello.dylib.dSYM
Build of product 'Hello' complete! (1.30s)
Swift Package Manager version/commit hash
6.0.3, 6.1.0, 6.2.0-dev (from Xcode 16.2, 16.4 and 26b2 respectively)
Swift & OS version (output of swift --version ; uname -a
)
swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: x86_64-apple-macosx14.0
Darwin kambala-mini.local 23.6.0 Darwin Kernel Version 23.6.0: Thu Mar 6 21:58:03 PST 2025; root:xnu-10063.141.1.704.6~1/RELEASE_X86_64 x86_64
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
Darwin Filipenkov-mb.local 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64
swift-driver version: 1.127.5.3 Apple Swift version 6.2 (swiftlang-6.2.0.10.950 clang-1700.3.10.950)
Target: arm64-apple-macosx15.0
Darwin Filipenkov-mb.local 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64