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

proposal: runtime, time: add API BuildTimestamp to report an application's build time #23175

Closed
vipally opened this issue Dec 19, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@vipally
Copy link

commented Dec 19, 2017

Use build timestamp to distinguish different version of application binary is a common way in other languages.
eg: C has macros "__DATE__" and "__TIME__" to fetch compiler time.
But golang has no way to achive this feature nowadays.
I have made a patch to provide fllow API to achive it.

runtime.BuildTimestamp defines a buildtimestamp value which will be written by linker(cmd/link).

time.BuildTime() converts runtime.BuildTimestamp() to time.Time.
The expected usage of BuildTimestamp API is as follow:

func main() {
	println("hello world!")
	println("buildtimestamp:", runtime.BuildTimestamp())
	println("buildtime     :", time.BuildTime().String())
	// Output:
	// hello world!
	// buildtimestamp: 1513671919
	// buildtime     : 2017-12-19 16:25:19 +0800 CST
}

It will be my pleasure that if go team can accept this feature in go repository.
The branch

@vipally vipally changed the title runtime/time: API runtime.BuildTimestamp required to report appication build time runtime/time: API runtime.BuildTimestamp required to report application build time Dec 19, 2017

@odeke-em odeke-em changed the title runtime/time: API runtime.BuildTimestamp required to report application build time proposal: runtime, time: add API BuildTimestamp to report an application's build time Dec 19, 2017

@gopherbot gopherbot added this to the Proposal milestone Dec 19, 2017

@gopherbot gopherbot added the Proposal label Dec 19, 2017

@bontibon

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2017

This proposal conflicts with #16860.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2017

If you want this, use the linker's -X option. We are not going to do this by default, as producing bit-identical binaries for bit-identical inputs is a goal. It would also prevent caching of go build results for main packages. Closing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.