-
Notifications
You must be signed in to change notification settings - Fork 402
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
Bazel build with prost-build build.rs fails with "No such file or directory" #454
Comments
protoc is likely not on your path. prost_build supports a PROTOC env var, but unless you're using the git version of prost_build, it checks it at build time instead of run time. I don't know if variable expansion is available in the Rust rules at the moment - adding it in the future would make things cleaner. I'm currently using a genrule with |
@dae thanks for the quick reply! I'm really new to Bazel so don't quite understand where in my demo repository would that kind of genrule then be? Because I believe this fails now before I get to almost any of my own Bazel labels, because the build.rs containing dependency is cargo-only project (the demo project replicates an actual problem, so touching anything under cargo/ won't work). |
I'm quite new to Bazel too :-) As far as I'm aware, this currently requires either hard-coding a path to PROTOC in the rustc_env argument (which you can have cargo-raze add for you), or jumping through hoops with a separate binary to resolve the proper location - which likely means vendoring the crate if it's not your own. To onlookers, if there's a simpler way that I've missed, please let me know! |
This makes it possible to pass in the path to generated files and external tools. This potentially closes bazelbuild#459, closes bazelbuild#454, and closes bazelbuild#79. The docs seem to indicate there's precedent for this in rules_cc: https://docs.bazel.build/versions/master/be/make-variables.html#predefined_label_variables
@dae: Could you help me understand your solution? I’m perfectly happy to In my [dependencies]
prost-build = "0.6.1"
[raze.crates.prost-build.'0.6.1']
gen_buildrs = true
[raze.crates.indexmap.'1.6.0']
additional_flags = [
"--cfg=has_std",
] As my test script: fn main() -> std::io::Result<()> {
let out_dir = "/tmp/gen_protos_out";
std::fs::DirBuilder::new()
.recursive(true)
.create(out_dir)
.unwrap();
prost_build::Config::new()
.out_dir(out_dir)
.compile_protos(&[""][0..0], &[])
.expect("compile_protos");
Ok(())
} To build that: rust_binary(
name = "build_protos",
srcs = ["build_protos.rs"],
edition = "2018",
deps = [
"//third_party/rust:prost_build",
],
) Now, when I build and run this with Bazel, I get the same
Note the path to Unsurprisingly, same dice when I invoke this via a genrule. So, I’m happy to jump through some BUILD hoops, especially since I have (Let me know if you need a more precise repro… minimizing a Bazel |
If you use the branch waiting to be merged in #468, the genrule hack is no longer needed, as you can pass a location directly to the build script: https://github.com/ankitects/anki/blob/ef5cd9f551269986ca44688e9fc42efeb4fc5bf6/rslib/BUILD.bazel#L24 Note that you'll need the git version of prost so it resolves PROTOC at run time instead of compile time. |
Oh!—
—thanks; this was what I had missed. I had been looking at the latest I’ve resolved my issue by copying your Git dep on |
I created a demo repository:
https://github.com/ttiurani/bazel-prost-build-bug
to showcase an issue where the standard
prost-build
example works fine with acargo build
but running the same withcargo raze
'd Bazel repository withbazel build demo
fails with:Where the build.rs is:
The error message is quite non-descriptive so was unable to trace this further myself. Note that I'd very much like to use the bundled
protoc
binary and not an external one to make my build easily repeatable in CI environments.Any ideas what might be wrong? I'm using the latest rules_rust from this morning.
The text was updated successfully, but these errors were encountered: