Skip to content

Add go-build method#234

Merged
wagoodman merged 2 commits intomainfrom
go-build-method
Mar 9, 2026
Merged

Add go-build method#234
wagoodman merged 2 commits intomainfrom
go-build-method

Conversation

@wagoodman
Copy link
Copy Markdown
Contributor

This adds a new go-build install method, which acts similar to go install, however, without the inherent limitations (such as not permitting replace directives). This new method will fetch the source from either the upstream github repo (via shallow clone) or from the go proxy directly (controllable via the source configuration) and perform a go build. Like with the go-install installation method, this responds to local modules (skips fetching source) when there is a local path given (such as . or ./cmd/tool).

This additionally fixes a logging issue introduced with #228 (the wrong logger was plumbed through context).

@wagoodman wagoodman added the enhancement New feature or request label Mar 5, 2026
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@kzantow
Copy link
Copy Markdown
Contributor

kzantow commented Mar 5, 2026

Should this just be a fallback to go-install? I did that in this branch fixing a few things for other platforms. The larger problem is that some platforms have prebuilt assets and others don't so a single binny.yaml often doesn't work across platforms without everything being go-install or, go-build now.

@wagoodman
Copy link
Copy Markdown
Contributor Author

Adding a go-build method doesn't really have anything to do with prebuilt assets (from the github-release install method, right?).

I didn't know about the other branch in question! I think it solves the problem nicely, however, there are two problems:

  • if the user is explicitly saying to use go-install and we don't actually use go install then that could be surprising (go install is reproducible where as builds are not necessary so)
  • the branch uses the module as the repo to git clone, but this will not always work. This approach allows the user to say "always get the source from the go proxy instead of the repo" as well.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@kzantow
Copy link
Copy Markdown
Contributor

kzantow commented Mar 5, 2026

Adding a go-build method doesn't really have anything to do with prebuilt assets (from the github-release install method, right?).

Right, just pointing out the larger problem of needing fallbacks. go-install vs go-build isn't really as much a needed fallback, but the scenario is we have a go-install configured and the project gets updated with a replace directive and it breaks and now we have to reconfigure everything to be go-build for that specific tool. Then later the replace directive gets removed again, we would want to go back to go-install. I'm not opposed to adding this, but I'm just pointing out that it is solving a problem that will be transient across particular tool releases.

Comment thread tool/gobuild/source.go
}

// normalizeSourceMode converts various source mode strings to canonical form.
func normalizeSourceMode(mode SourceMode) SourceMode {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we have this code somewhere else, maybe multiple other places (in syft, for example, go get go licenses)... it would be great not to duplicate it

@wagoodman wagoodman merged commit 2d08c73 into main Mar 9, 2026
4 checks passed
@wagoodman wagoodman deleted the go-build-method branch March 9, 2026 16:07
@wagoodman wagoodman added this to OSS Mar 10, 2026
@github-project-automation github-project-automation Bot moved this to Done in OSS Mar 10, 2026
@wagoodman wagoodman self-assigned this Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants