-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Binary Versioning #1370
Comments
Thank you for filing this issue. We have wanted to do something like this for a while, and in fact we have this logic already for building apps with the core tool: https://github.com/cogentcore/core/blob/7f69907/cmd/core/config/config.go#L256. If you right click in a Cogent Core app built with the core tool and then click However, we have not yet implemented such a version storage system for the core tool itself, since as you noted, doing so using the same approach would require a much longer install command that injects the version. Although that might be fine for a package manager that automatically executes that command, I would much rather avoid users having to deal with that verbosity. That being said, I saw in the Go 1.24 draft release notes that the main module's version will now be available at runtime, which would allow us to directly get the version without having to deal with any linker flag injection. However, Go 1.24 does not come out until February, and we are unlikely to update immediately, especially given that we are hoping to use gopherjs at some point, which is several versions behind (see #974). Regardless, once we do update to 1.24, we will definitely replace our existing linker flag usage with that functionality, and we will update to use it in the core tool itself to resolve this issue. In the meantime, I tried adding a build vcs=git
build vcs.revision=55e6ea8edc4efa83958bc52a6c54600bf7dac0e9
build vcs.time=2024-12-15T22:56:39Z
build vcs.modified=true However, I am not sure if that information will be there if the core tool is installed using |
Unfortunately, it does not appear to have those Regardless, I filed #1376 as a draft, so you can look at that and experiment with it if you want. It doesn't hurt to have this logic implemented in cli for when you are building from inside the repository, and as a backup for when you build an app without the core tool. Note that the use case for building an app is more sound for this, since you do typically do that from inside a repository, but the formatting is worse than that of the core tool linker flags, so we will only use that as a backup for now with the core tool linker flags still the main implementation. |
We did not mean to close this issue. We merged #1376 as it is helpful in some cases and doesn't hurt as mentioned above. However, it does not provide a full solution to the issue of getting the version of the core tool when installing it from outside the git repository. One option for getting this to work is to make If you are interested in that solution or have any other ideas, please let me know. Once we decide on a solution, you could submit a PR if you want, or I could implement it. |
Thanks for pointing that out about the draft release notes for go v1.24; I will need to keep that in mind. I generally have an aversion to update logic in binaries ; simply because I've seen this implemented in a very wrong way in the past. And if you are going to execute some For your purposes, since versioning isn't critical, perhaps waiting until the next go version would be better. For my purposes of versioning package-based installations, it should simply be possible to parse the output of I think my https://github.com/skycoin/skywire/blob/develop/pkg/skywire-utilities/pkg/buildinfo/buildinfo.go basically just set the version on compile - the formula for which is included in the comments there - and then add a flag to print the version and if desired print it in the help menu by default; ex.: https://github.com/skycoin/skywire/blob/develop/cmd/skycoin-skywire/commands/root.go#L86 on the verbosity - it really could be worse.
But the most important point is that versioning like this is totally optional. people can still install it with just go install without versioning it, and the version will just print as |
Okay, it seems reasonable to add that functionality as an optional feature that people can specify if they need. It is fine to wait for full support until Go 1.24, as getting the version is not that critical except in certain use cases, where you can use this optional feature. If you are interested in implementing this, a PR would be great, or I could implement it if you prefer. I think this should be added into package Also, if possible, it would be better to use |
I attempted to implement this but it's proving a bit challenging to test it, I think because the variable I'm setting with the version only exists on my fork..
I dare not change the go.mod for testing purposes if this would become a PR ; Here's a slimmed down version of the earlier implementation
and the changes to cli/usage
It's really not critical, for me, that this be implemented. More just a suggestion of an improvement. The next go release is not far away, which should basically enable automatically versioning this ; so do with it as you will. |
Thank you for the update. That looks like the right logic, so you are welcome to file that as a PR if you are interested, and if I look it over and it seems good, we could merge it and then test it on main to overcome the module issues (it wouldn't break anything, so it should be fine). On the other hand, if you don't need this functionality, I would also be perfectly fine just waiting for Go 1.24; your choice based on how much you need this. |
Describe the feature
I notice that the
core
binary does not have the version compiled into it.This begs the question: when did I build this binary and is this the latest version? There is no way to tell.
So I propose a simple method which I've recently devised to compile the version into the binary.
Relevant code
it's possible to get the informaton regarding the latest commits to a branch of this repo (for example
main
) withgo list
; example:The above should be executed in a subshell to set a variable at compile time via
-ldflags= -X ...
- in a library to be created. This can be, for instance pkg/buildinfo or, I might even suggest putting a file likecore.go
in the root of this repository where that can be set.So, for instance, instead of:
one might run
and there should perhaps be some init function to parse the version and commit out of the json set in that variable at compile time.
then cmd/core would just import "github.com/cogentcore/core" or "cogentcore.org/core" and then add a
-v --version
flag to the command line interface to print the version. And printing the version in the--help
menu by default never hurts either. And it will still work without setting the version, just default tounknown
version if the variable was not set on compilation....
I may submit this as a PR - if it would help. I thought of this for another project for which the versioning is more critical a concern ; so i'll be implementing it there already.
The text was updated successfully, but these errors were encountered: