apple / swift-migration-guide

Apache License 2.0
296 stars 22 forks source link

SwiftPM package does not build in Swift 6 mode from Xcode 16? #113

Closed vanvoorden closed 4 months ago

vanvoorden commented 4 months ago

I originally ran into this trying to repro a compiler error in Swift 6 mode.^1

According to the migration guide:

A Package.swift file that uses swift-tools-version of 6.0 will enable the Swift 6 language mode for all targets. You can still set the language mode for the package as a whole using the swiftLanguageVersions property of Package.

I created a sample SwiftPM executable package:

// swift-tools-version: 6.0

import PackageDescription

let package = Package(
  name: "MyExecutable",
  platforms: [
    .macOS(
      .v14
    )
  ],
  targets: [
    .executableTarget(
      name: "MyExecutable"
    ),
  ]
)

Since this package requires 6.0… my thinking is that this should build in Swift 6 mode. It seems like this does build in Swift 6 mode from command line. Building from Xcode_16_beta_2 does not build in Swift 6 mode unless I explicitly opt in to Swift 6 mode:

// swift-tools-version: 6.0

import PackageDescription

let package = Package(
  name: "MyExecutable",
  platforms: [
    .macOS(
      .v14
    )
  ],
  targets: [
    .executableTarget(
      name: "MyExecutable",
      swiftSettings: [
        .swiftLanguageVersion(.v6)
      ]
    ),
  ]
)

Now I see the compiler error from Xcode.

Is this expected behavior? If engineers build (and run) packages from Xcode my thinking is we can communicate in the Migration Guide that package might not build in Swift 6 mode like they might expect it to.

mattmassicotte commented 4 months ago

This is, unforutnately, a known issue with Xcode 16 😕 But I really hesitate to modify the guide to highlight this...

vanvoorden commented 4 months ago

This is, unforutnately, a known issue with Xcode 16

Hmm… interesting. So the understanding is this is a bug and the expectation is (we hope) this is fixed before 6.0 goes live in Q3?

The legit workaround (for now) is to explicitly select 6 mode in each package? Correct?

mattmassicotte commented 4 months ago

Hmm… interesting. So the understanding is this is a bug and the expectation is (we hope) this is fixed before 6.0 goes live in Q3?

Yeah 😅 But if it turns out this is the intended behavior, we'll definitely update the guide.

The legit workaround (for now) is to explicitly select 6 mode in each package? Correct?

Yes, that's what I've been doing. It don't think this comes with any downsides.

mattmassicotte commented 4 months ago

I just realized this is a duplicate of https://github.com/apple/swift-migration-guide/issues/84