Skip to content

Enhancement: set a string variable at build time (similar to go ld's -X flag) #19084

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

Closed
imbaczek opened this issue Nov 18, 2014 · 2 comments
Closed

Comments

@imbaczek
Copy link

Would it be possible to add functionality like go ld has? (Or maybe it's already possible and my google-fu fails me...?) This would be quite useful in Makefiles, build recipes, etc.

-X symbol value
    Set the value of an otherwise uninitialized string variable.
    The symbol name should be of the form importpath.name,
    as displayed in the symbol table printed by "go tool nm".

http://golang.org/cmd/ld/

Example usage: http://stackoverflow.com/a/11355611/38749

go build -ldflags "-X main.minversion `date -u +.%Y%m%d%.H%M%S`" service.go

main.minversion gets set to the build date and time.

@sfackler
Copy link
Member

You can do this via environment variables and the env! macro:

static VERSION: &'static str = env!("VERSION");
env VERSION="1.0.32" rustc lib.rs

@steveklabnik
Copy link
Member

Yes, you can. Giving this a close.

lnicola pushed a commit to lnicola/rust that referenced this issue Feb 10, 2025
Split cache priming into distinct phases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants