Skip to content

Commit

Permalink
Merge pull request twpayne#893 from twpayne/static-link-with-musl
Browse files Browse the repository at this point in the history
Statically link Linux binary with musl
  • Loading branch information
twpayne committed Sep 28, 2020
2 parents a23351f + c04022b commit cfa3fd2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/bin/gofumports
/bin/golangci-lint
/chezmoi
/chezmoi.exe
/chezmoi*
/dist
10 changes: 10 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cfa3fd2

Please sign in to comment.