Skip to content

Add support for build script [env_flags] sub-target #74

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yxdai-nju
Copy link
Contributor

@yxdai-nju yxdai-nju commented Apr 30, 2025

Summary

This PR allows Reindeer to generate rules that utilize environment variable outputs from build scripts.

Relates to facebook/buck2#929.

Changes

  • Add support for the [env_flags] sub-target on buildscript_run

For example, for the problematic mime_guess crate, Reindeer can now generate:

# BUCK
cargo.rust_library(
    name = "mime_guess-2.0.5",
    crate_root = "mime_guess-2.0.5.crate/src/lib.rs",
    env_flags = ["@$(location :mime_guess-2.0.5-build-script-run[env_flags])"],
    rustc_flags = ["@$(location :mime_guess-2.0.5-build-script-run[rustc_flags])"],
    # ...
)

This eliminates the need for manual environment variable fixups for crates that use cargo:rustc-env.

Testing

A demonstration repository verifies this works for mime_guess and ring crates, both have cargo:rustc-env outputs from build scripts.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 30, 2025
@yxdai-nju yxdai-nju force-pushed the buildscript-env-flags branch from 1b01ba5 to c3fbe53 Compare May 1, 2025 01:09
@yxdai-nju yxdai-nju changed the title Support Buck2's new buildscript_run environment variable handling Add support for build script [env_flags] sub-target May 1, 2025
…nary`

* When `buildscript.run = true`, set `env_flags` attribute like
  `env_flags = ["@$(location :my_crate-0.0.0-build-script-run[env_flags])"],`

Signed-off-by: Yuxuan Dai <yxdai@smail.nju.edu.cn>
@yxdai-nju yxdai-nju force-pushed the buildscript-env-flags branch from c3fbe53 to 02a28ae Compare May 1, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants