Skip to content

Commit

Permalink
Pass the netgo tag when building static binaries:
Browse files Browse the repository at this point in the history
- When building static binaries with CGO, cgo unix network segfaults
- When building dynamically linked binaries with CGO, everything is fine

prometheus/alertmanager#304
golang/go#7857

Signed-off-by: Ying Li <[email protected]>
  • Loading branch information
cyli committed Nov 15, 2016
1 parent ab9892b commit 1952384
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ ${PREFIX}/bin/static/notary:
else
${PREFIX}/bin/static/notary-server: NOTARY_VERSION $(shell find . -type f -name '*.go')
@echo "+ $@"
@(export CGO_ENABLED=0; go build -tags ${NOTARY_BUILDTAGS} -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-server)
@(export CGO_ENABLED=0; go build -tags "${NOTARY_BUILDTAGS} netgo" -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-server)

${PREFIX}/bin/static/notary-signer: NOTARY_VERSION $(shell find . -type f -name '*.go')
@echo "+ $@"
@(export CGO_ENABLED=0; go build -tags ${NOTARY_BUILDTAGS} -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-signer)
@(export CGO_ENABLED=0; go build -tags "${NOTARY_BUILDTAGS} netgo" -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary-signer)

${PREFIX}/bin/static/notary:
@echo "+ $@"
@go build -tags ${NOTARY_BUILDTAGS} -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary
@go build -tags "${NOTARY_BUILDTAGS} netgo" -o $@ ${GO_LDFLAGS_STATIC} ./cmd/notary

endif

Expand Down
2 changes: 1 addition & 1 deletion buildscripts/cross.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ for os in "$@"; do
go build \
-o "${NOTARYDIR}/cross/${GOOS}/${GOARCH}/${OUTFILE}" \
-a \
-tags "${BUILDTAGS}" \
-tags "${BUILDTAGS} netgo" \
-ldflags "-w ${CTIMEVAR} ${LDFLAGS}" \
./cmd/notary;
set +x;
Expand Down

0 comments on commit 1952384

Please sign in to comment.