Skip to content

Instantly share code, notes, and snippets.

@donkey-hotei
Created November 3, 2018 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donkey-hotei/45b1842ff438053c70d57a9af730acaa to your computer and use it in GitHub Desktop.
Save donkey-hotei/45b1842ff438053c70d57a9af730acaa to your computer and use it in GitHub Desktop.
# This bash script contains shared logic that is used to parse
# command line arguments. It is meant to be sourced from within the
# build scripts.
# This script parses command line arguments and exposes variables such
# as $PROFILE, and $FEATURES.
#
# Variables:
#
# $PROFILE: Can contain "--release" or "". By default it is set to
# "--release".
# $FEATURES: Contains a value of a feature passed by "--feature foo",
# as "--feature foo". In case of no --feature switch is
# found in $@ then empty string is used.
#
# Example:
#
# $ source ./build_common.sh --release --feature foo
# $ echo $FEATURES
# --features foo
# $ echo $PROFILE
# --release
# Builds release profile unless specified other
PROFILE="--release"
# Features switch that will be passed to cargo in a docker container
FEATURES=""
# Parse arguemnmts
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--debug)
# Without this argument cargo builds dev binary by default
PROFILE=""
shift
;;
--release)
PROFILE="--release"
shift
;;
--features)
FEATURES="$2"
shift
shift
;;
*)
shift
;;
esac
done
# Prepare `--features $FOO` only if --features is passed to this script.
if [ "$FEATURES" != '' ]; then
# Add --features with the input provided
FEATURES="--features $FEATURES"
fi
#!/bin/bash
# Usage: ./linux_build_static [--debug] [--release]
#
# This script builds a static Linux binaries.
#
# Options:
# --debug (optional) Use debug profile
# --release (optional) Use release profile (default)
# --feature (optional) List of features to build
#
# Note: You may need to disable or modify selinux, or add $USER to docker group
# to be able to use `docker`.
set -eux
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
# Parse command line arguments
source $DIR/build_common.sh
RUST_TOOLCHAIN="stable"
CARGO_ROOT="$HOME/.cargo"
CARGO_GIT="$CARGO_ROOT/.git"
CARGO_REGISTRY="$CARGO_ROOT/registry"
RUST_MUSL_BUILDER="docker run --rm -it -v "$(pwd)":/home/rust/src -v $CARGO_GIT:/home/rust/.cargo/git -v $CARGO_REGISTRY:/home/rust/.cargo/registry ekidd/rust-musl-builder:$RUST_TOOLCHAIN"
$RUST_MUSL_BUILDER sudo chown -R rust:rust /home/rust/.cargo/git /home/rust/.cargo/registry
$RUST_MUSL_BUILDER cargo build --all ${PROFILE} ${FEATURES}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment