Skip to content

Add support for using ldflags when building binary #28

@montanaflynn

Description

@montanaflynn

Prerequisites

  • I searched to see if the issue already exists.

Description

It would be quite useful to be able to add some 'ldflags` when building the binary. For example I usually add a version and commit hash variable to my programs which is updated when building rather than in the code. This is extremely useful for debugging.

An example of using ldflags to set the commit global variable:

go build -ldflags "-X github.com/a/b/main.commit=$(git rev-parse --short HEAD)" .

Other tools like goreleaser also set some flags by default and allow you to customize them as I do with my notify-cli tool. This makes it so when I run notify --version from a binary generated with goreleaser I get the following:

$ notify --version
Version: v0.0.8
Commit: a8982ead528a717a05415f5cef7d7448f5adc968

But with a binary from gobinaries:

$ notify --version
Version: unknown
Commit: unknown

I wonder if adding a config file like .gobinaries.yml with the flags you want to set would be something you would welcome, if so I could help with a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions