Skip to content

Commit

Permalink
fix(build): Fix nocgo builds. (#1493)
Browse files Browse the repository at this point in the history
Building Badger without Cgo fails because of references to Zstd in
table/builder.go introduced in #1459 .

     $ CGO_ENABLED=0 go build -v .
     github.com/DataDog/zstd
     go build github.com/DataDog/zstd: build constraints exclude all Go files in
     /home/dmai/go/pkg/mod/github.com/!data!dog/zstd@v1.4.1

Moving zstd.CompressBound to y/zstd_cgo.go and y/zstd_nocgo.go fixes non-Cgo
builds. As is already the case, non-Cgo builds with compression must use snappy,
not Zstd, or calling y.ZSTDCompressBound without Cgo will panic.
  • Loading branch information
danielmai authored Aug 28, 2020
1 parent 8397bd9 commit 806a325
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions table/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"sync"
"unsafe"

"github.com/DataDog/zstd"
"github.com/dgryski/go-farm"
"github.com/golang/protobuf/proto"
"github.com/golang/snappy"
Expand Down Expand Up @@ -507,7 +506,7 @@ func (b *Builder) compressData(data []byte) ([]byte, error) {
dst := z.Calloc(sz)
return snappy.Encode(dst, data), nil
case options.ZSTD:
sz := zstd.CompressBound(len(data))
sz := y.ZSTDCompressBound(len(data))
dst := z.Calloc(sz)
return y.ZSTDCompress(dst, data, b.opt.ZSTDCompressionLevel)
}
Expand Down
5 changes: 5 additions & 0 deletions y/zstd_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ func ZSTDDecompress(dst, src []byte) ([]byte, error) {
func ZSTDCompress(dst, src []byte, compressionLevel int) ([]byte, error) {
return zstd.CompressLevel(dst, src, compressionLevel)
}

// ZSTDCompressBound returns the worst case size needed for a destination buffer.
func ZSTDCompressBound(srcSize int) int {
return zstd.CompressBound(srcSize)
}
5 changes: 5 additions & 0 deletions y/zstd_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ func ZSTDDecompress(dst, src []byte) ([]byte, error) {
func ZSTDCompress(dst, src []byte, compressionLevel int) ([]byte, error) {
return nil, ErrZstdCgo
}

// ZSTDCompressBound returns the worst case size needed for a destination buffer.
func ZSTDCompressBound(srcSize int) int {
panic("ZSTD only supported in Cgo.")
}

0 comments on commit 806a325

Please sign in to comment.