Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static builds link against musl #3343

Merged
merged 3 commits into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ TESTFLAGS :=
DUPLFLAGS := -t 100

ifeq ($(STATIC),1)
# The netgo build tag instructs the net package to try to build a
# Go-only resolver. As of Go 1.5, netgo is the default...but apparently
# not when using cgo (???).
TAGS += netgo
# Static linking with glibc is a bad time; see
# https://github.com/golang/go/issues/13470.
# If a static build is requested, assume musl is installed (it is in
# the cockroachdb/builder docker container) and link against it
# instead.
CC = /usr/local/musl/bin/musl-gcc
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like fully-static builds was an experiment which failed. Why not just remove support for it completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it works just fine with musl. There's an ongoing discussion between @bdarnell and I in an "outdated diff" - basically, I think it's worth keeping this because someone may want a static build, and we've already done all the work to figure out how to make that safe.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to continue to test the musl builds? If not, they will likely rot as all untested code does. I like Ben's suggestion to place the info about using musl for static builds on a wiki page along with some notes about the downsides to using musl (i.e. not tested).

# `-v` so warnings from the linker aren't suppressed.
# `-a` so dependencies are rebuilt (they may have been dynamically
# linked).
GOFLAGS += -a -v
LDFLAGS += -extldflags '-static'
endif

Expand All @@ -58,14 +64,14 @@ build: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTag=$(shell git
build: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTime=$(shell date -u '+%Y/%m/%d %H:%M:%S')"
build: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildDeps=$(shell GOPATH=${GOPATH} build/depvers.sh)"
build:
$(GO) build -tags '$(TAGS)' $(GOFLAGS) -ldflags '$(LDFLAGS)' -v -i -o cockroach
$(GO) build -tags '$(TAGS)' $(GOFLAGS) -ldflags '$(LDFLAGS)' -i -o cockroach

.PHONY: install
install: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTag=$(shell git describe --dirty)"
install: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildTime=$(shell date -u '+%Y/%m/%d %H:%M:%S')"
install: LDFLAGS += -X "github.com/cockroachdb/cockroach/util.buildDeps=$(shell GOPATH=${GOPATH} build/depvers.sh)"
install:
$(GO) install -tags '$(TAGS)' $(GOFLAGS) -ldflags '$(LDFLAGS)' -v
$(GO) install -tags '$(TAGS)' $(GOFLAGS) -ldflags '$(LDFLAGS)'

# Build, but do not run the tests.
# PKG is expanded and all packages are built and moved to their directory.
Expand Down
2 changes: 2 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ RUN curl --silent --location https://deb.nodesource.com/setup_5.x | bash - && \
apt-get install --no-install-recommends --auto-remove -y git build-essential file nodejs && \
apt-get clean autoclean && \
apt-get autoremove -y && \
curl --silent --location http://www.musl-libc.org/releases/musl-1.1.12.tar.gz | tar -xz && \
cd musl-1.1.12 && ./configure && make && make install && \
rm -rf /tmp/*

ENV SKIP_BOOTSTRAP=1
Expand Down
2 changes: 1 addition & 1 deletion build/circle-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ buildcache_dir=~/buildcache
# The tag for the cockroachdb/builder image. If the image is changed
# (for example, adding "npm"), a new image should be pushed using
# "build/builder.sh push" and the new tag value placed here.
tag="20151108-172428"
tag="20151209-144441"

mkdir -p "${buildcache_dir}"
du -sh "${buildcache_dir}"
Expand Down