# Inserting gitInformation into source code?

**URL:** <https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128>\
**Category:** Using Swift\
**Tags:** packagemanager\
**Created:** [January 11, 2025, 12:51am UTC](https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128 "2025-01-11T00:51:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JetForMe](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jetforme/32/482_2.png) [@JetForMe](https://forums.swift.org/u/JetForMe)\
**Post date:** [January 11, 2025, 12:51am UTC](https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128/1 "2025-01-11T00:51:01Z")

</div>

This [post](https://forums.swift.org/t/insert-package-version-s-into-source-code/69073) 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.

---

<div class="post-metadata">

**Author:** ![sspringer](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sspringer](https://forums.swift.org/u/sspringer)\
**Post date:** [January 11, 2025, 8:41pm UTC](https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128/2 "2025-01-11T20:41:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [January 11, 2025, 11:31pm UTC](https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128/3 "2025-01-11T23:31:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sspringer](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sspringer](https://forums.swift.org/u/sspringer)\
**Post date:** [January 12, 2025, 7:21pm UTC](https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128/4 "2025-01-12T19:21:16Z")

</div>

> [@grynspan](#):
>
> Worth filing a GitHub issue.

[Done.](https://github.com/swiftlang/swift/issues/78594) (I was not sure if the issue should be for Swift or for Foundation, but certainly someone will move it if necessary.)

---

<div class="post-metadata">

**Author:** ![sspringer](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sspringer](https://forums.swift.org/u/sspringer)\
**Post date:** [September 19, 2026, 5:34am UTC](https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128/5 "2026-09-19T05:34:54Z")

</div>

The mentioned GutHub issue is untouched since its creation, so I would like revive this topic again (the topic is not too old and has very few contributors, so I think this should be OK).

I think being able to get the version of a package during compilation in an easy way could be in the interest of many. It would be nice if it could be realized.
