1#!/bin/bash 2 3# Run cargo_embargo with the appropriate arguments. 4 5set -e -u 6 7function usage() { echo "$0 [-r]" && exit 1; } 8 9REUSE="" 10while getopts 'r' FLAG; do 11 case ${FLAG} in 12 r) 13 REUSE="--reuse-cargo-out" 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='meson protobuf-compiler' 29for pkg in $pkges; do 30 result="$(dpkg-query -W --showformat='${db:Status-Status}' "$pkg" 2>&1)" 31 if [ ! $? = 0 ] || [ ! "$result" = installed ]; then 32 echo $pkg' not found. Please install.' >&2 33 exit 1 34 fi 35done 36 37# Use the specific rust version that crosvm upstream expects. 38# 39# TODO: Consider reading the toolchain from external/crosvm/rust-toolchain 40# 41# TODO: Consider using android's prebuilt rust binaries. Currently doesn't work 42# because they try to incorrectly use system clang and llvm. 43RUST_TOOLCHAIN="1.73.0" 44rustup which --toolchain $RUST_TOOLCHAIN cargo || \ 45 rustup toolchain install $RUST_TOOLCHAIN 46CARGO_BIN="$(dirname $(rustup which --toolchain $RUST_TOOLCHAIN cargo))" 47 48cd $ANDROID_BUILD_TOP/external/crosvm 49 50if [ ! "$REUSE" ]; then 51 rm -f cargo.out cargo.metadata 52 rm -rf target.tmp || /bin/true 53fi 54 55set -x 56cargo_embargo $REUSE --cargo-bin "$CARGO_BIN" generate cargo_embargo.json 57set +x 58 59if [ ! "$REUSE" ]; then 60 rm -f cargo.out cargo.metadata 61 rm -rf target.tmp || /bin/true 62fi 63 64# Revert changes to Cargo.lock caused by cargo_embargo. 65# 66# Android diffs in Cargo.toml files can cause diffs in the Cargo.lock when 67# cargo_embargo runs. This didn't happen with cargo2android.py because it 68# ignored the lock file. 69git restore Cargo.lock 70