1#!/bin/sh -ex 2 3cd "$(dirname "$0")" 4 5die() { 6 echo "$@" >&2 7 exit 1 8} 9 10protoc_ver=$(protoc --version) 11case "$protoc_ver" in 12"libprotoc 3"*) ;; 13*) 14 die "you need to use protobuf 3 to regenerate .rs from .proto" 15 ;; 16esac 17 18cargo build --manifest-path=../protobuf-codegen/Cargo.toml 19cargo build --manifest-path=../protoc-bin-vendored/Cargo.toml --bin protoc-bin-which 20 21PROTOC=$(cargo run --manifest-path=../protoc-bin-vendored/Cargo.toml --bin protoc-bin-which) 22 23where_am_i=$( 24 cd .. 25 pwd 26) 27 28rm -rf tmp-generated 29mkdir tmp-generated 30 31case $(uname) in 32Linux) 33 exe_suffix="" 34 ;; 35MSYS_NT*) 36 exe_suffix=".exe" 37 ;; 38esac 39 40"$PROTOC" \ 41 --plugin=protoc-gen-rust="$where_am_i/target/debug/protoc-gen-rust$exe_suffix" \ 42 --rust_out tmp-generated \ 43 --rust_opt 'serde_derive=true inside_protobuf=true' \ 44 -I../proto \ 45 -I../protoc-bin-vendored/include \ 46 ../protoc-bin-vendored/include/google/protobuf/*.proto \ 47 ../protoc-bin-vendored/include/google/protobuf/compiler/* \ 48 ../proto/rustproto.proto 49 50mv tmp-generated/descriptor.rs tmp-generated/plugin.rs tmp-generated/rustproto.rs src/ 51mv tmp-generated/*.rs src/well_known_types/ 52( 53 cd src/well_known_types 54 exec >mod.rs 55 echo "// This file is generated. Do not edit" 56 echo '//! Generated code for "well known types"' 57 echo "//!" 58 echo "//! [This document](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf) describes these types." 59 60 mod_list() { 61 # shellcheck disable=SC2010 62 ls | grep -v mod.rs | sed -e 's,\.rs$,,' 63 } 64 65 echo 66 mod_list | sed -e 's,^,mod ,; s,$,;,' 67 68 echo 69 mod_list | while read -r mod; do 70 echo "pub use self::$mod::*;" 71 done 72) 73 74# vim: set ts=4 sw=4 et: 75