swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

API for getting the full Swift version (as reported by `swift --version`) #75998

Open grynspan opened 3 weeks ago

grynspan commented 3 weeks ago

Motivation

Swift Testing needs to be able to report the full Swift version (as reported by swift --version) for diagnostic purposes, e.g. when reading logs produced by a CI job or another engineer or in a different configuration. This version information is immensely useful when filing bug reports because it allows us to immediately see "oh, it was the [e.g.] August 9th nightly main-branch toolchain where the bug occurred" and so on.

Proposed solution

I'd like to propose we add API to the Swift standard library that vends a "human-readable" string equivalent to the aforementioned one. Something like this would be sufficient:

/// The human-readable version of the standard library.
///
/// Rabble rabble details details nuances nuances.
public var standardLibraryVersion: String { get }

Alternatives considered

Additional information

No response

grynspan commented 3 weeks ago

Also, Swift Package Manager could adopt the same API so that it doesn't need to fake it for subcommands like swift test --version (which produce very different strings.)

hassila commented 3 weeks ago

This would also be great of benchmarks to print out, we got this issue filed that we can't currently nicely solve without proper API:

https://github.com/ordo-one/package-benchmark/issues/213

JaapWijnen commented 3 weeks ago

Wouldn't it also be nice if this was available at compile time somehow? To be used in compiler directives like #if perhaps?

grynspan commented 3 weeks ago

That would be feasible if it were exposed as a string literal macro, I think.