Skip to content

Commit

Permalink
gen-protos: special case path for cfg(buck_build)
Browse files Browse the repository at this point in the history
This is needed to emit the `.rs` files into the right build directory in a
follow up diff to add `BUCK` files.
  • Loading branch information
thoughtpolice committed May 12, 2024
1 parent af08c61 commit 80ebd71
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/gen-protos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,29 @@ fn main() -> Result<()> {
"working_copy.proto",
];

let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
let protos_dir = root.join("src").join("protos");
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let protos_dir = if cfg!(buck_build) {
// NOTE (aseipp, buck_build): the cargo build allows `../src/protos`
// like below, but this is really awkward in the buck2 design since
// directory names are autogenerated. use `src/protos` instead.
root.join("src").join("protos")
} else {
root.parent().unwrap().join("src").join("protos")
};

let out_dir = if cfg!(buck_build) {
// NOTE (aseipp, buck_build): under `cfg(buck_build)` the genrule() that
// invokes this program will automatically set $OUT, so always use that
// and fail otherwise.
std::env::var("OUT")
.map(|s| Path::new(&s).to_path_buf())
.expect("OUT environment variable not set during cfg(buck_build)")
} else {
protos_dir.clone()
};

prost_build::Config::new()
.out_dir(&protos_dir)
.out_dir(&out_dir)
.include_file("mod.rs")
// For old protoc versions. 3.12.4 needs this, but 3.21.12 doesn't.
.protoc_arg("--experimental_allow_proto3_optional")
Expand Down

0 comments on commit 80ebd71

Please sign in to comment.