You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Up until recently we'd been using a wrapper script around the linker which just injected -lc++ no matter how broken the build system was being, but now I need to support compilation against either libc++ or libstdc++, so that's no longer an option.
which strips it out assuming that it'll be in CGO_LDFLAGS if needed except, leaving aside that _cgo_codegen doesn't seem to be a thing any more, I'm not sure how it's supposed to do that, because the go library doesn't have a direct dependency on the c++ library, and the go library doesn't use #cgo LDFLAGS directives because it wouldn't work anyway because the library it needs to link to doesn't exist outside of bazel. Adding
// #cgo LDFLAGS: -lstdc++
in the code is out of the question because this has to build with either libstdc++ or libc++ (including on linux).
The comment also seems somewhat at odds with
It may be possible to set it explicitly in the linkopts for the go_library, by configuring complicated select()s to infer which c++ standard library should be in use, but frankly I went to the trouble of configuring my c++ toolchain correctly so that I wouldn't have to do that.
Now that I've tracked down the cause of this issue, I do have a workaround, which is to change my toolchain configuration's linkopts to use -Wl,-Bstatic,-lstdc++ to defeat the string matching, but it does seem like a case of the go rules trying to outsmart the c++ toolchain configuration and failing.
The text was updated successfully, but these errors were encountered:
What version of rules_go are you using?
0.48.1
What version of gazelle are you using?
n/a
What version of Bazel are you using?
7.4.1
Does this issue reproduce with the latest releases of all the above?
Yes
What operating system and processor architecture are you using?
Linux/amd64
Any other potentially useful information about your toolchain?
Custom c++ toolchain configuration including
What did you do?
Try to compile a cgo executable with a transitive dependency on c++
cc_library
.What did you expect to see?
Successful linking with the toolchain-provided link flags.
What did you see instead?
The
-lstdc++
is stripped out from the link line, so we getUp until recently we'd been using a wrapper script around the linker which just injected
-lc++
no matter how broken the build system was being, but now I need to support compilation against eitherlibc++
orlibstdc++
, so that's no longer an option.This seems to be caused by I think
rules_go/go/private/actions/link.bzl
Lines 55 to 58 in 5200a61
which strips it out assuming that it'll be in
CGO_LDFLAGS
if needed except, leaving aside that_cgo_codegen
doesn't seem to be a thing any more, I'm not sure how it's supposed to do that, because the go library doesn't have a direct dependency on the c++ library, and the go library doesn't use#cgo LDFLAGS
directives because it wouldn't work anyway because the library it needs to link to doesn't exist outside of bazel. Adding// #cgo LDFLAGS: -lstdc++
in the code is out of the question because this has to build with either
libstdc++
orlibc++
(including on linux).The comment also seems somewhat at odds with
rules_go/go/tools/builders/cgo2.go
Lines 50 to 52 in 5200a61
I'm not 100% sure that
rules_go/go/private/rules/cgo.bzl
Lines 63 to 69 in 5200a61
isn't involved as well.
It may be possible to set it explicitly in the linkopts for the
go_library
, by configuring complicatedselect()
s to infer which c++ standard library should be in use, but frankly I went to the trouble of configuring my c++ toolchain correctly so that I wouldn't have to do that.Now that I've tracked down the cause of this issue, I do have a workaround, which is to change my toolchain configuration's linkopts to use
-Wl,-Bstatic,-lstdc++
to defeat the string matching, but it does seem like a case of the go rules trying to outsmart the c++ toolchain configuration and failing.The text was updated successfully, but these errors were encountered: