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

Cannot use ldflags to set build-time go variables #356

Open
andytynan opened this issue Jun 29, 2024 · 0 comments
Open

Cannot use ldflags to set build-time go variables #356

andytynan opened this issue Jun 29, 2024 · 0 comments

Comments

@andytynan
Copy link

Desired behaviour

When building a go module, it is useful to have a version string "burned" into the binary.
In go, this is accomplished by using the go tool link option -X, via the go build option -ldflags.
E.g.: go build -ldflags="-X BUILD_VERSION=${VERSION}"
That command tells the linker to use the value in the bash variable VERSION as the initial value for the go variable BUILD_VERSION.

Current behaviour

Although the -ldflags line is used internally in the gopy code, and passed to the go build command, it is hard-coded to set just the -s and -w options, based on the gopy option --symbols.

args = append(args, "-ldflags=-s -w")

Possible solution

Add a new gopy build option --ldflags that would pass its value on to go build.
The -w and -s flags could be de-duplicated if the gopy --symbols is set, and those flags were also included in the --ldflags value.

Development

I plan to fork the project and fix this for my own requirements shortly, and would be grateful if a contributor could revierw the change once tested, and see whether they consider it a useful enhancement, to be merged into the main project.

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

1 participant