Skip to content

Commit

Permalink
fix: explicitly pass static flag to linker (#788)
Browse files Browse the repository at this point in the history
* fix: pass static flag to linker

* fix: set version=2 in goreleaser

* fix: when building with goreleaser also create archives and packages

* ci: also trimpath

* ci: add --snapshot
  • Loading branch information
mrexox authored Jul 26, 2024
1 parent f1d85d3 commit ac882cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
with:
distribution: goreleaser
version: '~> v2'
args: build --snapshot --skip=validate --clean
args: release --snapshot --skip=publish --skip=snapcraft --skip=validate --clean
- name: Tar binaries to preserve executable bit
run: 'tar -cvf lefthook-binaries.tar --directory dist/ $(find dist/ -executable -type f -printf "%P\0" | xargs --null)'
- name: Upload binaries as artifacts
Expand Down
9 changes: 7 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
project_name: lefthook
before:
hooks:
Expand Down Expand Up @@ -25,8 +26,10 @@ builds:
goarch: 386
- goos: freebsd
goarch: 386
flags:
- -trimpath
ldflags:
- -s -w -X github.com/evilmartians/lefthook/internal/version.commit={{.Commit}}
- -s -w -extldflags '-static' -X github.com/evilmartians/lefthook/internal/version.commit={{.Commit}}

# Full lefthook binary
- id: lefthook
Expand All @@ -48,8 +51,10 @@ builds:
goarch: 386
- goos: freebsd
goarch: 386
flags:
- -trimpath
ldflags:
- -s -w -X github.com/evilmartians/lefthook/internal/version.commit={{.Commit}}
- -s -w -extldflags '-static' -X github.com/evilmartians/lefthook/internal/version.commit={{.Commit}}

archives:
- id: lefthook
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
COMMIT_HASH = $(shell git rev-parse HEAD)

build:
go build -ldflags "-s -w -X github.com/evilmartians/lefthook/internal/version.commit=$(COMMIT_HASH)" -o lefthook
go build -ldflags "-s -w -extldflags '-static' -X github.com/evilmartians/lefthook/internal/version.commit=$(COMMIT_HASH)" -o lefthook

build-with-coverage:
go build -cover -ldflags "-s -w -X github.com/evilmartians/lefthook/internal/version.commit=$(COMMIT_HASH)" -o lefthook
go build -cover -ldflags "-s -w extldflags '-static' -X github.com/evilmartians/lefthook/internal/version.commit=$(COMMIT_HASH)" -o lefthook

install: build
cp lefthook $$(go env GOPATH)/bin
Expand Down

0 comments on commit ac882cc

Please sign in to comment.