swiftlang / swift-package-manager

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

[SR-13761] Swift Package Manager requires macOS version from Linux only dependency #4484

Open adam-fowler opened 3 years ago

adam-fowler commented 3 years ago
Previous ID SR-13761
Radar rdar://problem/70543422
Original Reporter @adam-fowler
Type Bug
Environment Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1) Target: x86_64-apple-darwin19.6.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 7f4e55b02e396816b5cbe9a36104fbea

Issue Description:

If a swift package includes a dependency that has a condition to be Linux only the platform requirements of that dependent package are still applied to other platforms.

The following Package.swift contains a dependency on apple/swift-crypto but only for Linux.

// swift-tools-version:5.3

import PackageDescription

let package = Package(
    name: "swift-5.3-deps",
    products: [
        .library(name: "swift-5.3-deps", targets: ["swift-5.3-deps"]),
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-crypto.git", from: "1.0.0"),
    ],
    targets: [
        .target(
            name: "swift-5.3-deps",
            dependencies: [.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux]))]),
    ]
)

When I run `swift build` I get the following error even though I am not linking swift-crypto into the macOS version of my library.

error: the library 'swift-5.3-deps' requires macos 10.10, but depends on the product 'Crypto' which requires macos 10.15; consider changing the library 'swift-5.3-deps' to require macos 10.15 or later, or the product 'Crypto' to require macos 10.10 or earlier.
typesanitizer commented 3 years ago

@swift-ci create

neonichu commented 3 years ago

This could be a quirk of the fact that the dependency is still present and not conditional, plus the fact that the minimum deployment target is a package-level property. But needs more investigation.

adam-fowler commented 3 years ago

Interestingly Xcode doesn't complain about this.

adam-fowler commented 3 years ago

Do you think this is something that is going to be resolved soon? I was hoping to replace an if statement at the end of my Package.swift https://github.com/soto-project/soto-core/blob/main/Package.swift with the new .when(platforms: [.linux]) before doing a new major release of Soto. But this issue means I can't.