From 253ea6eee89a332cfefe43a24819d2b68011849e Mon Sep 17 00:00:00 2001 From: Karun Sandhu <129101708+MrSom3body@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:22:35 +0100 Subject: [PATCH] treewide: make every compilation statically linked --- .github/workflows/go.yml | 6 +++++- .github/workflows/release.yml | 5 ++++- nix/package.nix | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6092f4a..c9ea8c5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,10 +19,14 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.23' + go-version-file: 'go.mod' - name: Build + env: + CGO_ENABLED: 0 run: go build -v ./... - name: Test + env: + CGO_ENABLED: 0 run: go test -v ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 932beb3..827c3f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,11 +23,14 @@ jobs: - name: Compile go binary env: + CGO_ENABLED: 0 GOOS: linux GOARCH: amd64 run: | mkdir -p dist - go build -o dist/ + go build \ + -ldflags="-s -w -extldflags '-static'" + -o dist/ - name: Create release env: diff --git a/nix/package.nix b/nix/package.nix index d4f693c..96ae211 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -8,7 +8,11 @@ buildGoModule { src = ./..; vendorHash = "sha256-hocnLCzWN8srQcO3BMNkd2lt0m54Qe7sqAhUxVZlz1k="; + env.CGO_ENABLED = 0; + ldflags = [ + "-s -w" "-X 'github.com/MrSom3body/gotcha/cmd.ifaceName=${interface}'" + "-extldflags '-static'" ]; }