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

Support expanding locations in rustc_env and build_script_env #2 #468

Merged
merged 2 commits into from
Nov 5, 2020

Conversation

dae
Copy link
Contributor

@dae dae commented Oct 29, 2020

This is #461 squashed into fewer commits - please see that PR for previous discussion.

This potentially closes #459, closes #454, and closes #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

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

One implementation detail worth specifically calling out: This expands to an absolute, rather than relative, path for cargo build scripts, because we don't run them in the execroot. I think this is fine, but it's a bit weird.

I will leave a bit of time for others to chime in before merging :)

@@ -4,6 +4,19 @@ load("@io_bazel_rules_rust//rust:private/rustc.bzl", "BuildInfo", "DepInfo", "ge
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary")

def _expand_location(ctx, env, data):
if env.startswith("$(execpath ") or env.startswith("$(location "):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only does substitution if the start of the env var is a $(...) expression, whereas other rules do so anywhere. I think this is ok, but at some point may bite someone... It would be a shame to write our own parser for the replacement, but maybe doing a contains rather than startswith check, and an env.replace("$(location", "${pwd}/$(location" or similar could be worthwhile

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect non-prefixed usage won't be common, but it was easy enough to change. Also added a note about it being an absolute path to the docstring.

@dae dae force-pushed the location-expansion-tidied branch from d9e4f85 to fa9a732 Compare October 29, 2020 12:11
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dae dae force-pushed the location-expansion-tidied branch from fa9a732 to 31f096e Compare October 29, 2020 13:45
@dae
Copy link
Contributor Author

dae commented Oct 29, 2020

Latest push just corrects some $(execroot) references in the docs to $(execpath)

# Optional environment variables passed during build.rs execution.
# Note that as the build script's working directory is not execroot,
# execpath/location will return an absolute path, instead of a relative
# one.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work under remote-execution? Is it tested by the ci rbe_ubuntu1604 target?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should work under remote execution - the expansion is done in the cargo_build_script runner within the action.

The build script could opt to do bad things with the path passing it to dependees (though we have some logic in cargo_build_script to try to normalise that too), but within the action this is valid.

- rustc_env now expands $(rootpath //package:target), for passing
the location of files that are needed at compile time
- build_script_env now expands $(execpath //package:target), for
passing the location of files or tools that are needed at build
script runtime
- cargo_script_build() now passes the data argument to the build
script runner, so the data is available at runtime
@dae dae force-pushed the location-expansion-tidied branch from 2e3f50f to 10007a8 Compare November 5, 2020 02:06
@dae
Copy link
Contributor Author

dae commented Nov 5, 2020

Rebased on latest master; if there's anything else that needs changing, please let me know.

@illicitonion illicitonion merged commit afee872 into bazelbuild:master Nov 5, 2020
dwtj added a commit to dwtj/phasicj that referenced this pull request Nov 5, 2020
This removes the `do_nothing_cargo_build_script()` helper Bazel macro.

We now use new support for [`$(execpath)` expansion in the `rustc_env`
attribute][1] to help the `include_bytes!()` Rust macro find the
right Bazel-generated files.

---

[1]: bazelbuild/rules_rust#468
@UebelAndre UebelAndre mentioned this pull request Nov 6, 2020
wchargin added a commit to tensorflow/tensorboard that referenced this pull request Nov 10, 2020
Summary:
We pull in bazelbuild/rules_rust#468 to make it easier to build protos,
while not pulling in bazelbuild/rules_rust#463, because that would
require us to update Bazel to 3.0.0. Happily, the commit that we need
merged immediately before the commit that we don’t want! (Yes, this is a
wee bit precarious; we’re working on the Bazel upgrade: #4277.)

Test Plan:
With both Bazel 2.1.0 and Bazel 3.7.0, everything builds, all tests
pass, and TensorBoard looks okay enough.

wchargin-branch: rules-rust-20201105a
wchargin-source: bb3180a3a2a415d800d6a2a925fef0cb4e376d2f
wchargin added a commit to tensorflow/tensorboard that referenced this pull request Nov 10, 2020
Summary:
We pull in bazelbuild/rules_rust#468 to make it easier to build protos,
while not pulling in bazelbuild/rules_rust#463, because that would
require us to update Bazel to 3.0.0. Happily, the commit that we need
merged immediately before the commit that we don’t want! (Yes, this is a
wee bit precarious; we’re working on the Bazel upgrade: #4277.)

Test Plan:
With both Bazel 2.1.0 and Bazel 3.7.0, everything builds, all tests
pass, and TensorBoard looks okay enough.

wchargin-branch: rules-rust-20201105a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants