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 19 20where_am_i=$(cd ..; pwd) 21 22rm -rf tmp-generated 23mkdir tmp-generated 24 25case `uname` in 26 Linux) 27 exe_suffix="" 28 ;; 29 MSYS_NT*) 30 exe_suffix=".exe" 31 ;; 32esac 33 34protoc \ 35 --plugin=protoc-gen-rust="$where_am_i/target/debug/protoc-gen-rust$exe_suffix" \ 36 --rust_out tmp-generated \ 37 --rust_opt 'serde_derive=true inside_protobuf=true' \ 38 -I../proto \ 39 -I../protoc-bin-vendored/include \ 40 ../protoc-bin-vendored/include/google/protobuf/*.proto \ 41 ../protoc-bin-vendored/include/google/protobuf/compiler/* \ 42 ../proto/rustproto.proto 43 44mv tmp-generated/descriptor.rs tmp-generated/plugin.rs tmp-generated/rustproto.rs src/ 45mv tmp-generated/*.rs src/well_known_types/ 46( 47 cd src/well_known_types 48 exec > mod.rs 49 echo "// This file is generated. Do not edit" 50 echo '//! Generated code for "well known types"' 51 echo "//!" 52 echo "//! [This document](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf) describes these types." 53 54 mod_list() { 55 ls | grep -v mod.rs | sed -e 's,\.rs$,,' 56 } 57 58 echo 59 mod_list | sed -e 's,^,mod ,; s,$,;,' 60 61 echo 62 mod_list | while read mod; do 63 echo "pub use self::$mod::*;" 64 done 65) 66 67# vim: set ts=4 sw=4 et: 68