Skip to content

Commit 98f781a

Browse files
authored
*: use xtask workflow (tikv#522)
This PR removes all scripts for maintaining the project. Instead, introduce [xtask][1] workflow to whole process more portable and rusty. It also introduces a new workflow named codegen to generate code for health crate. [1]: https://github.com/matklad/cargo-xtask Signed-off-by: Jay Lee <[email protected]>
1 parent f1d5723 commit 98f781a

20 files changed

+401
-163
lines changed

.cargo/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[alias]
2+
xtask = "run --manifest-path ./xtask/Cargo.toml --"

.github/workflows/ci.yml

+13-11
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ jobs:
2222
- run: sudo apt-get install -y clang-tidy-9
2323
- run: sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-9 100
2424
- run: which go && go version && which cargo && cargo version && clang --version && openssl version && which cmake && cmake --version
25-
- run: scripts/reset-submodule.cmd
25+
- run: cargo xtask submodule
2626
- run: cargo fmt --all -- --check
2727
- run: cargo clippy --all -- -D clippy::all && cargo clippy --all --no-default-features --features prost-codec -- -D clippy::all
28-
- run: scripts/lint-grpc-sys.sh && git diff-index --quiet HEAD
28+
- run: cargo xtask clang-lint && git diff-index --quiet HEAD
2929

3030
Linux-Stable:
3131
name: Linux-Stable
3232
runs-on: ubuntu-latest
3333
steps:
3434
- uses: actions/checkout@v2
35+
- run: sudo apt install -y protobuf-compiler
3536
- run: which go && go version && which cargo && cargo version && clang --version && openssl version
36-
- run: scripts/reset-submodule.cmd
37-
- run: env TEST_BIND=0 scripts/generate-bindings.sh && git diff --exit-code HEAD
38-
- run: scripts/generate-bindings.sh
37+
- run: cargo xtask submodule
38+
- run: env TEST_BIND=0 cargo xtask bindgen && git diff --exit-code HEAD
39+
- run: cargo xtask codegen && git diff --exit-code HEAD;
40+
- run: cargo xtask bindgen
3941
- run: cargo build --no-default-features
4042
- run: cargo build --no-default-features --features protobuf-codec
4143
- run: cargo build --no-default-features --features prost-codec
@@ -49,7 +51,7 @@ jobs:
4951
steps:
5052
- uses: actions/checkout@v2
5153
- run: which go && go version && which cargo && cargo version && clang --version && openssl version
52-
- run: scripts/reset-submodule.cmd
54+
- run: cargo xtask submodule
5355
- run: cargo test --features "openssl-vendored" --all
5456
- run: cargo clean
5557
- run: cargo test --features "openssl" --all
@@ -61,7 +63,7 @@ jobs:
6163
- uses: actions/checkout@v2
6264
- run: rustup default nightly
6365
- run: which go && go version && which cargo && cargo version && clang --version && openssl version
64-
- run: scripts/reset-submodule.cmd
66+
- run: cargo xtask submodule
6567
- run: cargo build --no-default-features
6668
- run: cargo build --no-default-features --features protobuf-codec
6769
- run: cargo build --no-default-features --features prost-codec
@@ -75,7 +77,7 @@ jobs:
7577
steps:
7678
- uses: actions/checkout@v2
7779
- run: which go && go version && which cargo && cargo version && clang --version && openssl version
78-
- run: scripts/reset-submodule.cmd
80+
- run: cargo xtask submodule
7981
- run: cargo build --no-default-features --features use-bindgen
8082
- run: cargo build --no-default-features --features "protobuf-codec use-bindgen"
8183
- run: cargo build --no-default-features --features "prost-codec use-bindgen"
@@ -89,7 +91,7 @@ jobs:
8991
- uses: actions/checkout@v2
9092
- run: brew update && brew upgrade [email protected]
9193
- run: which go && go version && which cargo && cargo version && clang --version && openssl version
92-
- run: scripts/reset-submodule.cmd
94+
- run: cargo xtask submodule
9395
- run: OPENSSL_ROOT_DIR="/usr/local/opt/[email protected]/" cargo test --features "openssl" --all
9496
- run: cargo test --features "openssl-vendored" --all
9597

@@ -103,7 +105,7 @@ jobs:
103105
- run: choco install -y llvm
104106
- run: refreshenv
105107
- run: go version ; cargo version ; cmake --version
106-
- run: scripts/reset-submodule.cmd
108+
- run: cargo xtask submodule
107109
- run: cargo build
108110
- run: cargo test --all
109111

@@ -112,7 +114,7 @@ jobs:
112114
runs-on: ubuntu-latest
113115
steps:
114116
- uses: actions/checkout@v2
115-
- run: scripts/reset-submodule.cmd
117+
- run: cargo xtask submodule
116118
- run: cd grpc-sys && cargo publish --dry-run
117119
- name: Check generated package size
118120
run: |

.travis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ jobs:
2929
arch: arm64-graviton2
3030
vm: virt
3131
before_script:
32-
- scripts/reset-submodule.cmd
32+
- cargo xtask submodule
3333
- export GRPC_VERSION=1.35.0
3434
- export PATH="$PATH:$HOME/.cache/bin:$HOME/.cargo/bin"
3535
- which cmake && cmake --version && openssl version
3636
- eval "$(gimme stable)"
3737
script:
3838
- if [[ $TRAVIS_OS_NAME == "linux" ]] && [[ $TRAVIS_RUST_VERSION == "stable" ]]; then
3939
rustup component add rustfmt && cargo fmt --all -- --check;
40-
env TEST_BIND=0 scripts/generate-bindings.sh && git diff --exit-code HEAD;
40+
env TEST_BIND=0 cargo xtask bindgen && git diff --exit-code HEAD;
4141
fi
42-
- ./scripts/generate-bindings.sh
42+
- cargo xtask bindgen
4343
- cargo build --no-default-features
4444
- cargo build --no-default-features --features protobuf-codec
4545
- cargo build --no-default-features --features prost-codec
@@ -49,7 +49,7 @@ jobs:
4949
arch: arm64-graviton2
5050
vm: virt
5151
before_script:
52-
- scripts/reset-submodule.cmd
52+
- cargo xtask submodule
5353
- export GRPC_VERSION=1.35.0
5454
- export PATH="$PATH:$HOME/.cache/bin:$HOME/.cargo/bin"
5555
- sudo apt-get update && sudo apt-get -y install libssl-dev

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ members = [
3333
"compiler",
3434
"health",
3535
"interop",
36-
"tests-and-examples"
36+
"tests-and-examples",
3737
]
38+
# Don't include it in workspace to make it possible to use different version of
39+
# rust-protobuf.
40+
exclude = ["xtask"]
3841

3942
[features]
4043
default = ["protobuf-codec", "secure", "use-bindgen"]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ For Windows, you also need to install following software:
4444
## Build
4545

4646
```
47-
$ ./scripts/reset-submodule.cmd # if you just cloned the repository
47+
$ cargo xtask submodule # if you just cloned the repository
4848
$ cargo build
4949
```
5050

@@ -142,5 +142,5 @@ Make sure to format and test the code before sending a PR.
142142
If the content in grpc-sys/grpc is updated, you may need to regenerate bindings:
143143

144144
```
145-
$ ./scripts/generate-bindings.sh
145+
$ cargo xtask bindgen
146146
```

compiler/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ tempfile = { version = "3.0", optional = true }
2727
[[bin]]
2828
name = "grpc_rust_plugin"
2929
required-features = ["protobuf-codec"]
30+
31+
[[bin]]
32+
name = "grpc_rust_prost"
33+
required-features = ["prost-codec"]

compiler/src/bin/grpc_rust_prost.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.
2+
3+
extern crate grpcio_compiler;
4+
5+
use grpcio_compiler::prost_codegen;
6+
7+
fn main() {
8+
prost_codegen::protoc_gen_grpc_rust_main();
9+
}

compiler/src/prost_codegen.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::io::{Error, ErrorKind, Read};
44
use std::path::Path;
5-
use std::{fs, io, process::Command};
5+
use std::{env, fs, io, process::Command, str};
66

77
use derive_new::new;
88
use prost::Message;
@@ -536,3 +536,22 @@ fn generate_method_bind(service_name: &str, method: &Method, buf: &mut String) {
536536
buf.push_str(&method.name);
537537
buf.push_str("(ctx, req, resp));\n");
538538
}
539+
540+
pub fn protoc_gen_grpc_rust_main() {
541+
let mut args = env::args();
542+
args.next();
543+
let (mut protos, mut includes, mut out_dir): (Vec<_>, Vec<_>, _) = Default::default();
544+
for arg in args {
545+
if let Some(value) = arg.strip_prefix("--protos=") {
546+
protos.extend(value.split(",").map(|s| s.to_string()));
547+
} else if let Some(value) = arg.strip_prefix("--includes=") {
548+
includes.extend(value.split(",").map(|s| s.to_string()));
549+
} else if let Some(value) = arg.strip_prefix("--out-dir=") {
550+
out_dir = value.to_string();
551+
}
552+
}
553+
if protos.is_empty() {
554+
panic!("should at least specify protos to generate");
555+
}
556+
compile_protos(&protos, &includes, &out_dir).unwrap();
557+
}

grpc-sys/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn get_env(name: &str) -> Option<String> {
299299
// Generate the bindings to grpc C-core.
300300
// Try to disable the generation of platform-related bindings.
301301
#[cfg(feature = "use-bindgen")]
302-
fn bindgen_grpc(file_path: &PathBuf) {
302+
fn bindgen_grpc(file_path: &Path) {
303303
// create a config to generate binding file
304304
let mut config = bindgen::Builder::default();
305305
if cfg!(feature = "secure") {

health/src/proto.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
#[cfg(feature = "prost-codec")]
44
mod reexports {
5-
include!("proto/grpc.health.v1.rs");
5+
include!("proto/prost/grpc.health.v1.rs");
66

77
pub use self::health_check_response::ServingStatus;
88
}
99

1010
#[cfg(feature = "protobuf-codec")]
11-
#[allow(deprecated)]
12-
mod health;
13-
#[cfg(feature = "protobuf-codec")]
14-
mod health_grpc;
11+
mod protobuf {
12+
#[allow(deprecated)]
13+
pub mod health;
14+
pub mod health_grpc;
15+
}
1516
#[cfg(feature = "protobuf-codec")]
1617
mod reexports {
17-
pub use super::health::*;
18-
pub use HealthCheckResponseServingStatus as ServingStatus;
18+
pub use super::protobuf::health::*;
19+
pub use super::protobuf::health_grpc::*;
1920
}
2021

2122
pub use self::reexports::*;
File renamed without changes.

0 commit comments

Comments
 (0)