From c04022bb56ebef768170fdbd6b51306c456e7d2d Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 28 Sep 2020 16:08:56 +0200 Subject: [PATCH] Statically link Linux binary with musl --- .github/workflows/main.yml | 8 +++++++- .gitignore | 3 +-- .goreleaser.yaml | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 426283c5a44..bca5c47c4fa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,6 +38,9 @@ jobs: test-release: runs-on: ubuntu-latest steps: + - name: Install musl + run: | + sudo apt install -y musl-tools - name: Set up Go uses: actions/setup-go@v2 with: @@ -62,7 +65,7 @@ jobs: - name: Test release run: | # verify that version information is embedded correctly - ./dist/chezmoi-cgo_linux_amd64/chezmoi --version | tee /dev/stderr | grep -q "chezmoi version v" + file ./dist/chezmoi-cgo_linux_amd64/chezmoi | tee /dev/stderr | grep -q "statically linked" ./dist/chezmoi-cgo_linux_amd64/chezmoi --version | tee /dev/stderr | grep -q "chezmoi version v" ./dist/chezmoi-nocgo_linux_386/chezmoi --version | tee /dev/stderr | grep -q "chezmoi version v" generate: @@ -103,6 +106,9 @@ jobs: - test-release runs-on: ubuntu-latest steps: + - name: Install musl + run: | + sudo apt install -y musl-tools - name: Set up Go uses: actions/setup-go@v2 with: diff --git a/.gitignore b/.gitignore index 9315982f61a..625e34df4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /bin/gofumports /bin/golangci-lint -/chezmoi -/chezmoi.exe +/chezmoi* /dist diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 74424e308da..6dd01fd90fc 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -8,11 +8,21 @@ builds: - id: chezmoi-cgo binary: chezmoi env: + - CC=/usr/bin/musl-gcc - CGO_ENABLED=1 goos: - linux goarch: - amd64 + ldflags: + - '-s' + - '-w' + - '-X main.version={{.Version}}' + - '-X main.commit={{.Commit}}' + - '-X main.date={{.Date}}' + - '-X main.builtBy=goreleaser' + - '-linkmode external' + - '--extldflags "-static"' - id: chezmoi-nocgo binary: chezmoi env: