Getting Swift version information to the driver, multiple tools

I'm looking to display the Swift version number (e.g. x.y.z) in the driver's help "intro" text that I recently landed. If Swift was built from source, I'd also like to display something that indicates that, such as 6.0 (development) or 6.0 (beta).

As I understand it, the compiler parses its version via a preprocessor string configured at build time. I also understand that this information also typically comes through CMake builds and not one-off or SPM builds.

The driver has its own versioning from what I can tell. Does it know what the overall Swift version is?

What would be a good way for the driver to be able to understand or at least print the same version string that the compiler itself understands? What about other projects in the toolchain?

To recap:

  1. I'd like the following information be available to the driver:
  • Swift major, minor, and patch version
  • What kind of build it is
  1. This information ideally should be available regardless of how it was built.

  2. Ideally this information would be available uniformly to all tools in the toolchain.

  3. Not looking to change how the compiler prints its version information. All of that useful hash information is good for debugging.

  4. The driver should continue to print its local, precise versioning, including Git hashes if appropriate, when its --version flag is on.

Thoughts?

The driver has its own versioning from what I can tell. Does it know what the overall Swift version is?

Assuming you're talking about the new driver written in Swift, not the old C++ one, no, it does not appear to. I was surprised to find that swift --version -v does not invoke the new Swift driver for the version.

What would be a good way for the driver to be able to understand or at least print the same version string that the compiler itself understands? What about other projects in the toolchain?

The compiler has a flag for precisely this, -print-target-info, which produces a JSON string that includes the compiler version. SPM already uses it when building packages to determine the host triple (run swift build -v to see it invoked), and the SPM build script uses it for some info too.

Since you're not likely to build swift-driver with a different compiler version, you could modify the swift-driver build script to get this info from the compiler you're building with, same for other toolchain projects. I think this fulfils all your requirements.