Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
kateinoigakukun opened this issue Sep 18, 2024 · 9 comments
Open
1 task done

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

kateinoigakukun opened this issue Sep 18, 2024 · 9 comments
Labels

Comments

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Sep 18, 2024

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

@kateinoigakukun
Copy link
Member Author

I'd like to hear @MaxDesiatov's opinion here 🙏

@dschaefer2
Copy link
Member

I only have a higher level comment for now. This is a confusing area with Swift SDKs I stumbled on early. It feels like Swift SDKs should be versioned like Packages are and you should be able to specify what SDKs you depend on with version constraints. I'd like to see the two concepts come together, maybe where SDKs are define in Packages, for example.

But much more study is needed to understand the full side effects of that. And does that even help solve the problem you are having here?

@kateinoigakukun
Copy link
Member Author

I'm not sure if a package should declare SDK dependencies because a package itself does not depend on a SDK and builder developers do. And this problem is not related to SDK version management, but the structure of SDK identification.

However, I totally agree that we need to re-organize concepts around Swift SDK. I'll post several concerns of the current Swift SDK design later separately anyway.

@dschaefer2
Copy link
Member

However, I totally agree that we need to re-organize concepts around Swift SDK. I'll post several concerns of the current Swift SDK design later separately anyway.

Awesome. Thanks!

@finagolfin
Copy link
Member

I repeatedly hammered on exactly this issue during the review of that proposal, but for whatever reason, Max refused to address it.

@stevapple
Copy link
Contributor

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.

I would like to go one step further in this way: if only one SDK is capable for the specified --triple, swift build should use it without requiring --swift-sdk. This makes SDK selection fully deterministic by --triple and --swift-sdk, and allows omitting either of them if there's no ambiguity.

@MaxDesiatov
Copy link
Contributor

I would like to go one step further in this way: if only one SDK is capable for the specified --triple, swift build should use it without requiring --swift-sdk. This makes SDK selection fully deterministic by --triple and --swift-sdk, and allows omitting either of them if there's no ambiguity.

That one's already tracked as #7330

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Sep 23, 2024

Currently, --swift-sdk and --triple are both specified, --triple option is preferred, and --swift-sdk is just ignored.

IMO, it's a bug. We should implement option 1 (i.e. not ignore --swift-sdk), unless there are known important cases where this would be a harmful regression and/or egregiously breaking change.

@dschaefer2
Copy link
Member

The problem is that if you take this out further and we'll have multiple Linux SDKs for cross compilation, they'll all have the same triple. We need a way to identify which Linux/SDK you're trying to target.

I also think there's a mix of requirements here. A lot of packages are cross platform and can build with any SDK. I do think we need to also allow for package targets that only support a subset of SDKs, to take advantage of special capabilities they may have for example. This will be especially important as we add in support for embedded. We should at least allow for targets to be constrained to a specific set of SDKs.

I'd also love if we were able to put together a strong ecosystem of SDKs that could be managed by package registries, for example. And at that point we'll need it to be easy for users to select which SDKs they want to target and "everything just works" ™️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants