Skip to content

Commit

Permalink
Directly embed protos rather than submoduling pachyderm, to avoid a c…
Browse files Browse the repository at this point in the history
  • Loading branch information
ysimonson committed Mar 12, 2019
1 parent 37a8b50 commit d6485d2
Show file tree
Hide file tree
Showing 22 changed files with 3,977 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
**/*.rs.bk
Cargo.lock
.DS_Store
/proto/client
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ tower-util = { git = "https://github.com/tower-rs/tower" }

[build-dependencies]
failure = "0.1.5"
regex = "1.1.2"
walkdir = "2"
tower-grpc-build = { git = "https://github.com/tower-rs/tower-grpc" }

Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
init:
git submodule update --init
SHELL := /bin/bash

.PHONY: init
PACHYDERM_ROOT?=${GOPATH}/src/github.com/pachyderm/pachyderm
RUST_PACHYDERM_ROOT?=${PWD}

.PHONY: clean

clean:
rm -rf proto

proto:
mkdir proto
cd $(PACHYDERM_ROOT)/src && find ./client -maxdepth 5 -regex ".*\.proto" -exec cp --parents {} $(RUST_PACHYDERM_ROOT)/proto/ \;
find ./proto -name "*.proto" -exec sed -i '' 's/import.*gogo.proto.*\;//' {} +
find ./proto -name "*.proto" -exec sed -i '' 's/\[.*gogoproto.*\]//' {} +
28 changes: 5 additions & 23 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#[macro_use]
extern crate failure;
extern crate regex;
extern crate tower_grpc_build;
extern crate walkdir;

use std::env;
use std::fs::{create_dir_all, File};
use std::fs::File;
use std::io::{Error as IoError, Read, Write};
use std::path::{Path, PathBuf};
use std::process::exit;

use regex::Regex;
use walkdir::{DirEntry, Error as WalkDirError, WalkDir};

#[derive(Debug, Fail)]
Expand All @@ -33,13 +31,11 @@ impl From<IoError> for BuildError {
}
}

fn find<P>(root: P, min_depth: usize, max_depth: usize, ext: &str) -> Result<Vec<DirEntry>, WalkDirError>
fn find<P>(root: P, ext: &str) -> Result<Vec<DirEntry>, WalkDirError>
where
P: AsRef<Path>,
{
let entries: Result<Vec<DirEntry>, WalkDirError> = WalkDir::new(root)
.min_depth(min_depth)
.max_depth(max_depth)
.into_iter()
.filter_entry(|e| {
let actual_ext = e.path().extension().map(|s| s.to_str());
Expand Down Expand Up @@ -74,32 +70,18 @@ where
}

fn run() -> Result<(), BuildError> {
let gogo_matcher = Regex::new("import.*gogo\\.proto.*;|\\[.*gogoproto.*\\]").unwrap();
let mut compilable_protos = Vec::new();

for proto in find("./proto/pachyderm/src/client", 1, 4, "proto")? {
let src = proto.path();
let dest = Path::new("./proto/client").join(src.strip_prefix("./proto/pachyderm/src/client").unwrap());

create_dir_all(dest.parent().unwrap())?;

with_file_contents(src, &dest, |contents| {
gogo_matcher.replace_all(&contents, "").to_string()
})?;

compilable_protos.push(dest);
}
let protos: Vec<PathBuf> = find("./proto", "proto")?.into_iter().map(|e| e.into_path()).collect();

tower_grpc_build::Config::new()
.enable_client(true)
.build(&compilable_protos, &["./proto".into()])?;
.build(&protos.as_slice(), &["./proto".into()])?;

// TODO: it seems like prost has substitutions for well-known types built
// in, but tower-grpc-build doesn't use it:
// https://github.com/danburkert/prost/blob/2f5d570ce4989b87980f989829577a564da37cb2/prost-build/src/extern_paths.rs
// Figure out why, so we can remove this hack.
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR environment variable not set"));
for rs in find(out_dir, 0, 1, "rs")? {
for rs in find(out_dir, "rs")? {
let path = rs.into_path();

with_file_contents(&path, &path, |contents| {
Expand Down
Loading

0 comments on commit d6485d2

Please sign in to comment.