Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont modify the source dir during code generation from proto file #45

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ledger-transport-zemu/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "ledger-transport-zemu"
description = "Ledger Zemu Wallet - Zemu Transport"
description = "Ledger Hardware Wallet - Zemu Transport"
version = "0.7.0"
license = "Apache-2.0"
authors = ["Linfeng Yuan <linfeng@crypto.com>"]
homepage = "https://github.com/zondax/ledger-rs"
repository = "https://github.com/zondax/ledger-rs"
readme = "README.md"
categories = ["authentication", "cryptography", "zemu"]
categories = ["authentication", "cryptography"]
keywords = ["ledger", "nano", "blue", "apdu", "zemu"]
edition = "2018"
autobenches = false
Expand All @@ -31,4 +31,5 @@ ledger-apdu = { path = "../ledger-apdu", version = "0.7.0" }

[build-dependencies]
protoc-rust-grpc = "0.8.1"
glob = "0.3.0"

28 changes: 27 additions & 1 deletion ledger-transport-zemu/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
use std::{env, fs, path::PathBuf};

use protoc_rust_grpc::Codegen;

fn out_dir() -> PathBuf {
PathBuf::from(env::var_os("OUT_DIR").unwrap())
}

fn generate_mod_rs() {
let out_dir = out_dir();

let mods = glob::glob(&out_dir.join("*.rs").to_string_lossy())
.expect("glob")
.filter_map(|p| {
p.ok()
.map(|p| format!("pub mod {};", p.file_stem().unwrap().to_string_lossy()))
})
.collect::<Vec<_>>()
.join("\n");

let mod_rs = out_dir.join("proto_mod.rs");
fs::write(&mod_rs, format!("// @generated\n{}\n", mods)).expect("write");

println!("cargo:rustc-env=PROTO_MOD_RS={}", mod_rs.to_string_lossy());
}

fn main() {
let out = out_dir();
Codegen::new()
.out_dir("src")
.out_dir(out)
.input("zemu.proto")
.rust_protobuf(true)
.run()
.expect("protoc-rust-grpc");
generate_mod_rs();
}
6 changes: 2 additions & 4 deletions ledger-transport-zemu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod errors;
#[rustfmt::skip]
mod zemu;
#[rustfmt::skip]
mod zemu_grpc;

include!(env!("PROTO_MOD_RS"));

use grpc::prelude::*;
use grpc::ClientConf;
Expand Down