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

Add Trimpath build option #505

Merged
merged 1 commit into from
Nov 17, 2021
Merged

Add Trimpath build option #505

merged 1 commit into from
Nov 17, 2021

Conversation

halvards
Copy link
Collaborator

Enables programmatic control of adding 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 likely 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

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
@google-cla google-cla bot added the cla: yes label Nov 17, 2021
@codecov-commenter
Copy link

Codecov Report

Merging #505 (60969de) into main (08fccaa) will increase coverage by 0.97%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
pkg/build/gobuild.go 56.83% <100.00%> (+0.57%) ⬆️
pkg/build/options.go 89.65% <100.00%> (+24.27%) ⬆️
pkg/commands/options/build.go 63.07% <100.00%> (+13.07%) ⬆️
pkg/commands/resolver.go 31.18% <100.00%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08fccaa...60969de. Read the comment docs.

if !ok {
// Apply default build flags in case none were supplied
config := g.buildConfigs[ip]
if g.trimpath {

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?

Copy link
Collaborator Author

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?

Copy link

@thielepaul thielepaul Jul 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider not adding -trimpath flag by default when disabling compiler optimizations
4 participants