Go: unable to build snap when using `go mod` and main package is not in the root
Metadata
Current evaluation
Merged in commit dd7431146: the Go plugin now uses ./... to find main packages in subdirectories, with an integration test added.
Resolution: closed resolved
Reason: PR #2962 was approved and merged as commit dd7431146. It changed the Go plugin to build Go modules with the ./... pattern and added coverage for a main package in a subdirectory, resolving the reported build failure.
Evaluated by: mr-cal-bot
No scores available.
Issue body
When using go modules, `go build -o <path>` will pick up main package only if it's in the root of repository.
Steps to reproduce:
0. Given a go module, where [main](https://github.com/pavel-d/snaptest/blob/master/cli/main.go) package is located in `./cli` subdirectory
1. Clone https://github.com/pavel-d/snaptest
2. `cd snaptest`
2. Run `snapcraft build --use-lxd --debug`
Result:
```
snapcraft --use-lxd --debug
The LXD provider is offered as a technology preview for early adopters.
The command line interface, container names or lifecycle handling may change in upcoming releases.
Launching a container.
Waiting for container to be ready
......................
status: done
snapd 2.43.3 from Canonical✓ refreshed
Skipping pull snaptest (already ran)
Building snaptest
go build -o /root/parts/snaptest/install/bin
go build: no main packages to build
Failed to run 'go build -o /root/parts/snaptest/install/bin' for 'snaptest': Exited with code 1.
Verify that the part is using the correct parameters and try again.
snapcraft-snaptest # snapcraft --version
snapcraft, version 3.10.1
```
The `./...` pattern matches all the packages within the current module and `go build` will automatically build main packages in subdirectories.
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] Have you successfully run `./runtests.sh static`?
- [ ] Have you successfully run `./runtests.sh tests/unit`?
-----
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged in commit dd7431146: the Go plugin now uses ./... to find main packages in subdirectories, with an integration test added. | |
| stealth/space-bunny-alpha | — | closed resolved | Go module builds now find main packages in subdirectories. PR #2962 updated the Go plugin to use the ./... pattern and added an integration test; it was merged in commit dd7431146. | |
| qwen/qwen3.6-35b-a3b | — | — | Merged a fix for Go module builds failing when the main package is in a subdirectory. Updated the build command to use the ./... pattern to locate main packages, added an integration test, and resolved CLA email issues. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged fix for Go module builds failing when the main package is in a subdirectory. Updated the build command to use the ./... pattern to locate main packages. Added integration tests and resolved CLA email mismatches. |
Update history
No update history recorded yet.
Related work
-
Related To:
snapcraft (launchpad)#1858494
(confidence 95%)
Launchpad report describing the same Go module root-package assumption; it is marked fixed by PR #2962.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1858494 go module plugin assumes go files are in root of part source | snapcraft (launchpad) | closed | Go builds outside the part-source root were addressed by snapcore/snapcraft#2962; the maintainer linked that PR before the Launchpad bug was closed. | |
| #2194 plugins: do not install go debs if go snap is used | snapcraft | merged | Merged as commit 12d9151d3: the Go plugin now skips golang-go when a go build-snap is defined, preventing PATH conflicts. |