Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6aedff0

Browse files
authored
Merge pull request #5 from pjbgf/no-cgo-support
build: Support build when CGO is disabled
2 parents c854406 + 5fd1969 commit 6aedff0

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ build-arm64:
2424
docker build -t sha1cd-arm64 -f Dockerfile.arm64 .
2525
docker run --rm sha1cd-arm64
2626

27+
# Build with cgo disabled.
28+
build-nocgo:
29+
CGO_ENABLED=0 go build ./cgo
30+
2731
# Run cross-compilation to assure supported architectures.
28-
cross-build: build-arm build-arm64
32+
cross-build: build-arm build-arm64 build-nocgo

cgo/fallback_no_cgo.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//go:build !cgo
2+
// +build !cgo
3+
4+
package cgo
5+
6+
import (
7+
"hash"
8+
9+
"github.com/pjbgf/sha1cd"
10+
"github.com/pjbgf/sha1cd/ubc"
11+
)
12+
13+
// CalculateDvMask falls back to github.com/pjbgf/sha1cd/ubc implementation
14+
// due to CGO being disabled at compilation time.
15+
func CalculateDvMask(W []uint32) (uint32, error) {
16+
return ubc.CalculateDvMask(W)
17+
}
18+
19+
// CalculateDvMask falls back to github.com/pjbgf/sha1cd implementation
20+
// due to CGO being disabled at compilation time.
21+
func New() hash.Hash {
22+
return sha1cd.New()
23+
}
24+
25+
// CalculateDvMask falls back to github.com/pjbgf/sha1cd implementation
26+
// due to CGO being disabled at compilation time.
27+
func Sum(data []byte) ([]byte, bool) {
28+
d := sha1cd.New().(sha1cd.CollisionResistantHash)
29+
d.Write(data)
30+
31+
return d.CollisionResistantSum(nil)
32+
}

0 commit comments

Comments
 (0)