This post mentions a PR for Context.gitInformation, which provides information like the current git commit and tag.
I would like for my running app (a Vapor app) to be able to get at this information from when it was built (in order to show version information to the user or for support purposes). I don’t see an obvious way to do this. The best I can gather is I need a build tool plugin to generate a Swift file.
But I can't tell if there’s a way to get the git info to the plugin, or if the plugin has a simlar property.
Yes, there should be e.g. a macro #packageVersions making a (literal) map with the versions as part of the standard library. You cannot do this with your own macro that reads the Package.resolved file, because reading files is prohibited for a macro because of security reasons.
Take a look at what Swift Testing does: we create a C/C++ target, define C macros in that target that correspond to the gitInformation fields we care about, then bubble those macros up to Swift.
There's probably room here to improve the ergonomics of this structure by exposing it directly to packages' Swift sources (somehow.) Worth filing a GitHub issue.