cmd/go: cache confuses package with different build tags when using CGO with pkg-config #73033
Labels
GoCommand
cmd/go
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
go version go1.24.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I encountered this issue while using https://github.com/hillu/go-yara/v4.
The setup for this is fairly complex and requires a Golang program using CGO with a
#cgo pkg-config
instruction to reference a C library, which refers to another C library as a private dependency in its pkg-config file. In go-yara's case, go-yara uses libyara which has libcrypto as a private dependency.This can also be reproduced without libyara; a minimal example (which, due to the aforementioned complex setup, is not that small) is attached as a ZIP file.
minimalexample.zip
As a prerequisite for reproducing the issue, the contained C libraries in
dependencies/c
need to be built withgcc -c life.c earth.c && ar rcs liblife.a life.o && ar rcs libearth.a earth.o
.Now, the program can be built with:
go clean -cache go build -tags life_static .
Which should succeed.
A build without
life_static
tag should fail:go clean -cache go build .
However, the issue arises when building first without
life_static
(which will fail) and then withlife_static
(which shouldn't fail):go clean -cache go build . ; go build -tags life_static .
What did you see happen?
For the first
go build
invocation (withoutlife_static
tag), the build (expectedly) fails since the symbols oflibearth
are missing for the (statically built)liblife
.However, the second
go build
invocation (withlife_static
) also fails, with the same error message, despite the same invocation succeeding on a clean cache.This seems to be related to to the build cache (since building on a clean cache succeeds); presumably, the cache reuses the already built packages from the previous build, despite the fact that they were built with different tags.
What did you expect to see?
go build -tags life_static
should always return the same result.The text was updated successfully, but these errors were encountered: