gozstd
gozstd copied to clipboard
build: enable build without cgo
we have moved from github.com/klauspost/compress to github.com/valyala/gozstd in github.com/containers/storage for performance reasons when pulling container images, but unfortunately we need to support build also on targets where cgo is missing: https://github.com/containers/podman/pull/12794
Without this PR, I get:
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
# github.com/valyala/gozstd
./stream.go:14:48: undefined: DefaultCompressionLevel
./stream.go:31:59: undefined: CDict
./stream.go:35:64: undefined: CDict
./stream.go:47:20: undefined: Writer
./stream.go:56:22: undefined: NewWriterLevel
./stream.go:101:61: undefined: DDict
./stream.go:110:6: undefined: Reader
./stream.go:117:8: undefined: NewReader
now the build works fine
Signed-off-by: Giuseppe Scrivano [email protected]
@valyala PTAL
The Podman team is waiting on this to merge.
@valyala PTAL
@giuseppe , sorry for the delay and thanks for the pull request! I'm unsure this is a good way to go, since it allows building github.com/valyala/gozstd
without cgo
, but the resulting build is unusable - it is just a stub. Probably the approach taken in VictoriaMetrics is better - e.g. to create a wrapper package containing two files:
- the first one is built when
cgo
is enabled. It importsgithub.com/valyala/gozstd
- the second one is built when
cgo
is disabled. It importsgithub.com/klauspost/compress/zstd
See https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/lib/encoding/zstd .
We are fine with that. The issue we are seeing when we vendor in your code into a package, it blows up on compile, even if we are not using gozstd in the revendored package.
The issue we are seeing when we vendor in your code into a package, it blows up on compile, even if we are not using gozstd in the revendored package.
This sounds strange, since VictoriaMetrics is successfully built with both CGO_ENABLED=0
and CGO_ENABLED=1
when using the trick described above. Make sure that the github.com/valyala/gozstd
is imported in the file, which compiles only for CGO_ENABLED=1
. See build instructions and this particular section for details.