Skip to content

Commit 8da6126

Browse files
authoredFeb 28, 2022
Update grpc c core to 1.44.0 (tikv#558)
This PR also uses the same bindings for both (x86_64|aarch64)_(macos|linux). CI will check if it's OK to do so. This should make maintenance easier. Changes from tikv#539 is also included in this PR. Features use-bindgen is removed as it can be detected during compile time now. This PR also rename the secure features to boringssl for better understanding. And now only enabling openssl features will not download boringssl anymore. Close tikv#557. Close tikv#539. Signed-off-by: Jay Lee <BusyJayLee@gmail.com>
1 parent 5a7f3ac commit 8da6126

File tree

17 files changed

+665
-4540
lines changed

17 files changed

+665
-4540
lines changed
 

‎.github/workflows/ci.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ jobs:
9797
- uses: actions/checkout@v2
9898
- run: which cargo && cargo version && clang --version && openssl version
9999
- run: cargo xtask submodule
100-
- run: cargo build --no-default-features --features use-bindgen
101-
- run: cargo build --no-default-features --features "protobuf-codec use-bindgen"
102-
- run: cargo build --no-default-features --features "prost-codec use-bindgen"
100+
- run: env TEST_BIND=0 cargo xtask bindgen && git diff --exit-code HEAD
101+
- run: cargo xtask bindgen
102+
- run: cargo build --no-default-features
103+
- run: cargo build --no-default-features --features "protobuf-codec"
104+
- run: cargo build --no-default-features --features "prost-codec"
103105
- run: cargo build
104106
- run: cargo test --all
105107

‎Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ members = [
4141
exclude = ["xtask"]
4242

4343
[features]
44-
default = ["protobuf-codec", "secure", "use-bindgen"]
44+
default = ["protobuf-codec", "boringssl"]
45+
_secure = []
4546
protobuf-codec = ["protobuf"]
4647
prost-codec = ["prost", "bytes"]
47-
secure = ["grpcio-sys/secure"]
48-
openssl = ["secure", "grpcio-sys/openssl"]
49-
openssl-vendored = ["secure", "grpcio-sys/openssl-vendored"]
48+
boringssl = ["grpcio-sys/boringssl", "_secure"]
49+
openssl = ["_secure", "grpcio-sys/openssl"]
50+
openssl-vendored = ["_secure", "grpcio-sys/openssl-vendored"]
5051
no-omit-frame-pointer = ["grpcio-sys/no-omit-frame-pointer"]
51-
use-bindgen = ["grpcio-sys/use-bindgen"]
5252

5353
[badges]
5454
travis-ci = { repository = "tikv/grpc-rs" }

‎README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ This project is still under development. The following features with the check m
2929
- Rust >= 1.36.0
3030
- binutils >= 2.22
3131
- LLVM and Clang >= 3.9 if you need to generate bindings at compile time.
32-
- By default, the [secure feature](#feature-secure) is provided by boringssl. You can also use openssl instead by enabling [openssl feature](#feature-openssl).
3332

3433
For Linux and MacOS, you also need to install gcc 4.9+ (or clang) too.
3534

@@ -93,9 +92,9 @@ To include this project as a dependency:
9392
grpcio = "0.6"
9493
```
9594

96-
### Feature `secure`
95+
### Feature `boringssl`
9796

98-
`secure` feature enables support for TLS encryption and some authentication
97+
`boringssl` feature enables support for TLS encryption and some authentication
9998
mechanism. When you do not need it, for example when working in intranet,
10099
you can disable it by using the following configuration:
101100
```

‎grpc-sys/Cargo.toml

+12-9
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,24 @@ openssl-sys = { version = "0.9", optional = true, features = ["vendored"] }
5353
libz-sys = { version = "1.1.3", default-features = false, features = ["libc", "static"] }
5454

5555
[features]
56-
default = ["use-bindgen"]
57-
secure = ["boringssl-src"]
58-
openssl = ["secure"]
56+
# A hidden feature indicating that secure features should be enabled.
57+
_secure = []
58+
boringssl = ["boringssl-src", "_secure"]
59+
openssl = ["_secure"]
5960
openssl-vendored = ["openssl", "openssl-sys"]
6061
no-omit-frame-pointer = []
61-
# If this feature is disabled, bindgen will not be used and the previously generated bindings will
62-
# be compiled instead. This only work for the supported targets and will make compilation fails for
63-
# the other ones.
64-
use-bindgen = ["bindgen"]
62+
# A hidden feature that is used to force regenerating bindings.
63+
_gen-bindings = ["bindgen"]
64+
_list-package = []
65+
66+
[target.'cfg(not(all(any(target_os = "linux", target_os = "macos"), any(target_arch = "x86_64", target_arch = "aarch64"))))'.build-dependencies]
67+
bindgen = "0.59.0"
6568

6669
[build-dependencies]
6770
cc = "1.0"
6871
cmake = "0.1"
6972
pkg-config = "0.3"
7073
walkdir = "2.2.9"
7174
# Because of rust-lang/cargo#5237, bindgen should not be upgraded util a minor or major release.
72-
bindgen = { version = "0.57.0", default-features = false, optional = true, features = ["runtime"] }
73-
boringssl-src = { version = "0.4.0", optional = true }
75+
bindgen = { version = "0.59.0", default-features = false, optional = true, features = ["runtime"] }
76+
boringssl-src = { version = "0.5.0", optional = true }

‎grpc-sys/bindings/aarch64-unknown-linux-gnu-bindings.rs ‎grpc-sys/bindings/bindings.rs

+409-290
Large diffs are not rendered by default.

‎grpc-sys/bindings/x86_64-unknown-linux-gnu-bindings.rs

-4,106
This file was deleted.

‎grpc-sys/build.rs

+135-63
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3+
use std::collections::HashSet;
34
use std::env::VarError;
5+
use std::fs::File;
46
use std::io::prelude::*;
57
use std::io::BufReader;
68
use std::path::{Path, PathBuf};
@@ -10,24 +12,9 @@ use cmake::Config as CmakeConfig;
1012
use pkg_config::{Config as PkgConfig, Library};
1113
use walkdir::WalkDir;
1214

13-
const GRPC_VERSION: &str = "1.38.0";
15+
const GRPC_VERSION: &str = "1.44.0";
1416

15-
/// Following two arrays are generated by running pkg-config manually. We can
16-
/// also choose to run pkg-config at build time, but it will requires pkg-config
17-
/// in path, which is unfriendly for platforms like Windows.
18-
// grpc_unsecure.pc is not accurate, see also grpc/grpc#24512. Should also include "address_sorting", "upb", "cares", "z".
19-
#[rustfmt::skip]
20-
const COMMON_DEPS: &[&str] = &[
21-
"absl_bad_optional_access", "absl_bad_variant_access", "absl_base", "absl_city", "absl_civil_time",
22-
"absl_cord", "absl_debugging_internal", "absl_demangle_internal", "absl_exponential_biased",
23-
"absl_graphcycles_internal", "absl_hash", "absl_hashtablez_sampler", "absl_int128", "absl_log_severity",
24-
"absl_malloc_internal", "absl_raw_hash_set", "absl_raw_logging_internal", "absl_spinlock_wait",
25-
"absl_stacktrace", "absl_status", "absl_statusor", "absl_str_format_internal", "absl_strings",
26-
"absl_strings_internal", "absl_symbolize", "absl_synchronization", "absl_throw_delegate", "absl_time",
27-
"absl_time_zone", "absl_wyhash", "address_sorting", "cares", "gpr", "upb", "z",
28-
];
29-
const GRPC_DEPS: &[&str] = &["grpc", "re2"];
30-
const GRPC_UNSECURE_DEPS: &[&str] = &["grpc_unsecure"];
17+
include!("link-deps.rs");
3118

3219
fn probe_library(library: &str, cargo_metadata: bool) -> Library {
3320
match PkgConfig::new()
@@ -99,6 +86,68 @@ fn clean_up_stale_cache(cxx_compiler: String) {
9986
}
10087
}
10188

89+
/// List packages needed for linking in working directory.
90+
fn list_packages(dst: &Path) {
91+
env::set_var(
92+
"PKG_CONFIG_PATH",
93+
format!("{}/lib/pkgconfig", dst.display()),
94+
);
95+
let mut cfg = PkgConfig::new();
96+
cfg.print_system_cflags(false)
97+
.print_system_libs(false)
98+
.env_metadata(false)
99+
.cargo_metadata(false)
100+
.atleast_version(GRPC_VERSION);
101+
let grpc = cfg.probe("grpc").unwrap();
102+
let mut grpc_libs: HashSet<_> = grpc.libs.iter().cloned().collect();
103+
let grpc_unsecure = cfg.probe("grpc_unsecure").unwrap();
104+
let mut grpc_unsecure_libs: HashSet<_> = grpc_unsecure.libs.iter().cloned().collect();
105+
106+
// grpc_unsecure.pc is not accurate, see also grpc/grpc#24512. Should also include "address_sorting", "upb", "cares", "z".
107+
grpc_unsecure_libs.extend(
108+
["address_sorting", "upb", "cares", "z"]
109+
.iter()
110+
.map(|s| s.to_string()),
111+
);
112+
// There is no "rt" on Windows and MacOS.
113+
grpc_libs.remove("rt");
114+
grpc_unsecure_libs.remove("rt");
115+
116+
// ssl, crypto is managed by us according to different features.
117+
grpc_libs.remove("ssl");
118+
grpc_libs.remove("crypto");
119+
120+
let mut common_libs: Vec<_> = grpc_libs.intersection(&grpc_unsecure_libs).collect();
121+
let mut secure_only: Vec<_> = grpc_libs.difference(&grpc_unsecure_libs).collect();
122+
let mut unsecure_only: Vec<_> = grpc_unsecure_libs.difference(&grpc_libs).collect();
123+
124+
common_libs.sort();
125+
secure_only.sort();
126+
unsecure_only.sort();
127+
128+
let outputs = &[
129+
("COMMON_DEPS", common_libs),
130+
("GRPC_DEPS", secure_only),
131+
("GRPC_UNSECURE_DEPS", unsecure_only),
132+
];
133+
134+
let mut f = File::create("link-deps.rs").unwrap();
135+
f.write_all(
136+
b"/// Following two arrays are generated by running pkg-config manually. We can
137+
/// also choose to run pkg-config at build time, but it will requires pkg-config
138+
/// in path, which is unfriendly for platforms like Windows.
139+
",
140+
)
141+
.unwrap();
142+
for (name, libs) in outputs {
143+
writeln!(f, "const {}: &[&str] = &[", name).unwrap();
144+
for lib in libs {
145+
writeln!(f, "\"{}\",", lib).unwrap();
146+
}
147+
writeln!(f, "];").unwrap();
148+
}
149+
}
150+
102151
fn build_grpc(cc: &mut cc::Build, library: &str) {
103152
prepare_grpc();
104153

@@ -165,7 +214,7 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {
165214
}
166215

167216
// We don't need to generate install targets.
168-
config.define("gRPC_INSTALL", "false");
217+
config.define("gRPC_INSTALL", cfg!(feature = "_list-package").to_string());
169218
// We don't need to build csharp target.
170219
config.define("gRPC_BUILD_CSHARP_EXT", "false");
171220
// We don't need to build codegen target.
@@ -175,15 +224,16 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {
175224

176225
// `package` should only be set for secure feature, otherwise cmake will always search for
177226
// ssl library.
178-
if cfg!(feature = "secure") {
227+
if cfg!(feature = "_secure") {
179228
config.define("gRPC_SSL_PROVIDER", "package");
180229
}
181-
#[cfg(feature = "secure")]
230+
#[cfg(feature = "_secure")]
182231
if cfg!(feature = "openssl") {
183232
if cfg!(feature = "openssl-vendored") {
184233
config.register_dep("openssl");
185234
}
186235
} else {
236+
#[cfg(feature = "boringssl")]
187237
build_boringssl(&mut config);
188238
}
189239
if cfg!(feature = "no-omit-frame-pointer") {
@@ -193,7 +243,10 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {
193243
}
194244
// Uses zlib from libz-sys.
195245
setup_libz(&mut config);
196-
config.build_target(library).uses_cxx11().build()
246+
if !cfg!(feature = "_list-package") {
247+
config.build_target(library);
248+
}
249+
config.uses_cxx11().build()
197250
};
198251

199252
let lib_suffix = if target.contains("msvc") {
@@ -212,6 +265,10 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {
212265
}
213266
}
214267

268+
if cfg!(feature = "_list-package") {
269+
list_packages(&dst);
270+
}
271+
215272
let libs = if library.contains("unsecure") {
216273
GRPC_UNSECURE_DEPS
217274
} else {
@@ -221,7 +278,7 @@ fn build_grpc(cc: &mut cc::Build, library: &str) {
221278
println!("cargo:rustc-link-lib=static={}", l);
222279
}
223280

224-
if cfg!(feature = "secure") {
281+
if cfg!(feature = "_secure") {
225282
if cfg!(feature = "openssl") && !cfg!(feature = "openssl-vendored") {
226283
figure_ssl_path(&build_dir);
227284
} else {
@@ -260,7 +317,7 @@ fn figure_ssl_path(build_dir: &str) {
260317
println!("cargo:rustc-link-lib=crypto");
261318
}
262319

263-
#[cfg(feature = "secure")]
320+
#[cfg(feature = "boringssl")]
264321
fn build_boringssl(config: &mut CmakeConfig) {
265322
let boringssl_artifact = boringssl_src::Build::new().build();
266323
config.define(
@@ -304,11 +361,17 @@ fn get_env(name: &str) -> Option<String> {
304361

305362
// Generate the bindings to grpc C-core.
306363
// Try to disable the generation of platform-related bindings.
307-
#[cfg(feature = "use-bindgen")]
364+
#[cfg(any(
365+
feature = "_gen-bindings",
366+
not(all(
367+
any(target_os = "linux", target_os = "macos"),
368+
any(target_arch = "x86_64", target_arch = "aarch64")
369+
))
370+
))]
308371
fn bindgen_grpc(file_path: &Path) {
309372
// create a config to generate binding file
310373
let mut config = bindgen::Builder::default();
311-
if cfg!(feature = "secure") {
374+
if cfg!(feature = "_secure") {
312375
config = config.clang_arg("-DGRPC_SYS_SECURE");
313376
}
314377

@@ -350,22 +413,23 @@ fn bindgen_grpc(file_path: &Path) {
350413
.impl_debug(true)
351414
.size_t_is_usize(true)
352415
.disable_header_comment()
353-
.whitelist_function(r"\bgrpc_.*")
354-
.whitelist_function(r"\bgpr_.*")
355-
.whitelist_function(r"\bgrpcwrap_.*")
356-
.whitelist_var(r"\bGRPC_.*")
357-
.whitelist_type(r"\bgrpc_.*")
358-
.whitelist_type(r"\bgpr_.*")
359-
.whitelist_type(r"\bgrpcwrap_.*")
360-
.whitelist_type(r"\bcensus_context.*")
361-
.whitelist_type(r"\bverify_peer_options.*")
362-
.blacklist_type(r"(__)?pthread.*")
363-
.blacklist_function(r"\bgpr_mu_.*")
364-
.blacklist_function(r"\bgpr_cv_.*")
365-
.blacklist_function(r"\bgpr_once_.*")
366-
.blacklist_type(r"gpr_mu")
367-
.blacklist_type(r"gpr_cv")
368-
.blacklist_type(r"gpr_once")
416+
.allowlist_function(r"\bgrpc_.*")
417+
.allowlist_function(r"\bgpr_.*")
418+
.allowlist_function(r"\bgrpcwrap_.*")
419+
.allowlist_var(r"\bGRPC_.*")
420+
.allowlist_type(r"\bgrpc_.*")
421+
.allowlist_type(r"\bgpr_.*")
422+
.allowlist_type(r"\bgrpcwrap_.*")
423+
.allowlist_type(r"\bcensus_context.*")
424+
.allowlist_type(r"\bverify_peer_options.*")
425+
// Block all system headers.
426+
.blocklist_file(r"^/.*")
427+
.blocklist_function(r"\bgpr_mu_.*")
428+
.blocklist_function(r"\bgpr_cv_.*")
429+
.blocklist_function(r"\bgpr_once_.*")
430+
.blocklist_type(r"gpr_mu")
431+
.blocklist_type(r"gpr_cv")
432+
.blocklist_type(r"gpr_once")
369433
.constified_enum_module(r"grpc_status_code")
370434
.layout_tests(gen_tests)
371435
.default_enum_style(bindgen::EnumVariation::Rust {
@@ -379,38 +443,47 @@ fn bindgen_grpc(file_path: &Path) {
379443
}
380444

381445
// Determine if need to update bindings. Supported platforms do not
382-
// need to be updated by default unless the UPDATE_BIND is specified.
446+
// need to be updated by default unless the _gen-bindings feature is specified.
383447
// Other platforms use bindgen to generate the bindings every time.
384448
fn config_binding_path() {
385449
let target = env::var("TARGET").unwrap();
386450
let file_path: PathBuf = match target.as_str() {
387-
"x86_64-unknown-linux-gnu" | "aarch64-unknown-linux-gnu" => {
451+
"x86_64-unknown-linux-gnu"
452+
| "aarch64-unknown-linux-gnu"
453+
| "x86_64-apple-darwin"
454+
| "aarch64-apple-darwin" => {
388455
// Cargo treats nonexistent files changed, so we only emit the rerun-if-changed
389456
// directive when we expect the target-specific pre-generated binding file to be
390457
// present.
391-
println!("cargo:rerun-if-changed=bindings/{}-bindings.rs", &target);
458+
println!("cargo:rerun-if-changed=bindings/bindings.rs");
392459

393-
let file_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
460+
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
394461
.join("bindings")
395-
.join(format!("{}-bindings.rs", &target));
396-
397-
#[cfg(feature = "use-bindgen")]
398-
if env::var("UPDATE_BIND").is_ok() {
399-
bindgen_grpc(&file_path);
400-
}
401-
402-
file_path
403-
}
404-
_ => {
405-
let file_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("grpc-bindings.rs");
406-
407-
#[cfg(feature = "use-bindgen")]
408-
bindgen_grpc(&file_path);
409-
410-
file_path
462+
.join("bindings.rs")
411463
}
464+
_ => PathBuf::from(env::var("OUT_DIR").unwrap()).join("grpc-bindings.rs"),
412465
};
413466

467+
#[cfg(any(
468+
feature = "_gen-bindings",
469+
not(all(
470+
any(target_os = "linux", target_os = "macos"),
471+
any(target_arch = "x86_64", target_arch = "aarch64")
472+
))
473+
))]
474+
{
475+
// On some system (like Windows), stack size of main thread may
476+
// be too small.
477+
let f = file_path.clone();
478+
std::thread::Builder::new()
479+
.stack_size(8 * 1024 * 1024)
480+
.name("bindgen_grpc".to_string())
481+
.spawn(move || bindgen_grpc(&f))
482+
.unwrap()
483+
.join()
484+
.unwrap();
485+
}
486+
414487
println!(
415488
"cargo:rustc-env=BINDING_PATH={}",
416489
file_path.to_str().unwrap()
@@ -420,12 +493,11 @@ fn config_binding_path() {
420493
fn main() {
421494
println!("cargo:rerun-if-changed=grpc_wrap.cc");
422495
println!("cargo:rerun-if-changed=grpc");
423-
println!("cargo:rerun-if-env-changed=UPDATE_BIND");
424496

425497
// create a builder to compile grpc_wrap.cc
426498
let mut cc = cc::Build::new();
427499

428-
let library = if cfg!(feature = "secure") {
500+
let library = if cfg!(feature = "_secure") {
429501
cc.define("GRPC_SYS_SECURE", None);
430502
"grpc"
431503
} else {

‎grpc-sys/grpc

Submodule grpc updated from faa7a04 to d560d06

‎grpc-sys/grpc_wrap.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,16 @@ grpcwrap_request_call_context_create() {
118118
* Destroys array->metadata.
119119
* The array pointer itself is not freed.
120120
*/
121-
void grpcwrap_metadata_array_destroy_metadata_only(grpc_metadata_array* array) {
121+
GPR_EXPORT void grpcwrap_metadata_array_destroy_metadata_only(
122+
grpc_metadata_array* array) {
122123
gpr_free(array->metadata);
123124
}
124125

125126
/*
126127
* Destroys keys, values and array->metadata.
127128
* The array pointer itself is not freed.
128129
*/
129-
void grpcwrap_metadata_array_destroy_metadata_including_entries(
130+
GPR_EXPORT void grpcwrap_metadata_array_destroy_metadata_including_entries(
130131
grpc_metadata_array* array) {
131132
size_t i;
132133
if (array->metadata) {
@@ -221,8 +222,8 @@ grpcwrap_metadata_array_shrink_to_fit(grpc_metadata_array* array) {
221222
}
222223

223224
/* Move contents of metadata array */
224-
void grpcwrap_metadata_array_move(grpc_metadata_array* dest,
225-
grpc_metadata_array* src) {
225+
GPR_EXPORT void grpcwrap_metadata_array_move(grpc_metadata_array* dest,
226+
grpc_metadata_array* src) {
226227
if (!src) {
227228
dest->capacity = 0;
228229
dest->count = 0;

‎grpc-sys/link-deps.rs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/// Following two arrays are generated by running pkg-config manually. We can
2+
/// also choose to run pkg-config at build time, but it will requires pkg-config
3+
/// in path, which is unfriendly for platforms like Windows.
4+
const COMMON_DEPS: &[&str] = &[
5+
"absl_bad_optional_access",
6+
"absl_bad_variant_access",
7+
"absl_base",
8+
"absl_city",
9+
"absl_civil_time",
10+
"absl_cord",
11+
"absl_cord_internal",
12+
"absl_cordz_functions",
13+
"absl_cordz_handle",
14+
"absl_cordz_info",
15+
"absl_debugging_internal",
16+
"absl_demangle_internal",
17+
"absl_exponential_biased",
18+
"absl_graphcycles_internal",
19+
"absl_hash",
20+
"absl_hashtablez_sampler",
21+
"absl_int128",
22+
"absl_log_severity",
23+
"absl_low_level_hash",
24+
"absl_malloc_internal",
25+
"absl_random_distributions",
26+
"absl_random_internal_platform",
27+
"absl_random_internal_pool_urbg",
28+
"absl_random_internal_randen",
29+
"absl_random_internal_randen_hwaes",
30+
"absl_random_internal_randen_hwaes_impl",
31+
"absl_random_internal_randen_slow",
32+
"absl_random_internal_seed_material",
33+
"absl_random_seed_gen_exception",
34+
"absl_random_seed_sequences",
35+
"absl_raw_hash_set",
36+
"absl_raw_logging_internal",
37+
"absl_spinlock_wait",
38+
"absl_stacktrace",
39+
"absl_status",
40+
"absl_statusor",
41+
"absl_str_format_internal",
42+
"absl_strings",
43+
"absl_strings_internal",
44+
"absl_symbolize",
45+
"absl_synchronization",
46+
"absl_throw_delegate",
47+
"absl_time",
48+
"absl_time_zone",
49+
"address_sorting",
50+
"cares",
51+
"gpr",
52+
"upb",
53+
"z",
54+
];
55+
const GRPC_DEPS: &[&str] = &["grpc", "re2"];
56+
const GRPC_UNSECURE_DEPS: &[&str] = &["grpc_unsecure"];

‎health/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ categories = ["network-programming"]
1313
readme = "README.md"
1414

1515
[features]
16-
default = ["protobuf-codec", "use-bindgen"]
16+
default = ["protobuf-codec"]
1717
protobuf-codec = ["grpcio/protobuf-codec", "protobuf"]
1818
prost-codec = ["grpcio/prost-codec", "prost"]
19-
use-bindgen = ["grpcio/use-bindgen"]
2019

2120
[dependencies]
2221
futures-executor = "0.3"
2322
futures-util = { version = "0.3", default-features = false, features = ["std"] }
24-
grpcio = { path = "..", features = ["secure"], version = "0.9.0", default-features = false }
23+
grpcio = { path = "..", version = "0.9.0", default-features = false }
2524
prost = { version = "0.8", optional = true }
2625
protobuf = { version = "2", optional = true }
2726
log = "0.4"

‎proto/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ categories = ["network-programming"]
1313
build = "build.rs"
1414

1515
[features]
16-
default = ["protobuf-codec", "use-bindgen"]
16+
default = ["protobuf-codec"]
1717
protobuf-codec = ["grpcio/protobuf-codec", "protobuf-build/grpcio-protobuf-codec"]
1818
prost-codec = ["prost-derive", "prost-types", "bytes", "lazy_static", "grpcio/prost-codec", "prost", "protobuf-build/grpcio-prost-codec"]
19-
use-bindgen = ["grpcio/use-bindgen"]
2019

2120
[dependencies]
22-
grpcio = { path = "..", features = ["secure"], version = "0.9.0", default-features = false }
21+
grpcio = { path = "..", features = ["boringssl"], version = "0.9.0", default-features = false }
2322
bytes = { version = "1.0", optional = true }
2423
prost = { version = "0.8", optional = true }
2524
prost-derive = { version = "0.8", optional = true }

‎src/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl ChannelBuilder {
472472
}
473473
}
474474

475-
#[cfg(feature = "secure")]
475+
#[cfg(feature = "_secure")]
476476
mod secure_channel {
477477
use std::borrow::Cow;
478478
use std::ffi::CString;

‎src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ framework that puts mobile and HTTP/2 first. grpcio is built on [gRPC Core] and
1212
1313
## Optional features
1414
15-
- **`secure`** *(enabled by default)* - Enables support for TLS encryption and some authentication
15+
- **`boringssl`** *(enabled by default)* - Enables support for TLS encryption and some authentication
1616
mechanisms.
17+
- **`openssl`** - Same as `boringssl`, but base on the system openssl.
18+
- **`openssl-vendored`** - Same as `openssl`, but build openssl from source.
1719
1820
*/
1921

@@ -39,7 +41,7 @@ mod error;
3941
mod log_util;
4042
mod metadata;
4143
mod quota;
42-
#[cfg(feature = "secure")]
44+
#[cfg(feature = "_secure")]
4345
mod security;
4446
mod server;
4547
mod task;
@@ -73,7 +75,7 @@ pub use crate::error::{Error, Result};
7375
pub use crate::log_util::redirect_log;
7476
pub use crate::metadata::{Metadata, MetadataBuilder, MetadataIter};
7577
pub use crate::quota::ResourceQuota;
76-
#[cfg(feature = "secure")]
78+
#[cfg(feature = "_secure")]
7779
pub use crate::security::{
7880
CertificateRequestType, ChannelCredentials, ChannelCredentialsBuilder, ServerCredentials,
7981
ServerCredentialsBuilder, ServerCredentialsFetcher,

‎src/server.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn join_host_port(host: &str, port: u16) -> String {
7777
}
7878
}
7979

80-
#[cfg(feature = "secure")]
80+
#[cfg(feature = "_secure")]
8181
mod imp {
8282
use super::join_host_port;
8383
use crate::grpc_sys::{self, grpc_server};
@@ -135,7 +135,7 @@ mod imp {
135135
}
136136
}
137137

138-
#[cfg(not(feature = "secure"))]
138+
#[cfg(not(feature = "_secure"))]
139139
mod imp {
140140
use super::join_host_port;
141141
use crate::grpc_sys::{self, grpc_server};
@@ -396,7 +396,7 @@ impl ServerBuilder {
396396
}
397397
}
398398

399-
#[cfg(feature = "secure")]
399+
#[cfg(feature = "_secure")]
400400
mod secure_server {
401401
use super::{Binder, ServerBuilder};
402402
use crate::grpc_sys;

‎tests-and-examples/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protobuf = { version = "2.22", optional = true }
2121
prost = { version = "0.8", optional = true }
2222
bytes = { version = "1.0", optional = true }
2323
log = "0.4"
24-
grpcio = { path = "..", version = "0.9", default-features = false, features = ["secure"] }
24+
grpcio = { path = "..", version = "0.9", default-features = false, features = ["boringssl"] }
2525
grpcio-health = { path = "../health", version = "0.9", default-features = false }
2626

2727
[dev-dependencies]

‎xtask/src/main.rs

+21-42
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn print_help() {
1717
eprintln!("\tsubmodule\tInit necessary submodules for compilation");
1818
eprintln!("\tclang-lint\tLint cpp code in grpcio-sys package");
1919
eprintln!("\tcodegen\tGenerate rust code for all protocols");
20+
eprintln!("\trefresh-package\tRegenerate grpc-sys/link-deps.rs to show the latest linking dependencies.");
2021
}
2122

2223
fn cargo() -> Command {
@@ -30,29 +31,17 @@ fn cargo() -> Command {
3031
}
3132

3233
fn exec(c: &mut Command) {
33-
if let Err(e) = c.status() {
34-
eprintln!("failed to execute {:?}: {}", c, e);
35-
process::exit(-1);
36-
}
37-
}
38-
39-
fn find_default_arch() -> String {
40-
let s = String::from_utf8(
41-
Command::new("rustc")
42-
.args(&["--print", "cfg"])
43-
.output()
44-
.unwrap()
45-
.stdout,
46-
)
47-
.unwrap();
48-
for l in s.lines() {
49-
if let Some(arch) = l.strip_prefix("target_arch=") {
50-
if !arch.is_empty() {
51-
return arch[1..arch.len() - 1].to_string();
34+
match c.status() {
35+
Err(e) => {
36+
eprintln!("failed to execute {:?}: {}", c, e);
37+
process::exit(-1);
38+
}
39+
Ok(s) => {
40+
if !s.success() {
41+
process::exit(s.code().unwrap_or(-1));
5242
}
5343
}
5444
}
55-
panic!("arch not found in {:?}", s);
5645
}
5746

5847
fn remove_match(data: &str, pattern: impl Fn(&str) -> bool) -> String {
@@ -68,31 +57,11 @@ fn remove_match(data: &str, pattern: impl Fn(&str) -> bool) -> String {
6857
}
6958

7059
fn bindgen() {
71-
let arch = match env::var("ARCH") {
72-
Ok(arch) => arch,
73-
Err(_) => find_default_arch(),
74-
};
75-
let tuple = format!("{}-unknown-linux-gnu", arch);
7660
exec(
7761
cargo()
78-
.env("UPDATE_BIND", "1")
79-
.args(&["build", "-p", "grpcio-sys", "--target", &tuple]),
62+
.current_dir("grpc-sys")
63+
.args(&["build", "-p", "grpcio-sys", "--features", "_gen-bindings"]),
8064
);
81-
for f in fs::read_dir("grpc-sys/bindings").unwrap() {
82-
let p = f.unwrap().path();
83-
let mut content = String::new();
84-
File::open(&p)
85-
.unwrap()
86-
.read_to_string(&mut content)
87-
.unwrap();
88-
let content = remove_match(&content, |l| {
89-
l.starts_with("pub type ") && l.contains("= ::std::os::raw::")
90-
});
91-
File::create(&p)
92-
.unwrap()
93-
.write_all(content.as_bytes())
94-
.unwrap();
95-
}
9665
}
9766

9867
fn cmd(c: &str) -> Command {
@@ -264,6 +233,15 @@ fn codegen() {
264233
exec(cargo().args(&["fmt", "--all"]))
265234
}
266235

236+
fn refresh_link_package() {
237+
exec(
238+
cargo()
239+
.current_dir("grpc-sys")
240+
.args(&["build", "-p", "grpcio-sys", "--features", "_list-package"]),
241+
);
242+
exec(Command::new("rustfmt").args(&["grpc-sys/link-deps.rs"]));
243+
}
244+
267245
fn main() {
268246
let mut args = env::args();
269247
if args.len() != 2 {
@@ -277,6 +255,7 @@ fn main() {
277255
"submodule" => submodule(),
278256
"clang-lint" => clang_lint(),
279257
"codegen" => codegen(),
258+
"refresh-package" => refresh_link_package(),
280259
_ => print_help(),
281260
}
282261
}

0 commit comments

Comments
 (0)
Please sign in to comment.