• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Use the specific rust version that crosvm upstream expects.
28#
29# TODO: Consider reading the toolchain from external/crosvm/rust-toolchain
30#
31# TODO: Consider using android's prebuilt rust binaries. Currently doesn't work
32# because they try to incorrectly use system clang and llvm.
33RUST_TOOLCHAIN="1.65.0"
34rustup which --toolchain $RUST_TOOLCHAIN cargo || \
35  rustup toolchain install $RUST_TOOLCHAIN
36CARGO_BIN="$(dirname $(rustup which --toolchain $RUST_TOOLCHAIN cargo))"
37
38cd $ANDROID_BUILD_TOP/external/crosvm
39
40if [ ! "$REUSE" ]; then
41  rm -f cargo.out cargo.metadata
42  rm -rf target.tmp || /bin/true
43fi
44
45set -x
46cargo_embargo --cfg cargo_embargo.json $REUSE --cargo-bin "$CARGO_BIN"
47set +x
48
49if [ ! "$REUSE" ]; then
50  rm -f cargo.out cargo.metadata
51  rm -rf target.tmp || /bin/true
52fi
53
54# Revert changes to Cargo.lock caused by cargo_embargo.
55#
56# Android diffs in Cargo.toml files can cause diffs in the Cargo.lock when
57# cargo_embargo runs. This didn't happen with cargo2android.py because it
58# ignored the lock file.
59git restore Cargo.lock
60
61# Fix workstation specific path in "metrics" crate's generated files.
62# TODO(b/232150148): Find a better solution for protobuf generated files.
63sed --in-place 's/path = ".*\/out/path = "./' metrics/out/generated.rs
64