blob: a1e0dd9ad00a07e6f6c2df3a078564780cfee93e [file] [log] [blame]
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -07001#!/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 ../proto/google/protobuf/*.proto \
40 ../proto/google/protobuf/compiler/* \
41 ../proto/rustproto.proto
42
43mv tmp-generated/descriptor.rs tmp-generated/plugin.rs tmp-generated/rustproto.rs src/
44mv tmp-generated/*.rs src/well_known_types/
45(
46 cd src/well_known_types
47 exec > mod.rs
48 echo "// This file is generated. Do not edit"
49 echo '//! Generated code for "well known types"'
50 echo "//!"
51 echo "//! [This document](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf) describes these types."
52
53 mod_list() {
54 ls | grep -v mod.rs | sed -e 's,\.rs$,,'
55 }
56
57 echo
58 mod_list | sed -e 's,^,mod ,; s,$,;,'
59
60 echo
61 mod_list | while read mod; do
62 echo "pub use self::$mod::*;"
63 done
64)
65
66# vim: set ts=4 sw=4 et: