Skip to content

Commit

Permalink
Use strip and upx to compress binary for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowee committed Sep 22, 2019
1 parent 1cbafd8 commit e4d4215
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Based on the "trust" template v0.1.2
# https://github.com/japaric/trust/tree/v0.1.2

dist: trusty
dist: bionic
language: rust
rust:
- nightly-2019-08-21
Expand All @@ -13,6 +13,8 @@ env:
# TODO Update this to match the name of your project.
- CRATE_NAME=intray

# TODO: DISABLE_TEST is unnecessary
# because only one target is built regardless of tags.
matrix:
include:
# Android
Expand Down Expand Up @@ -74,9 +76,10 @@ matrix:

# *BSD
# - if: tag IS present
# env: TARGET=i686-unknown-freebsd DISABLE_TEST=1
- if: tag IS present
env: TARGET=x86_64-unknown-freebsd DISABLE_TEST=1
# env: TARGET=i686-unknown-freebsd DISABLE_TEST=1
# TODO: there seems to be a bug in Rust currently, disabled this target
# - if: tag IS present
# env: TARGET=x86_64-unknown-freebsd DISABLE_TEST=1
# - env: TARGET=x86_64-unknown-netbsd DISABLE_TEST=1

# Windows
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions ci/before_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#!/bin/bash
# This script takes care of building your crate and packaging it for release

set -ex

try_compress() {
file=$1
target=$(objdump -a $file | grep -oP "(?<=format )[\w-]+" | tr -d '\n' || "")
if [ -n "$target" ] && strip -v $file --target $target; then
echo "Stripped $file (target: $target)."
fi
if upx $file; then
echo "Upx $file done."
fi
}

main() {
local src=$(pwd) \
stage=
Expand All @@ -19,7 +30,14 @@ main() {

cross rustc --bin $CRATE_NAME --target $TARGET --release -- -C lto

cp target/$TARGET/release/$CRATE_NAME $src/$CRATE_NAME-$TARGET
if [ $TARGET = x86_64-pc-windows-gnu ]; then
suffix=".exe"
else
suffix=""
fi
origin=target/$TARGET/release/$CRATE_NAME$suffix
try_compress $origin
cp $origin $src/$CRATE_NAME-$TARGET$suffix
# cp target/$TARGET/release/$CRATE_NAME $stage/

# cd $stage
Expand Down

0 comments on commit e4d4215

Please sign in to comment.