blob: 01734969776945428dbde874ab7400770b1e85d9 [file] [log] [blame]
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -07001#!/bin/sh -ex
2
David LeGare793d84b2022-03-02 16:21:10 +00003cd "$(dirname "$0")"
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -07004
5die() {
6 echo "$@" >&2
7 exit 1
8}
9
10protoc_ver=$(protoc --version)
11case "$protoc_ver" in
David LeGare793d84b2022-03-02 16:21:10 +000012"libprotoc 3"*) ;;
13*)
14 die "you need to use protobuf 3 to regenerate .rs from .proto"
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070015 ;;
16esac
17
18cargo build --manifest-path=../protobuf-codegen/Cargo.toml
David LeGare793d84b2022-03-02 16:21:10 +000019cargo build --manifest-path=../protoc-bin-vendored/Cargo.toml --bin protoc-bin-which
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070020
David LeGare793d84b2022-03-02 16:21:10 +000021PROTOC=$(cargo run --manifest-path=../protoc-bin-vendored/Cargo.toml --bin protoc-bin-which)
22
23where_am_i=$(
24 cd ..
25 pwd
26)
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070027
28rm -rf tmp-generated
29mkdir tmp-generated
30
David LeGare793d84b2022-03-02 16:21:10 +000031case $(uname) in
32Linux)
33 exe_suffix=""
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070034 ;;
David LeGare793d84b2022-03-02 16:21:10 +000035MSYS_NT*)
36 exe_suffix=".exe"
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070037 ;;
38esac
39
David LeGare793d84b2022-03-02 16:21:10 +000040"$PROTOC" \
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070041 --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 \
Haibo Huangca95bfd2021-02-09 17:48:30 -080045 -I../protoc-bin-vendored/include \
46 ../protoc-bin-vendored/include/google/protobuf/*.proto \
47 ../protoc-bin-vendored/include/google/protobuf/compiler/* \
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070048 ../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
David LeGare793d84b2022-03-02 16:21:10 +000054 exec >mod.rs
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070055 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() {
David LeGare793d84b2022-03-02 16:21:10 +000061 # shellcheck disable=SC2010
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070062 ls | grep -v mod.rs | sed -e 's,\.rs$,,'
63 }
64
65 echo
66 mod_list | sed -e 's,^,mod ,; s,$,;,'
67
68 echo
David LeGare793d84b2022-03-02 16:21:10 +000069 mod_list | while read -r mod; do
Chih-Hung Hsiehcfc3a232020-06-10 20:13:05 -070070 echo "pub use self::$mod::*;"
71 done
72)
73
74# vim: set ts=4 sw=4 et: