1#!/usr/bin/env bash 2 3# Copyright 2022 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Update the Rust protobufs on netsim-dev branch 18# 19# scripts/build_tools.sh 20# ninja -C objs netsimd 21# repo start proto-update 22# scripts/proto_update.sh 23# git add rust/proto 24# 25# You may need to install protobuf-compiler 26# 27# Linux: sudo apt-get install protobuf-compiler 28# Mac: brew install protobuf 29 30# Absolute path to tools/netsim using this scripts directory 31REPO=$(dirname $(readlink -f "$0"))/.. 32CARGO=$REPO/rust/proto/Cargo.toml 33 34 35# run protoc command to generate grpc proto rust files 36# Can not generate files by proto/build.rs because protoc-grpcio doesn't support protobuf v3 yet. 37# https://github.com/mtp401/protoc-grpcio/issues/41 38 39# Install compilers since the crates are not in AOSP 40# TODO: Add required crate mappings to work in netsim-dev 41export CARGO_HOME="" 42# Specify versions to use the correct protobuf version. 43cargo install protobuf-codegen --version 3.2.0 44cargo install grpcio-compiler --version 0.13.0 45 46PROTOC_CMD="protoc --rust_out=./rust/proto/src --grpc_out=./rust/proto/src\ 47 --plugin=protoc-gen-grpc=`which grpc_rust_plugin`\ 48 -I./proto -I../../external/protobuf/src\ 49 -I../../packages/modules/Bluetooth/tools/rootcanal/proto" 50$PROTOC_CMD ./proto/netsim/frontend.proto 51$PROTOC_CMD ./proto/netsim/packet_streamer.proto 52 53# Revert the generate proto files because they will be generatd by proto/build.rs. 54git checkout $REPO/rust/proto/src/packet_streamer.rs 55git checkout $REPO/rust/proto/src/frontend.rs 56rm $REPO/rust/proto/src/mod.rs 57 58# uncomment out lines 59sed -i 's/^##//g' $CARGO 60 61# depends on emu-master-dev branch 62export CARGO_HOME=$REPO/objs/rust/.cargo 63 64# For grpcio-sys 65export GRPCIO_SYS_GRPC_INCLUDE_PATH="$REPO/../../external/grpc/include" 66 67cd $REPO 68cargo build --manifest-path $CARGO 69 70# Undo changed to Cargo.toml 71git checkout $CARGO 72 73# The possible values are "linux" and "darwin". 74OS=$(uname | tr '[:upper:]' '[:lower:]') 75 76# Find the most recent rustfmt installed 77RUSTFMT=`ls -d ../../prebuilts/rust/$OS-x86/*/bin/rustfmt | tail -1` 78 79# Format rust code 80find $REPO/rust/proto -name '*.rs' -exec $RUSTFMT --files-with-diff {} \; 81 82rm rust/Cargo.lock 83