| #!/usr/bin/env bash |
| |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| set -eo pipefail |
| |
| usage() { |
| echo "usage: ${0} [options] {arm64, x64}" |
| echo |
| echo " -f [fuchsia-dir] Fuchsia directory (required)" |
| echo |
| exit 1 |
| } |
| |
| while getopts "f:" OPT; do |
| case $OPT in |
| f) FUCHSIA_DIR="${OPTARG}";; |
| esac |
| done |
| shift $((OPTIND - 1)) |
| |
| case "${1}" in |
| arm64) |
| ARCH="arm64" |
| TARGET="aarch64-unknown-linux-musl";; |
| x64) |
| ARCH="x64" |
| TARGET="x86_64-unknown-linux-musl";; |
| *) |
| usage;; |
| esac |
| |
| # If building ARM, ensure we have the correct toolchain installed. |
| if [ $ARCH = "arm64" ]; then |
| type aarch64-linux-gnu-gcc >/dev/null 2>/dev/null || { |
| echo "Required package gcc-aarch64-linux-gnu is not installed. To install" |
| echo "on Debian-based systems, run:" |
| echo |
| echo " sudo apt install gcc-aarch64-linux-gnu" |
| exit 1 |
| } |
| fi |
| |
| declare -r OUT_DIR="out/${ARCH}" |
| declare -r IMAGE_FILE="out/linux-tests-${ARCH}.img" |
| |
| if [ ! -d "rust_crates" ]; then |
| if [ ! -d "${FUCHSIA_DIR}" ]; then |
| echo "Must specifiy Fuchsia directory on first run." |
| usage |
| fi |
| |
| ln -s ${FUCHSIA_DIR}/third_party/rust_crates/ rust_crates |
| fi |
| |
| cargo build --target=${TARGET} |
| |
| mkdir -p ${OUT_DIR} |
| cp target/${TARGET}/debug/virtio_block_test_util ${OUT_DIR} |
| cp target/${TARGET}/debug/virtio_input_test_util ${OUT_DIR} |
| cp target/${TARGET}/debug/virtio_net_test_util ${OUT_DIR} |
| cp target/${TARGET}/debug/virtio_rng_test_util ${OUT_DIR} |
| cp target/${TARGET}/debug/virtio_vsock_test_util ${OUT_DIR} |
| |
| declare -r BLOCK_SIZE=4096 |
| declare -r ADDITIONAL_BLOCKS=1024 |
| declare -r SIZE=$(du -sb ${OUT_DIR} | grep -o '^[0-9]*') |
| declare -r BLOCKS=$(($((${SIZE}/${BLOCK_SIZE}))+${ADDITIONAL_BLOCKS})) |
| rm -f "${IMAGE_FILE}" |
| mke2fs -q -d "${OUT_DIR}" -t ext2 -b ${BLOCK_SIZE} "${IMAGE_FILE}" ${BLOCKS} |