Skip to content

Enhancement: Add -gcflags option for statically compiling binary #518

Description

@Bertie690

Describe the feature
Currently, there is an -ldflags argument that passes arguments directly to go build during compilation. This would aim to add a parallel for the gcflags build flags setting as well.

What problem does this feature address?
While there are probably other uses out there that I don't know about, the once instance of this that stands out to me is removing compiler optimizations from built code for debugging. Currently, trying to launch a compiled magefile binary using dlv results in often subpar information due to compiler optimizations, and the means of removing said optimizations require passing gcflags arguments.

Additional context
While a separate flag could be made to disable compiler optimizations, this would be a more general-purpose solution.
Another option would be adding a general "build" flag that passes on its arguments directly to go build, though that might pose backwards compatibility issues.

For the record, the debug setup I am using simply has mage handle compiling the binary and dlv run the finished product afterwards.

mage -compile ./magefile-debug
dlv exec magefiles/magefile-debug

In the event this already exists, I will be very sad.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions