-
Notifications
You must be signed in to change notification settings - Fork 405
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
Add Trimpath
build option
#505
Conversation
Enables programmatic control of whether `ko` adds the `-trimpath` flag to `go build`. The `-trimpath` flag removes file system paths from the resulting binary. `ko` adds `-trimpath` by default as it aids in achieving reproducible builds. However, removing file system paths makes interactive debugging more challenging, in particular in mapping source file locations in the IDE to debug information in the binary. If you set `Trimpath` to `false` to enable interactive debugging, you probably also want to set `DisableOptimizations` to `true` to disable compiler optimizations and inlining. Reference for `-trimpath`: https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies Resolves: #500 Related: #71, #78, GoogleContainerTools/skaffold#6843
Codecov Report
@@ Coverage Diff @@
## main #505 +/- ##
==========================================
+ Coverage 50.15% 51.12% +0.97%
==========================================
Files 41 41
Lines 1944 1950 +6
==========================================
+ Hits 975 997 +22
+ Misses 809 794 -15
+ Partials 160 159 -1
Continue to review full report at Codecov.
|
if !ok { | ||
// Apply default build flags in case none were supplied | ||
config := g.buildConfigs[ip] | ||
if g.trimpath { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am trying to disable -trimpath
for local debugging. After reading #500 (comment) I hoped that setting flags: []
should be sufficient to do so.
Maybe, we could change the check in this line in the following way:
if g.trimpath && config.Flags == nil {
Or is there another way to make a build without trimpath that I am currently missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flags: []
should be sufficient I believe, or if not then you could set some other flag, such as ["-v"]
.
Did you verify that ko
picked up the build config correctly from .ko.yaml
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I verified that the .ko.yaml is used by adding an invalid flag that made the build fail. I also did a local build of ko with a print statement and the trimpath flag was always appended no matter if other flags were set or not.
Enables programmatic control of adding the
-trimpath
flag togo build
.The
-trimpath
flag removes file system paths from the resulting binary.ko
adds-trimpath
by default as it aids in achieving reproducible builds.However, removing file system paths makes interactive debugging more challenging, in particular in mapping source file locations in the IDE to debug information in the binary.
If you set
Trimpath
tofalse
to enable interactive debugging, you likely also want to setDisableOptimizations
totrue
to disable compiler optimizations and inlining.Reference for
-trimpath
: https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependenciesResolves: #500
Related: #71, #78, GoogleContainerTools/skaffold#6843