Cross-compile Go projects with C dependencies.
Install the following tools:
Enable the experimental features for Docker CLI by adding the following config to ~/.docker/config.json:
{
"experimental": "enabled"
}And enable the experimental features for Docker Daemon by adding the following config to the /etc/docker/daemon.json file (for Linux; on macOS it's ~/.docker/daemon.json):
{
"experimental": true
}Build the hello binary with buildx build:
docker buildx build -f Dockerfile.hello -o type=local,dest=./bin .Or build it with bake:
docker buildx bakeBuild the hello cmd on the current platform/host:
CGO_LDFLAGS="-lmsgpackc" go build -race -o ./bin/hello cmd/hello/main.goTo run tests for pkg run:
go test ./pkg/...To avoid caching during tests use:
go test -count=1 ./pkg/...To get coverage reports use the -cover flag:
go test -coverprofile=coverage.out ./pkg/...And to view the profile run:
go tool cover -html=coverage.outTo run static analysis on a package/cmd run:
go vet ./cmd/hello/main.go