-
Notifications
You must be signed in to change notification settings - Fork 273
Add support for cargo:rustc-env
outputs from build scripts (draft)
#919
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 support for cargo:rustc-env
outputs from build scripts (draft)
#919
Conversation
@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. (Because this pull request was imported automatically, there will not be any future comments.) |
All of this would be dramatically simpler, I'm talking +3 lines of code instead of +300, with the unstable Could this PR encode the flags the same way (as |
This is the +3 for posterity |
Thank you for your suggestions, this would be a really helpful feature! However, things are a bit more complex with remote execution. If an environment variable contains a path, it should get converted to an absolute path before passed to rustc, to ensure correct behavior. Currently, any environment variable values you set in the The workflow of my solution is, for example: 1. Collect build script outputs:
--->
This produces "--env" flags to be passed to 2. Determine whether the values contain paths: # Step 3: Utilize 'process_env' to determine whether each environment variable
# is "plain" or "with path", then produce an *-env-flags.txt file
# containing environment variable flags suitable to pass to the
# `_long_command` macro. For instance
# ```
# --env=USER=john
# --path-env=HOME=/home/john
# ```
plain_env, path_env = process_env(compile_ctx, env_map, exec_is_windows, escape_for_rustc_action) So the conversion done here is:
--->
This produces "--env" and "--path-env" flags to be passed to the |
329d071
to
4f96e1a
Compare
cargo:rustc-env
outputs from build scripts
39f6a2e
to
a77a2b6
Compare
Signed-off-by: Yuxuan Dai <[email protected]>
* Accept passing environment variables through "--env=NAME=VAL" flags * Add two rust internal tools to assist environment variable flags processing Signed-off-by: Yuxuan Dai <[email protected]>
Signed-off-by: Yuxuan Dai <[email protected]>
* Collect build script `^cargo:rustc-env=(.+?)=(.*)` output into `--env=$1=$2` flags * Export flags as an Artifact, which can be passed to cargo.rust_library/binary with `env_flags = ["@$(location :<CARGO_PKG_NAME>-<CARGO_PKG_VERSION>-build-script-run[env_flags])"],` Signed-off-by: Yuxuan Dai <[email protected]>
Signed-off-by: Yuxuan Dai <[email protected]>
a77a2b6
to
e575b5b
Compare
I misunderstood the purpose of the env = {
"NAME": "john",
"RESULT_PATH": "$(location :my_crate-1.0.0-build-script-run[out_dir])/result.txt",
} The mapping goes through the
And with Environment variable values emitted by build scripts don't contain macros and don't need this conversion. Using just |
cargo:rustc-env
outputs from build scriptscargo:rustc-env
outputs from build scripts (draft)
Superseded by #929. |
Summary
This PR adds support for collecting
cargo:rustc-env
outputs from build scripts.Relates to facebookincubator/reindeer#67.
Changes
cargo:rustc-env
outputs, in the format of "--env=NAME=val" flags[env_flags]
onbuildscript_run
, for getting the "--env" flags outputenv_flags
torust_library
andrust_binary
rule, accepting "--env" flagsExample usage:
After facebookincubator/reindeer#67, the
env_flags = ["@$(location ...)"],
setting will be automatically added, when any buildscript fixup ofrustc_flags
orgen_srcs
type exists.Closes #918.