Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a macro to read the package versions #78594

Open
stefanspringer1 opened this issue Jan 12, 2025 · 0 comments
Open

Add a macro to read the package versions #78594

stefanspringer1 opened this issue Jan 12, 2025 · 0 comments
Labels
feature A feature request or implementation triage needed This issue needs more specific labels

Comments

@stefanspringer1
Copy link

stefanspringer1 commented Jan 12, 2025

Motivation

In many circumstances, you might want an executable to know about the package version(s) that was used, so the program can give according infos to the user of the program e.g. in case of an error. This should be possible also for programs being distributed as one single executable file. Because this seems to a common issue, an easy to use solution should exist.

Proposed solution

From https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128:

… there should be e.g. a macro #packageVersions making a (literal) map with the versions as part of the standard library. …

Alternatives considered

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. Same issue when calling Git.

From https://forums.swift.org/t/inserting-gitinformation-into-source-code/77128:

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.

But this is complicated.

Additional information

No response

@stefanspringer1 stefanspringer1 added feature A feature request or implementation triage needed This issue needs more specific labels labels Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant