1#!/bin/bash 2 3# Run cargo_embargo with the appropriate arguments. 4 5set -e -u 6 7function usage() { echo "$0 [-r]" && exit 1; } 8CROSVM_DIR="$ANDROID_BUILD_TOP/external/crosvm" 9REUSE="" 10while getopts 'r' FLAG; do 11 case ${FLAG} in 12 r) 13 REUSE="--reuse-cargo-out --cargo-out-dir $CROSVM_DIR" 14 ;; 15 ?) 16 echo "unknown flag." 17 usage 18 ;; 19 esac 20done 21 22if ! [ -x "$(command -v bpfmt)" ]; then 23 echo 'Error: bpfmt not found.' >&2 24 exit 1 25fi 26 27# If there is need to verify installation of some packages, add them here in pkges. 28pkges=' 29libdrm-dev 30libcap-dev 31libepoxy-dev 32libwayland-dev 33meson 34pkg-config 35protobuf-compiler 36wayland-protocols 37' 38for pkg in $pkges; do 39 set +e; result="$(dpkg-query -W --showformat='${db:Status-Status}' "$pkg" 2>&1)"; set -e 40 if [ ! $? = 0 ] || [ ! "$result" = installed ]; then 41 echo $pkg' not found. Please install.' >&2 42 exit 1 43 fi 44done 45 46# Use the specific rust version that crosvm upstream expects. 47# 48# TODO: Consider reading the toolchain from external/crosvm/rust-toolchain 49# 50# TODO: Consider using android's prebuilt rust binaries. Currently doesn't work 51# because they try to incorrectly use system clang and llvm. 52RUST_TOOLCHAIN="1.77.2" 53rustup which --toolchain $RUST_TOOLCHAIN cargo || \ 54 rustup toolchain install $RUST_TOOLCHAIN 55CARGO_BIN="$(dirname $(rustup which --toolchain $RUST_TOOLCHAIN cargo))" 56 57cd "$CROSVM_DIR" 58 59if [ ! "$REUSE" ]; then 60 rm -f cargo.out cargo.metadata 61 rm -rf target.tmp || /bin/true 62fi 63 64set -x 65cargo_embargo $REUSE --cargo-bin "$CARGO_BIN" generate cargo_embargo.json 66set +x 67 68if [ ! "$REUSE" ]; then 69 rm -f cargo.out cargo.metadata 70 rm -rf target.tmp || /bin/true 71fi 72 73# Revert changes to Cargo.lock caused by cargo_embargo. 74# 75# Android diffs in Cargo.toml files can cause diffs in the Cargo.lock when 76# cargo_embargo runs. This didn't happen with cargo2android.py because it 77# ignored the lock file. 78git restore Cargo.lock 79