-
Notifications
You must be signed in to change notification settings - Fork 444
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
Add a cargo_dep_env
rule for setting build.rs environment variables
#1415
Conversation
6d60056
to
f9afd54
Compare
f9afd54
to
f541373
Compare
From its documentation: ``` File containing additional environment variables to set for build scripts of direct dependencies. This has the same effect as a `cargo_build_script` this target depends on printing `cargo:VAR=VALUE` lines, but without requiring a build script. This is useful for using Bazel rules instead of a build script, while also generating configuration information for build scripts which depend on this crate. See `rustc_env_files` for formatting details. ```
f541373
to
8180c87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! I think having this kind of mechanism generally makes sense - just one question about the shape of it.
rust/private/rustc.bzl
Outdated
@@ -225,6 +227,15 @@ def collect_deps( | |||
|
|||
transitive_crates_depset = depset(transitive = transitive_crates) | |||
|
|||
dep_env = None | |||
if build_info and dep_env_file: | |||
fail("Only a dependency or a dep_env_file may provide build information") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fail("Only a dependency or a dep_env_file may provide build information") | |
fail("Only one of a dependency or a dep_env_file may provide build information") |
rust/private/rust.bzl
Outdated
@@ -542,6 +542,20 @@ _common_attrs = { | |||
"""), | |||
allow_files = True, | |||
), | |||
"dep_env_file": attr.label( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this should be a common attr - if I'm understanding correctly, this is something a library sets to propagate to its dependents? It feels like it should either only live on rust_library
(I don't see a use-case for rust_binary
or rust_test
setting a dep_env_file
), or possibly be a standalone rule:
cargo_dep_env(
name = "set_b",
dep_env_file = "set_b.env",
)
I'd lean towards the standalone rule, which just populates a BuildInfo
provider, as this doesn't seem like it would be particularly coupled to a rust_library
, but I could be easily convinced otherwise.
This feels like it blurs the lines farther for whether or not Additionally, @bsilver8192, would you be willing to share a concrete use case you have for this functionality? |
My use case is pointing libz-sys at a Bazel-compiled zlib (without using its build.rs), but using the build.rs for libgit2 (which depends on libz-sys). https://github.com/frc971/971-Robot-Code/blob/8e815fbb728ddc4df9714f72beb925cb8c93159d/third_party/cargo_raze/cargo_raze.patch is my patches (also includes some unrelated changes to platforms and warning flags). I'm planning to submit that to cargo_raze if we get something merged here. PS: Ignore the More background on why I want to do this: libz-sys is pretty easy to write a BUILD file for, and is also commonly a shared dependency with C++ code which needs a cc_library to link against. libgit2 looks complicated to build (judging by the build.rs), and I don't have any C++ dependencies on it. |
Would |
Yes, I think this would avoid the concern of cargo "polluting" the rest of rules_rust. It's also worth noting that this rule wouldn't have to live in rules_rust - the
AFAIK the issue isn't so much that cargo support is experimental (I wouldn't describe it as such); the two concerns around the cargo support are:
|
From the docs: > A rule for generating variables for dependent `cargo_build_script`s > without a build script. This is useful for using Bazel rules instead > of a build script, while also generating configuration information > for build scripts which depend on this crate.
cargo_dep_env
rule for setting build.rs environment variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much!
From the docs: