toys/fastapi-rs/build.sh

30 lines
659 B
Bash
Executable File

#!/usr/bin/env bash
#
# Build the executable with minimal size optimization
#
# Author: donkey <anjingyu_ws@foxmail.com>
readonly CUR_DIR=$(cd `dirname $0`; pwd)
# NOTE: please check the options in Cargo.toml
# [profile.release]
# strip = true
# opt-level = "z" # Optimize for size
# lto = true
# codegen-units = 1
pushd $CUR_DIR 1>/dev/null 2>&1
cargo build --release
if [ $? -eq 0 ]; then
# Do compression via UPX
if command -v "upx" 1>/dev/null 2>&1; then
mv target/release/fastapi ./
upx --best --lzma ./fastapi
else
echo "Please install UPX for smaller size: sudo apt install upx"
fi
fi
popd 1>/dev/null 2>&1