bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.39k stars 663 forks source link

bzlmod + golang + cgo = undefined symbols #4180

Open bdleitner opened 6 days ago

bdleitner commented 6 days ago

What version of rules_go are you using?

0.50.1

What version of gazelle are you using?

0.38.0

What version of Bazel are you using?

7.4.1

Does this issue reproduce with the latest releases of all the above?

I believe I am on the latest for all these.

What operating system and processor architecture are you using?

Windows 10 64-bit

Any other potentially useful information about your toolchain?

I admit I am not sure I have everything correctly set up. I have mingw-64 within msys2 on my system. I've been unable to find from-scratch documentation to make sure my setup is fully cgo-ready so if there is documentation for this that would reveal I've missed something, a pointer to that would be appreciated.

What did you do?

I attempted first to have my bzlmod monolith repo depend on a library (gosseract) that uses cgo. When that failed I also tried just implementing an example cgo library.

golang_bzlmod_demo has minimal examples of all the issues I've had with golang/bzlmod that I've been able to repro. The cgoimport and cgo subprojects illustrate the import failure and the self-contained failure, respectively. The specific errors I see are shown in the README files there.

What did you expect to see?

I expected the code to compile and to be able to use the library code.

What did you see instead?

The builds failed with "undefined" errors for every time a symbol in the cgo-using library was referenced.

bdleitner commented 6 days ago

Looks like gazelle has v0.40.0 out. I wouldn't expect that to matter since the issue seems unrelated to gazelle, but just in case I tried changing the version to 0.40.0 locally and got all the same errors.