Skip to content

--swift-sdk option cannot uniquely select a Swift SDK #7973

@kateinoigakukun

Description

@kateinoigakukun

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

A Swift SDK can be identified by a combination of an artifact ID and a target triple by its definition. However, the current Swift SDK selector accepted by the --swift-sdk flag only allows specifying either an artifact ID or a target triple, making it impossible to uniquely select the desired Swift SDK in the following situation:

A developer installs two Artifacts containing two Swift SDKs with target triples A and B respectively:

~/.config/swiftpm/swift-sdks
├── swift-DEVELOPMENT-SNAPSHOT-2024-06-13-a_static-linux-0.0.1.artifactbundle
│   └── swift-DEVELOPMENT-SNAPSHOT-2024-06-13-a_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk
│       ├── aarch64
│       └── x86_64
└── swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1.artifactbundle
    └── swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk
        ├── aarch64
        └── x86_64

Then there are 4 Swift SDKs for:

  • Swift SDK A: swift-DEVELOPMENT-SNAPSHOT-2024-06-13-a_static-linux-0.0.1 (target: aarch64-swift-linux-musl)
  • Swift SDK B: swift-DEVELOPMENT-SNAPSHOT-2024-06-13-a_static-linux-0.0.1 (target: x86_64-swift-linux-musl)
  • Swift SDK C: swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1 (target: aarch64-swift-linux-musl)
  • Swift SDK D: swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1 (target: x86_64-swift-linux-musl)

If a developer specifies swift build --swift-sdk x86_64-swift-linux-musl, there are two candidates (Swift SDK B and D)
If a developer specifies swift build --swift-sdk swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1, there are still two candidates (Swift SDK C and D)

Potential Solutions

I think we have two options to allow a developer to specify the combination of an Artifact ID and a target triple:

  1. Use value specified by --triple option if specified with --swift-sdk (Currently, --swift-sdk and --triple are both specified, --triple option is preferred, and --swift-sdk is just ignored.)
    • Pros: No new option
    • Cons: It's a little bit confusing because --swift-sdk does not identify a Swift SDK but just identify an Artifact containing Swift SDKs.
  2. Extend the Swift SDK selector expression to allow specifying the both. e.g. --swift-sdk swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a_static-linux-0.0.1:x86_64-swift-linux-musl
    • Pros: --swift-sdk identifies a Swift SDK clearly
    • Cons: As we don't limit the character set of an artifact ID, so not sure if we can interpret the selector expression without ambiguity
  3. Assign Swift SDK ID to each SDK that are independent from artifact ID
  4. Restrict an artifact to have only a single Swift SDK

Swift Package Manager version/commit hash

da65429

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions