swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.72k stars 1.34k forks source link

Swift 5.9 tools uses watchOS 5 instead of 4 by default #6974

Closed ffried closed 1 month ago

ffried commented 1 year ago

Description

A package (e.g. pkg1) that does not define any platforms seems to be using watchOS 5 instead of 4. If another package (e.g. pkg2) depends on that package, but explicitly defines watchOS 4 as minimum supported version, it will fail to build.

Using Xcode 15 / Swift 5.9, the minimum supported watchOS version is 4 (according to the release notes):

image

Expected behavior

The second package builds fine.

Actual behavior

The build fails with the following error:

The package product 'Package1' requires minimum platform version 5.0 for the watchOS platform, but this target supports 4.0

Steps to reproduce

  1. Create a package named e.g. pkg1 with a target and product Package1 but no platforms specified.
  2. Create another package named pkg2 with a target Package2.
  3. Set platforms of pkg2 to [.watchOS(.v4)].
  4. Add pkg1 as dependency of pkg2, as well as the product Package1 as a dependency of target Package2.
  5. Build for watchOS

Swift Package Manager version/commit hash

Whatever is bundled with Swift 5.9 in Xcode 15.0

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
Target: arm64-apple-macosx14.0
Darwin Florians-MacBook-Pro.local 23.0.0 Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:43 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T6000 arm64
neonichu commented 12 months ago

I am able to reproduce. Not sure yet where the 5.0 comes from, this looks correct: https://github.com/apple/swift-package-manager/blob/main/Sources/PackageModel/Platform.swift#L44C5-L44C99

ffried commented 12 months ago

@neonichu thanks for confirming. Is there a way to build for watchOS using SPM alone (not using Xcode)? I've skimmed through the SPM source code as well and was unable to spot an obvious mistake Which is why I first hesitated to create an issue here. It could also be Xcode's fault, right?

neonichu commented 12 months ago

Yah, it doesn't seem to reproduce when doing that, so it's somewhat likely that the issue lies in Xcode, but it's not 100% clear to me.

What you can do is:

❯ cat destination.json 
{
    "version": 1,
    "sdk": "/Applications/Best.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS11.0.sdk",
    "toolchain-bin-dir": "/Applications/Best.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin",
    "target": "arm64-apple-watchos4.0",
    "extra-cc-flags": [],
    "extra-cpp-flags": [],
    "extra-swiftc-flags": [],
}
❯ swift build --destination destination.json
ffried commented 12 months ago

For the record, I've just filed this as a feedback as well: FB13239890

jakepetroules commented 5 months ago

This technically behaves correctly. The iOS minimum version is 12, which maps to watchOS 5. So in the absence of any explicitly specified versions, SwiftPM defaults to iOS 12, which in turn defaults to watchOS 5.

The watchOS minimum version happens to be 4, but because of iOS's higher minimum, it defaults to 5.

ffried commented 1 month ago

@jakepetroules Thanks for the explanation! And sorry for the late reply - totally went under the radar on my side.

I'm a bit torn between seeing the link between iOS and watchOS on the one hand, but still wondering whether this actually makes sense on the other hand. If I created a watchOS only package (w/o currently being able to specify this in the Package manifest), I'd probably expect the default version to be the minimum - just like it would be for e.g. macOS or iOS.

Either way, I'll close this as "Won't fix".