← Back to issue list

go module plugin assumes go files are in root of part source

View original Launchpad issue

Metadata

Project
snapcraft (launchpad)
Number
#1858494
Type
issue
State
closed
Author
~anonymouse67
Labels
—
Created
Updated
Closed

Current evaluation

Go builds outside the part-source root were addressed by snapcore/snapcraft#2962; the maintainer linked that PR before the Launchpad bug was closed.

Resolution: closed resolved

Reason: The maintainer cited snapcore/snapcraft#2962 as the follow-up, and the bug was subsequently closed without a competing explanation. That PR is the concrete resolution for the Go plugin behavior.

Evaluated by: mr-cal-bot

No scores available.

Issue body

The go plugin has been updated to support go modules, which is great, however its mechanism to build binaries is a bit weird. It seems like it runs: ``` go build -o $SNAPCRAFT_PART_INSTALL/bin ``` which doesn't do anything when your go code is organized underneath a cmd/ directory as is very common with go projects. I can build individual binaries by setting `source-subdir: cmd/command1` and just creating duplicate parts with the same source and different source-subdirs, but this feels duplicative and wasteful. Is there a better way to build such go binaries? In the meantime, I've fallen back to building like so: ```yaml parts: influxproxy: source: . plugin: go build-packages: [mercurial, git, build-essential] override-build: | mkdir -p $SNAPCRAFT_PART_INSTALL/bin cd $SNAPCRAFT_PART_SRC go build -o $SNAPCRAFT_PART_INSTALL/bin/thing1 ./cmd/thing1 go build -o $SNAPCRAFT_PART_INSTALL/bin/thing2 ./cmd/thing2 ``` which is better than the old behavior which didn't support modules properly.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Go builds outside the part-source root were addressed by snapcore/snapcraft#2962; the maintainer linked that PR before the Launchpad bug was closed.
stealth/space-bunny-alpha — closed resolved Fixed by merged PR #2962 (commit dd7431146), which updated the Go plugin to discover main packages in subdirectories and added an integration test.
stealth/space-bunny-alpha — closed stale Closed without a documented fix; matching Launchpad bug #1858494 is also closed with no comments, leaving builds from Go cmd/ subdirectories unresolved.
qwen/qwen3.6-35b-a3b — — Closed without resolution. The go plugin incorrectly assumes source files are in the project root, failing to build binaries from standard cmd/ directories. No comments or fixes were provided, leaving the issue abandoned.
qwen/qwen3.6-35b-a3b — — Closed without a fix. The author provided a workaround using override-build, but the Go plugin was never updated to handle cmd/ subdirectories. The request was effectively abandoned.
qwen/qwen3.6-35b-a3b — — Closed without comments or resolution, the go plugin cmd/ directory limitation was likely abandoned. The author provided a custom override-build workaround, but no official fix or update was implemented.
qwen3.6-35b-a3b-mtp-q6 — — Closed without resolution. The go plugin behavior remains unchanged, assuming source files are at the project root and failing for standard cmd/ directory layouts. No fix or workaround was implemented.

Update history

Date Change
created

Related work

  • Likely Fixed By: snapcore/snapcraft#2962 (confidence 95%)

    The maintainer directly linked this PR in the only issue comment.

Related issues

Issue Project State Summary Similarity
#2962 Go: unable to build snap when using `go mod` and main package is not in the root snapcraft merged Merged in commit dd7431146: the Go plugin now uses ./... to find main packages in subdirectories, with an integration test added.
72%