Skip to content

rolandjitsu/go-cross

Repository files navigation

Go Cross

Cross-compile Go projects with C dependencies.

GitHub Workflow Status

Prerequisites

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

Docker

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 bake

Native

Build the hello cmd on the current platform/host:

CGO_LDFLAGS="-lmsgpackc" go build -race -o ./bin/hello cmd/hello/main.go

Test

To 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.out

To run static analysis on a package/cmd run:

go vet ./cmd/hello/main.go