Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Lee <[email protected]>
  • Loading branch information
BusyJay committed Feb 25, 2022
1 parent c4b337c commit 4625473
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 43 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ default = ["protobuf-codec", "boringssl"]
_secure = []
protobuf-codec = ["protobuf"]
prost-codec = ["prost", "bytes"]
# Perhaps should rename to boringssl
boringssl = ["grpcio-sys/boringssl", "_secure"]
openssl = ["_secure", "grpcio-sys/openssl"]
openssl-vendored = ["_secure", "grpcio-sys/openssl-vendored"]
Expand Down
13 changes: 12 additions & 1 deletion grpc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,18 @@ fn config_binding_path() {
any(target_arch = "x86_64", target_arch = "aarch64")
))
))]
bindgen_grpc(&file_path);
{
// On some system (like Windows), stack size of main thread may
// be too small.
let f = file_path.clone();
std::thread::Builder::new()
.stack_size(8 * 1024 * 1024)
.name("bindgen_grpc".to_string())
.spawn(move || bindgen_grpc(&f))
.unwrap()
.join()
.unwrap();
}

println!(
"cargo:rustc-env=BINDING_PATH={}",
Expand Down
50 changes: 9 additions & 41 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,17 @@ fn cargo() -> Command {
}

fn exec(c: &mut Command) {
if let Err(e) = c.status() {
eprintln!("failed to execute {:?}: {}", c, e);
process::exit(-1);
}
}

fn find_default_arch() -> String {
let s = String::from_utf8(
Command::new("rustc")
.args(&["--print", "cfg"])
.output()
.unwrap()
.stdout,
)
.unwrap();
for l in s.lines() {
if let Some(arch) = l.strip_prefix("target_arch=") {
if !arch.is_empty() {
return arch[1..arch.len() - 1].to_string();
match c.status() {
Err(e) => {
eprintln!("failed to execute {:?}: {}", c, e);
process::exit(-1);
}
Ok(s) => {
if !s.success() {
process::exit(s.code().unwrap_or(-1));
}
}
}
panic!("arch not found in {:?}", s);
}

fn remove_match(data: &str, pattern: impl Fn(&str) -> bool) -> String {
Expand All @@ -68,31 +56,11 @@ fn remove_match(data: &str, pattern: impl Fn(&str) -> bool) -> String {
}

fn bindgen() {
let arch = match env::var("ARCH") {
Ok(arch) => arch,
Err(_) => find_default_arch(),
};
let tuple = format!("{}-unknown-linux-gnu", arch);
exec(
cargo()
.current_dir("grpc-sys")
.args(&["build", "-p", "grpcio-sys", "--target", &tuple, "--features", "_gen-bindings"]),
.args(&["build", "-p", "grpcio-sys", "--features", "_gen-bindings"]),
);
for f in fs::read_dir("grpc-sys/bindings").unwrap() {
let p = f.unwrap().path();
let mut content = String::new();
File::open(&p)
.unwrap()
.read_to_string(&mut content)
.unwrap();
let content = remove_match(&content, |l| {
l.starts_with("pub type ") && l.contains("= ::std::os::raw::")
});
File::create(&p)
.unwrap()
.write_all(content.as_bytes())
.unwrap();
}
}

fn cmd(c: &str) -> Command {
Expand Down

0 comments on commit 4625473

Please sign in to comment.