Skip to content

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

@imbaczek

Description

@imbaczek

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions