I have been looking into fixing issues such as https://bugs.swift.org/browse/SR-12758, which was an unintended side effect of a bugfix that required a new compiler flag to be passed when building a package.
The current version of the proposed fix is at https://github.com/apple/swift-package-manager/pull/2844. Since this is a general class of problem, and since there are some trade-offs in this specific case, I wanted to see if anyone has opinions about the nature of the proposed fix (or a better idea for how to address this type of problem).
Every Swift package specifies a
swift-tools-version that tells Swift Package Manager what version of the PackageDescription API to use when parsing the manifest. This allows older packages to continue working even when API changes are introduced in new versions of SwiftPM. The tools version also affects the semantics used when interpreting the file system layout of the package.
Until now, the tools version has not affected the compiler or linker flags that are passed during a build. But in order to fix https://bugs.swift.org/browse/SR-12758, and possibly in future cases, I think it would make sense to take the declared tools version into account when new build flags are added that change the semantics even for older packages.
Complicating this particular situation is that the original change went into SwiftPM 5.2, so it's been in use for a while. Since the flag is being passed unconditionally, this caused some older packages to no longer build with SwiftPM 5.2 and later. But if passing this flag is now made conditional on tools-version 5.2 or newer, it's possible that it might break some newer packages that specify a pre-5.2 tools-version but that rely on the 5.2 behavior (these packages could be fixed by specifying a 5.2 tools-version, however).
So: does anyone object to the general idea of conditionalizing build flags on the tools version as needed in order to preserve older package semantics? And does anyone have a better idea about how to address the specific issue of https://bugs.swift.org/browse/SR-12758 without risking breaking any newer packages that rely on post-5.2 behavior for this flag but that specify a pre-5.1 tools version?