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

Docker image does not support CGO_ENABLED on Mac #65

Open
javaducky opened this issue Apr 11, 2023 · 5 comments
Open

Docker image does not support CGO_ENABLED on Mac #65

javaducky opened this issue Apr 11, 2023 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@javaducky
Copy link
Contributor

Some extensions depend on libraries written in C, requiring the CGO_ENABLED=1 environment setting. An example is xk6-sql to support using SQLite3 databases. The preference, of course, would be for extensions to utilize pure-Go libraries strictly, but this will not always be the case.

We need the xk6 builder image to allow for the CGO runtime.

@imiric
Copy link
Contributor

imiric commented Apr 11, 2023

The golang image the grafana/xk6 image is based on already has gcc installed.

So to compile a binary that requires cgo, you only need to set CGO_ENABLED=1 in the container.

E.g. this works for xk6-sql:

docker run --rm -it -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" -e CGO_ENABLED=1 grafana/xk6 build \
  --with github.com/grafana/xk6-sql

@imiric imiric closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2023
@javaducky javaducky reopened this Apr 11, 2023
@javaducky
Copy link
Contributor Author

This may then be an issue on Mac.

image

@javaducky javaducky changed the title Docker image does not support CGO_ENABLED Docker image does not support CGO_ENABLED on Mac Apr 11, 2023
@imiric imiric added the help wanted Extra attention is needed label Apr 12, 2023
@sivakusayan
Copy link

sivakusayan commented Feb 27, 2025

This seems to be broken on Ubuntu for me as well. I forked the xk6-sql-driver-sqlite3 repo and added make example as a step to the CI, and CI seems to fail.

I got this to work locally by naively deleting the code that sets CGO_ENABLED from the Compile struct. I'm not the most familiar with go, but it seems from the comments that it's intended for that structure to be populated from the go tool list -json command?

@sivakusayan
Copy link

I think a more "proper" fix is to call SupportedPlatforms() and do some parsing logic from there, since it doesn't seem to be used anywhere at the moment.

@darrenvechain
Copy link

@sivakusayan have you tried XK6_RACE_DETECTOR=1 xk6 build --with <pkg>

CGO is enforced when this flag is set: v0.13.4...v0.14.0#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants