Skip to content

Binary Versioning #1370

@0pcom

Description

@0pcom

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) with go list ; example:

$ go list -m -json github.com/cogentcore/core@main

{
	"Path": "github.com/cogentcore/core",
	"Version": "v0.3.8-0.20241213221857-7f699071cef2",
	"Query": "main",
	"Time": "2024-12-13T22:18:57Z",
	"GoMod": "/home/user/go/pkg/mod/cache/download/github.com/cogentcore/core/@v/v0.3.8-0.20241213221857-7f699071cef2.mod",
	"GoVersion": "1.22",
	"Origin": {
		"VCS": "git",
		"URL": "https://github.com/cogentcore/core",
		"Hash": "7f699071cef2f7365f35c8b470e4066a8ce3b0cc"
	}
}

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 like core.go in the root of this repository where that can be set.

So, for instance, instead of:

go install cogentcore.org/cmd/core@main

one might run

go install -ldflags=" -X github.com/cogentcore/core.buildInfo=$(go list -m -json github.com/cogentcore/core@main)" cogentcore.org/cmd/core@main

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 to unknown 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedThis feature request will be implementedenhancementA new feature request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions