techknowlogick / xgo

Go CGO cross compiler
MIT License
478 stars 79 forks source link

xgo does not find package, compilation fails #222

Closed kolaente closed 1 year ago

kolaente commented 1 year ago

I'm using xgo to build multi-arch docker images. Since recently, compiling my package fails because it can't find an internal package:

 > [builder 5/5] RUN export PATH=/freebsdcross/x86_64-pc-freebsd12/bin:/osxcross/target/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/go/bin &&   mage build:clean &&     mage release:xgo "linux/amd64/":
#0 0.388 go: downloading golang.org/x/sync v0.3.0
#0 0.388 go: downloading gopkg.in/yaml.v3 v3.0.1
#0 0.390 go: downloading github.com/iancoleman/strcase v0.3.0
#0 16.08 /usr/bin/xgo -dest /go/src/code.vikunja.io/api/dist/binaries -tags netgo  -ldflags -linkmode external -extldflags "-static" -X "code.vikunja.io/api/pkg/version.Version=v0.21.0+86-c5c74e9537" -X "main.Tags=" -targets linux/amd64 -out vikunja-unstable /go/src/code.vikunja.io/api
#0 16.08
#0 16.08 Cross compiling code.vikunja.io/api...
#0 16.10 Building locally code.vikunja.io/api...
#0 17.68 Compiling for linux/amd64...
#0 18.12 pkg/version/version.go:19:8: no required module provides package code.vikunja.io/api/pkg/swagger; to add it:
#0 18.12        go get code.vikunja.io/api/pkg/swagger
#0 18.12 2023/09/07 15:36:56 Failed to cross compile package: exit status 1.
#0 18.12 Error: exit status 1

The package is present in the source tree, not sure why xgo is unable to find it. Is that a bug in xgo or did I misconfigure something?

CI run: https://drone.kolaente.de/vikunja/api/5356/5/3

It is reproducible, the package is open-source:

git clone https://kolaente.dev/vikunja/api.git
cd api
docker buildx build --platform linux/amd64 . -t api:test --load

(you need a recent version of docker with buildx available)

kolaente commented 1 year ago

Looks like the "direct" run (still runs directly in the xgo docker container, but does not build a docker image) fails with a different error:

/srv/app/pkg/mod/github.com/!click!house/ch-go@v0.55.0/compress/reader.go:10:2: github.com/klauspost/compress@v1.16.7: reading https://proxy.golang.org/github.com/klauspost/compress/@v/v1.16.7.zip: 403 Forbidden
/srv/app/pkg/mod/github.com/!click!house/ch-go@v0.55.0/compress/reader.go:11:2: github.com/pierrec/lz4/v4@v4.1.17: reading https://proxy.golang.org/github.com/pierrec/lz4/v4/@v/v4.1.17.zip: 403 Forbidden
/srv/app/pkg/mod/github.com/go-playground/validator/v10@v10.15.1/baked_in.go:25:2: github.com/gabriel-vasile/mimetype@v1.4.2: reading https://proxy.golang.org/github.com/gabriel-vasile/mimetype/@v/v1.4.2.zip: 403 Forbidden
2023/09/07 14:10:03 Failed to cross compile package: exit status 1.

https://drone.kolaente.de/vikunja/api/5356/3/6

Seems unrelated to xgo?

kolaente commented 1 year ago

Kind of embarrassing, but it looks like the package was cleared after generation and before building :man_facepalming:. Of course it could not be found.