Skip to content

Commit

Permalink
make: Optionally include debug symbols with builds (#193)
Browse files Browse the repository at this point in the history
Per #2199, we want to be able to include the proxy's
debug symbols in auxiliary diagnostic containers. In order to do this,
the process that produces the proxy's binaries also should be responsible
for producing its debug symbols.

This change adds a new environment variable, `CARGO_DEBUG`, which
the Makefile uses to instrument the build to produce debug symbols. If
`objcopy` is available on the local system (i.e. on Linux), then the
symbols are copied from the binary into a .obj file, and the executable
is stripped (from 3.3G down to 9.9M) before packaging.

This increases the size of the compressed package artifact by 76% (from 5.0M to
8.8M). This may have similar impacts on build time. To that end,
CARGO_DEBUG is not enabled in CI yet.

CI has been changed, however, to use build stages. Now, master will
undergo the same test stage as PRs, though packages are only built &
published for master.
  • Loading branch information
olix0r authored Feb 15, 2019
1 parent 738a541 commit d1bbd4b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
28 changes: 15 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@ sudo: false

language: rust
cache: cargo
env:
- RUSTFLAGS="-C debuginfo=0" RUST_TEST_THREADS=1 RUST_TEST_PATIENCE_MS=200

branches:
only:
- master

jobs:
include:
# On PRs and branches, quickly run tests in debug mode.
- if: type = pull_request
install: rustup component add rustfmt
# Quickly run tests in dev mode.
- rust: stable
install:
- rustup component add rustfmt
- export RUSTFLAGS="-C debuginfo=0" RUST_TEST_THREADS=1 RUST_TEST_PATIENCE_MS=200
script:
- make check-fmt
- make test
rust: stable
- travis_wait make test
# If you're debugging disk utilization/caching... This finds the largest files in `target`:
#- du -sh target && find target -type f |xargs -n 1000 du -s |sort -rn |head |awk '{print $2}' |xargs du -sh

# On master, package an artifact and run tests in release mode before
# publishing the artifact to build.l5d.io/linkerd2-proxy.
#
# build.l5d.io/linkerd2-proxy/latest.txt is updated to reference the latest
# uploaded binary.
- if: type != pull_request
# Verbose is enabled so that the build doesn't timeout.
install: export CARGO_RELEASE=1 CARGO_VERBOSE=1
script:
- make clean-package package
- make test
- stage: publish
if: branch = master && type != pull_request
rust: stable
script:
# Set `CARGO_DEBUG` in order to include debug symbols.
- CARGO_RELEASE=1 travis_wait make package
after_deploy:
- make clean-package
deploy:
on:
repo: linkerd/linkerd2-proxy
Expand Down
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ PKG = $(PKG_NAME).tar.gz

SHASUM = shasum -a 256

CARGO = cargo
ifdef CARGO_VERBOSE
CARGO = cargo --verbose
endif

CARGO ?= cargo
CARGO_BUILD = $(CARGO) build --frozen $(RELEASE)

CARGO_TEST = $(CARGO) test --all --frozen $(RELEASE)

CARGO_FMT = $(CARGO) fmt --all

DOCKER = docker
Expand All @@ -33,13 +27,25 @@ ifdef DOCKER_TAG
DOCKER_BUILD = docker build -t $(DOCKER_TAG)
endif

RUSTCFLAGS ?=
ifdef CARGO_DEBUG
RUSTCFLAGS += -C debuginfo=2
endif

$(TARGET_BIN): fetch
$(CARGO_BUILD)

$(PKG_ROOT)/$(PKG): $(TARGET_BIN)
mkdir -p $(PKG_BASE)/bin
cp LICENSE $(PKG_BASE)
cp $(TARGET_BIN) $(PKG_BASE)/bin
cp $(TARGET_BIN) $(PKG_BASE)/bin/linkerd2-proxy
strip $(PKG_BASE)/bin/linkerd2-proxy
ifdef CARGO_DEBUG
if which objcopy >/dev/null ; then \
objcopy $(TARGET_BIN) $(PKG_BASE)/linkerd2-proxy.obj ; \
chmod 644 $(PKG_BASE)/linkerd2-proxy.obj ; \
fi
endif
cd $(PKG_ROOT) && \
tar -czvf $(PKG) $(PKG_NAME) && \
($(SHASUM) $(PKG) >$(PKG_NAME).txt) && \
Expand Down

0 comments on commit d1bbd4b

Please sign in to comment.