After adding support for go mod in 3.10.1, we are no longer able to build new packages for https://github.com/travis-ci/worker
go build -o <out dir>, which builds main package only if it’s inside the root, but in our case main package is located in another dir
./cmd/travis-worker/main.go (which is a common pattern for go applications) and the command fails.
go mod support, snapcraft would scan all dirs for
main package and build all of them. Unfortunately, I haven’t found a way to restore the old behaviour.
Possible way to fix is to tell
go build where main package is located (e.g.
go build -o <output dir> ./cmd/travis-worker), or use
./... pattern (e.g.
go build -o <output dir> ./...), so that compiler will build all main packages in the repo. I think the 2nd option is preferable as it will not require any additional configuration.
I’ve prepared a minimal example where the issue is reproducible:
- Given a go module, where main package is located in
- Clone https://github.com/pavel-d/snaptest
snapcraft build --use-lxd --debug
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
snapd 2.43.3 from Canonical✓ refreshed
Skipping pull snaptest (already ran)
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
I’ve sent a PR, please let me know what you think! https://github.com/snapcore/snapcraft/pull/2962