techknowlogick / xgo

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

Ensure modules are correctly handled including remote modules #189

Closed zeripath closed 1 year ago

zeripath commented 1 year ago

There was an unfortunate misunderstanding in #180 which did not properly take account of how xgo.go handled remote builds as compared to local builds, and modules.

This PR adjusts the way xgo handles GO111MODULE and the way it sets GO111MODULE to more closely match the way go 1.16+ handles GO111MODULE - and it makes remote builds work again (albeit there is a problem here, see below...)

From go1.16 module aware builds are assumed by default with GO111MODULE. This means GO111MODULE="" means GO111MODULE="on". This differs from the previous state where GO111MODULE="" meant GO111MODULE="auto".

xgo will now respect the GO111MODULE environment variable in the context it run in. If it is empty, a module aware build is performed by default. If it is "auto" xgo will interrogate the repository to discover it should be "on" or "off" in a similar way to go. HOWEVER, "auto" is not supported for remote builds as source code is not available to it. (It would be possible to move some of this into the build.sh or make it a separate command if this was required.)

Next, when doing a module-aware build of a remote repository the bug in #180 has been fixed, and because of the change in go1.18 that causes go get to not work outside of a module by default - the go get command is explicitly run with GO111MODULE="off" to get the old GOPATH go get variant.

Potential issues:

Fix #187

Signed-off-by: Andrew Thornton art27@cantab.net