|
A go_binary target with linkmode c-archive emits only a single
_cgo_exports.h header instead of all such headers of all transitive
dependencies.
Currently, this header is taken to be the first element in a list
obtained from the depset of these transitive _cgo_exports.h files
via to_list(). While deterministic, this choice is not guaranteed to
give the correct _cgo_exports.h (i.e., the one of the go_binary
itself) as the depset iteration order is not specified.
This commit ensures that the _cgo_exports.h of the target itself is
added as the first element of the `direct` list of a depset with
iteration order specified as `preorder` and will thus always be the
first element when the depset is converted to a list.
The commit adds a testcase that does not compile without it:
If a Go library that depends on a CGo library (in this case x/sys/unix)
is itself depended on by a cc_library as a c-archive, the emitted CGo
header is that of the CGo library, not the Go library itself.
|