Skip to content

proposal: cmd/go: build: add -buildmode=nolink flag #31710

@kevinburke

Description

@kevinburke

My understanding of the "go build" process is it does something like this:

  • Figure out all of the dependencies of the package.
  • For each dependency, determine whether it has changed since the last time it was built, by checking the .a file or equivalent in $GOPATH/pkg.
  • Compile them, in parallel if possible
  • Generate the new artifact (a .a file or similar) we checked in net: LookupHost is returning odd values and crashing net tests #2 that is now out of date.
  • Link them all into a single binary.

I use vim to edit Go files. The most popular plugin, vim-go, recommends checking compilation by running :GoBuild. I do this frequently to ensure I have syntax correct, imports correct, a working Go program.

:GoBuild changes directory to the directory containing the file you are editing, then runs

go build -tags '' . errors

It builds the "errors" package because vim-go desperately does not want to build any final artifacts, and attempting to build multiple packages turns off the binary building behavior.

However, I notice that this never takes advantage of build caching. That is, if I run :GoBuild and then run :GoBuild again immediately without making changes, it takes 4 seconds on the package I am compiling. If I run go build . to compile an artifact, it is much faster, about 600ms on the second run.

Is there a way to make "go build" take advantage of whatever intermediate build steps exist - the .a files from above, or their equivalents - even if it does not produce a final binary?

Alternatively, can you work with the vim-go maintainers to recommend a different tool for checking a package (and/or test package) contains valid Go syntax and identifiers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Proposal

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions