Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gotooltest: better cgo support #151

Open
mvdan opened this issue Jan 6, 2022 · 0 comments
Open

gotooltest: better cgo support #151

mvdan opened this issue Jan 6, 2022 · 0 comments

Comments

@mvdan
Copy link
Collaborator

mvdan commented Jan 6, 2022

I propose two changes to gotooltest to better support Go tests which use cgo:

  1. A conditional, [cgo], which tells you whether cgo is enabled. Practically equivalent to the shell [[ $(go env CGO_ENABLED) == "1" ]]. To be used like [!cgo] skip 'this test requires cgo to work'.

  2. Passing the CGO_ENABLED env variable through to test scripts, like GOOS or GOARCH. I can use GOARCH=386 go test to run my Go test scripts with that architecture, but note that cross-compilation in Go disables cgo by default. GOARCH=386 CGO_ENABLED=1 go test doesn't make a difference, as the latter env var isn't forwarded.

I can work around item 1 by implementing the conditional myself, and I have, but might as well have it built-in :)

I can work around item 2 by manually forwarding the env var via the Setup func, but that feels hacky. I can't simply env CGO_ENABLED=1 in the test, because that will go on to assume that cgo can work. Which is not always the case; for instance, GOARCH=386 go test fails on CI because the regular gcc is installed rather than gcc-multilib, and the former can't cross-compile from amd64 to 386 as it fails to find some header files.

Happy to submit the changes, I just thought I'd propose them first. cc @rogpeppe @myitcv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant