1
0
mirror of https://github.com/containers/youki synced 2024-11-29 21:11:29 +01:00
youki/scripts/build.sh
Toru Komatsu 464344923f
Name the test tools contest (#2486)
* Name the test tools `contest`

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a build error

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a workflow

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

---------

Signed-off-by: utam0k <k0ma@utam0k.jp>
2024-01-12 14:28:47 +05:30

91 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT=$(git rev-parse --show-toplevel)
HOST_TARGET=$(rustc -Vv | grep ^host: | cut -d' ' -f2)
usage_exit() {
echo "Usage: $0 [-r] [-o dir] [-c crate] [-f features] [-t target] [-x]" 1>&2
exit 1
}
VERSION=debug
CRATE="youki"
TARGET=${TARGET:-$HOST_TARGET}
CARGO=${CARGO:-}
features=""
while getopts f:ro:c:t:xh OPT; do
case $OPT in
f) features=${OPTARG}
;;
o) output=${OPTARG}
;;
r) VERSION=release
;;
c) CRATE=${OPTARG}
;;
t) TARGET=${OPTARG}
;;
x) CARGO=cross
;;
h) usage_exit
;;
\?) usage_exit
;;
esac
done
shift $((OPTIND - 1))
OPTION=""
if [ "${VERSION}" = release ]; then
OPTION="--release"
fi
# expand target shortcuts
case "$TARGET" in
musl)
TARGET="$(uname -m)-unknown-linux-musl"
;;
gnu|glibc)
TARGET="$(uname -m)-unknown-linux-gnu"
;;
arm64|aarch64)
TARGET="aarch64-unknown-linux-musl"
;;
amd64|x86_64)
TARGET="x86_64-unknown-linux-musl"
;;
esac
FEATURES=()
if [ -n "${features}" ]; then
FEATURES=("--features=${features}")
fi
echo "* FEATURES: ${features:-<default>}"
echo "* TARGET: ${TARGET}"
OUTPUT=${output:-$ROOT/bin}
mkdir -p "$OUTPUT"
CARGO_SH="$(dirname "$0")/cargo.sh"
export CARGO_BUILD_TARGET="$TARGET"
if [ "$CRATE" == "youki" ]; then
rm -f "${OUTPUT}/youki"
"$CARGO_SH" build ${OPTION} "${FEATURES[@]}" --bin youki
mv "$("$CARGO_SH" --print-target-dir)/${TARGET}/${VERSION}/youki" "${OUTPUT}/"
fi
if [ "$CRATE" == "contest" ]; then
find ${OUTPUT} -maxdepth 1 -type f -name "contest" -exec rm -ifv {} \;
"$CARGO_SH" build ${OPTION} "${FEATURES[@]}" --bin contest
mv ${ROOT}/target/${TARGET}/${VERSION}/contest ${OUTPUT}/
find ${OUTPUT} -maxdepth 1 -type f -name "runtimetest" -exec rm -ifv {} \;
CONTEST_TARGET="$ROOT/contest-target"
CARGO_TARGET_DIR=${CONTEST_TARGET} RUSTFLAGS="-Ctarget-feature=+crt-static" "$CARGO_SH" build ${OPTION} "${FEATURES[@]}" --bin runtimetest
mv ${CONTEST_TARGET}/${TARGET}/${VERSION}/runtimetest ${OUTPUT}/
fi