Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: enable build without cgo #41

Closed
wants to merge 1 commit into from
Closed

Conversation

giuseppe
Copy link

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: containers/podman#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]

Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe
Copy link
Author

@valyala PTAL

@rhatdan
Copy link

rhatdan commented Jan 11, 2022

The Podman team is waiting on this to merge.

@rhatdan
Copy link

rhatdan commented Jan 14, 2022

@valyala PTAL

@valyala
Copy link
Owner

valyala commented Jan 31, 2022

@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 imports github.com/valyala/gozstd
  • the second one is built when cgo is disabled. It imports github.com/klauspost/compress/zstd

See https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/lib/encoding/zstd .

@rhatdan
Copy link

rhatdan commented Jan 31, 2022

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.

@valyala
Copy link
Owner

valyala commented Feb 7, 2022

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.

@giuseppe giuseppe closed this Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants