Skip to content

[PackageModel] Toolchain: A few fixes for features supported by Swift compiler #8761

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

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 3, 2025

Motivation:

  • Fix "supported features" parsing with older toolchains. -print-supported-features flag used to output "enabled_in" version as an integer (major only).
  • Handle absence of optional features section. JSON.get would throw if the key couldn't be found, let's handle that gracefully for an optional "optional features" section.

Modifications:

  • Update Toolchain.swiftCompilerSupportedFeatures to use try? when querying JSON for an optional "optional" key.
  • Update Toolchain.swiftCompilerSupportedFeatures to attempt to retrieve "enabled_in" key as a String first and if that fails - as an integer.

Result:

swift package migrate can now support older toolchains that have "enabled_in" printed as an integer and have no "optional features" section in their -print-supported-features output.

xedin added 2 commits June 3, 2025 15:51
…nteger

Older versions of `-print-supported-features` emitted `enabled_in`
field as an integer (major compiler version only), newer ones emit
it as a string to support major+minor.
… section

`JSON.get` would throw if the key couldn't be found, let's handle
that gracefully for an optional "optional features" section.
@xedin
Copy link
Contributor Author

xedin commented Jun 3, 2025

@swift-ci please test

@xedin xedin merged commit 985b56f into swiftlang:main Jun 4, 2025
6 checks passed
xedin added a commit that referenced this pull request Jun 4, 2025
…Swift compiler (#8762)

- Explanation:
 
   `swift package migrate` is broken when used with older toolchains.

- Fix "supported features" parsing with older toolchains.
`-print-supported-features` flag used to output "enabled_in" version as
an integer (major only).
- Handle absence of optional features section. `JSON.get` would throw if
the key couldn't be found, let's handle that gracefully for an optional
"optional features" section.

- Main Branch PR:
#8761

- Risk: Low (only `swift package migrate` is affected by this changes).

- Resolves: rdar://152533205

- Reviewed By: @dschaefer2 

- Testing: Updated existing tests in the suite, added new test-cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants