Skip to content

Commit

Permalink
Merge pull request #5 from pjbgf/no-cgo-support
Browse files Browse the repository at this point in the history
build: Support build when CGO is disabled
  • Loading branch information
pjbgf authored Dec 2, 2022
2 parents c854406 + 5fd1969 commit 6aedff0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ build-arm64:
docker build -t sha1cd-arm64 -f Dockerfile.arm64 .
docker run --rm sha1cd-arm64

# Build with cgo disabled.
build-nocgo:
CGO_ENABLED=0 go build ./cgo

# Run cross-compilation to assure supported architectures.
cross-build: build-arm build-arm64
cross-build: build-arm build-arm64 build-nocgo
32 changes: 32 additions & 0 deletions cgo/fallback_no_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build !cgo
// +build !cgo

package cgo

import (
"hash"

"github.com/pjbgf/sha1cd"
"github.com/pjbgf/sha1cd/ubc"
)

// CalculateDvMask falls back to github.com/pjbgf/sha1cd/ubc implementation
// due to CGO being disabled at compilation time.
func CalculateDvMask(W []uint32) (uint32, error) {
return ubc.CalculateDvMask(W)
}

// CalculateDvMask falls back to github.com/pjbgf/sha1cd implementation
// due to CGO being disabled at compilation time.
func New() hash.Hash {
return sha1cd.New()
}

// CalculateDvMask falls back to github.com/pjbgf/sha1cd implementation
// due to CGO being disabled at compilation time.
func Sum(data []byte) ([]byte, bool) {
d := sha1cd.New().(sha1cd.CollisionResistantHash)
d.Write(data)

return d.CollisionResistantSum(nil)
}

0 comments on commit 6aedff0

Please sign in to comment.