Skip to content

Commit

Permalink
Strip releases; include separate minimal debug info (#191)
Browse files Browse the repository at this point in the history
* Strip releases; include separate minimal debuginfo
* Remove redundant binary stripping from create-release.zsh
* Make it possible to opt out of debug info in create-release.zsh
  • Loading branch information
bradlarsen authored Jun 6, 2024
1 parent 8547ad8 commit a0633df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 32 deletions.
33 changes: 14 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,22 @@ publish = false


[profile.release]
# Generate debug symbols even in release builds
# Used for cargo-instruments: https://github.com/cmyr/cargo-instruments
# debug = true
# split-debuginfo = "packed"
opt-level = 3
lto = "thin"
opt-level = 3 # default for release profile

strip = true # strip out debug info and symbols

# Insta benefits from being compiled in release mode, even as dev dependency.
[profile.dev.package.insta]
opt-level = 3
split-debuginfo = "packed" # generate separate packed debug info

# The `similar` dependency that Insta uses also benefits from being compiled in
# release mode, even as dev dependency.
[profile.dev.package.similar]
opt-level = 3
debug = "line-tables-only" # generate enough debug info to give useful stack traces upon panic
#debug = true # generate full debug info; significantly larger!

# `vectorscan-rs` and `vectorscan-rs-sys` benefit from being build in release mode,
# even as a dev dependency: doing so saves about 6 seconds on each integration
# test case!
[profile.dev.package.vectorscan-rs]
opt-level = 3
[profile.dev.package.vectorscan-rs-sys]
opt-level = 3


# A number of packages benefit from being compiled with optimization even as dev dependencies.
[profile.dev.package]
insta = { opt-level = 3 }
similar = { opt-level = 3 }
# Using optimization on the vectorscan packages saves ~6s on each integration test case!
vectorscan-rs = { opt-level = 3 }
vectorscan-rs-sys = { opt-level = 3 }
3 changes: 2 additions & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ WORKDIR "/noseyparker"

COPY . .

RUN ./scripts/create-release.zsh --strip && cp -r release /release
RUN ./scripts/create-release.zsh --no-debug && \
cp -r release /release

################################################################################
# Build a smaller image just for running the `noseyparker` binary
Expand Down
26 changes: 14 additions & 12 deletions scripts/create-release.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ ensure_has_program() {
# The directory containing this script
HERE=${0:a:h}

# To strip or not strip the final binary?
DO_STRIP=0
# To include debug symbols in the release?
INCLUDE_DEBUG=1

################################################################################
# Parse arguments
################################################################################
while (( $# > 0 )); do
case $1 in
--strip)
DO_STRIP=1
--no-debug)
INCLUDE_DEBUG=0
shift
;;

Expand All @@ -41,6 +41,7 @@ while (( $# > 0 )); do
esac
done


################################################################################
# Determine build configuration
################################################################################
Expand All @@ -49,13 +50,11 @@ case $(uname) in
Darwin*)
PLATFORM="macos"
CARGO_FEATURES="release"
STRIP_COMMAND=(strip)
;;

Linux*)
PLATFORM="linux"
CARGO_FEATURES="release"
STRIP_COMMAND=(strip --strip-all)
;;

*)
Expand Down Expand Up @@ -83,6 +82,7 @@ echo "uname -p: $(uname -p)"
echo "arch: $(arch)"
echo "PLATFORM: $PLATFORM"
echo "CARGO_FEATURES: $CARGO_FEATURES"
echo "INCLUDE_DEBUG: $INCLUDE_DEBUG"


################################################################################
Expand Down Expand Up @@ -121,12 +121,14 @@ cp -p "$CARGO_BUILD_DIR/noseyparker-cli" "$NP" || fatal "failed to copy ${NOSEYP
# Copy CHANGELOG.md, LICENSE, and README.md
cp -p CHANGELOG.md LICENSE README.md "$RELEASE_DIR/" || fatal "failed to copy assets"

################################################################################
# Strip release binary if requested
################################################################################
if (( $DO_STRIP )); then
banner "Stripping release binary"
$STRIP_COMMAND "$NP"
if (( $INCLUDE_DEBUG )); then
if [[ $PLATFORM == 'linux' ]]; then
cp -rp "$CARGO_BUILD_DIR/noseyparker-cli.dwp" "$NP.dwp" || fatal "failed to copy ${NOSEYPARKER}.dwp"
elif [[ $PLATFORM == 'macos' ]]; then
cp -rp "$CARGO_BUILD_DIR/noseyparker-cli.dSYM" "$NP.dSYM" || fatal "failed to copy ${NOSEYPARKER}.dSYM"
else
fatal "unknown platform $PLATFORM"
fi
fi

################################################################################
Expand Down

0 comments on commit a0633df

Please sign in to comment.