Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 1 | #!/bin/sh -ex |
| 2 | |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 3 | cd "$(dirname "$0")" |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 4 | |
| 5 | die() { |
| 6 | echo "$@" >&2 |
| 7 | exit 1 |
| 8 | } |
| 9 | |
| 10 | protoc_ver=$(protoc --version) |
| 11 | case "$protoc_ver" in |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 12 | "libprotoc 3"*) ;; |
| 13 | *) |
| 14 | die "you need to use protobuf 3 to regenerate .rs from .proto" |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 15 | ;; |
| 16 | esac |
| 17 | |
| 18 | cargo build --manifest-path=../protobuf-codegen/Cargo.toml |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 19 | cargo build --manifest-path=../protoc-bin-vendored/Cargo.toml --bin protoc-bin-which |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 20 | |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 21 | PROTOC=$(cargo run --manifest-path=../protoc-bin-vendored/Cargo.toml --bin protoc-bin-which) |
| 22 | |
| 23 | where_am_i=$( |
| 24 | cd .. |
| 25 | pwd |
| 26 | ) |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 27 | |
| 28 | rm -rf tmp-generated |
| 29 | mkdir tmp-generated |
| 30 | |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 31 | case $(uname) in |
| 32 | Linux) |
| 33 | exe_suffix="" |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 34 | ;; |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 35 | MSYS_NT*) |
| 36 | exe_suffix=".exe" |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 37 | ;; |
| 38 | esac |
| 39 | |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 40 | "$PROTOC" \ |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 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 \ |
Haibo Huang | ca95bfd | 2021-02-09 17:48:30 -0800 | [diff] [blame] | 45 | -I../protoc-bin-vendored/include \ |
| 46 | ../protoc-bin-vendored/include/google/protobuf/*.proto \ |
| 47 | ../protoc-bin-vendored/include/google/protobuf/compiler/* \ |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 48 | ../proto/rustproto.proto |
| 49 | |
| 50 | mv tmp-generated/descriptor.rs tmp-generated/plugin.rs tmp-generated/rustproto.rs src/ |
| 51 | mv tmp-generated/*.rs src/well_known_types/ |
| 52 | ( |
| 53 | cd src/well_known_types |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 54 | exec >mod.rs |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 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() { |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 61 | # shellcheck disable=SC2010 |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 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 |
David LeGare | 793d84b | 2022-03-02 16:21:10 +0000 | [diff] [blame] | 69 | mod_list | while read -r mod; do |
Chih-Hung Hsieh | cfc3a23 | 2020-06-10 20:13:05 -0700 | [diff] [blame] | 70 | echo "pub use self::$mod::*;" |
| 71 | done |
| 72 | ) |
| 73 | |
| 74 | # vim: set ts=4 sw=4 et: |