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

add a function to populate flags from an arbitrary environment variable #818

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Jul 15, 2023

My specific use-case is to add ability for the end users to specify crate-specific environment variables, but with how general this method is I could imagine numerous other applications too.

Why does this need to be in cc-rs, you ask? The code to split up the CFLAGS or CXXFLAGS environment variables into flags seems trivial today, but I worry that it might not remain the case indefinitely into the future. If everybody is expected to do this in their own build scripts, we’re certain to run into a very inconsistent experience as soon as parsing needs an adjustment.

My specific use-case is to add ability for the end users to specify
crate-specific environment variables, but with how general this method
is I could imagine numerous other applications too.

Why does this need to be in `cc-rs`, you ask? The code to split up the
`CFLAGS` or `CXXFLAGS` environment variables into flags seems trivial
today, but I worry that it might not remain the case indefinitely into
the future. If everybody is expected to do this in their own build
scripts, we’re certain to run into a very inconsistent experience as
soon as parsing needs an adjustment.
@@ -3133,6 +3139,34 @@ impl Build {
}
}

fn getenv_with_target_prefixes(&self, var_base: &str) -> Result<String, Error> {
Copy link
Member Author

@nagisa nagisa Jul 16, 2023

Choose a reason for hiding this comment

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

This function has been moved and renamed to be grouped with other getenv family of functions, with no other changes intended.

}
}

fn envflags(&self, name: &str) -> Result<Vec<String>, Error> {
Copy link
Member Author

@nagisa nagisa Jul 16, 2023

Choose a reason for hiding this comment

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

This function has been changed to return an Error when getenv_with_target_prefixes fails in order to allow to propagate this error in the newly added method.

@thomcc
Copy link
Member

thomcc commented Jul 16, 2023

This seems fine to me, but probably needs some documentation.

@nagisa
Copy link
Member Author

nagisa commented Jul 16, 2023

What sort of documentation do you envision (i.e. what sort of questions should it answer) in addition to what is present in the doc-comment and where should it go?

@thomcc
Copy link
Member

thomcc commented Jul 16, 2023

Do you think it's worth mentioning with https://github.com/rust-lang/cc-rs#external-configuration-via-environment-variables? I could see an argument that it's not.

This is specifically a end-user facing information, so that they are
aware of the possibility that there may be additional environment
variables as well.
@nagisa
Copy link
Member Author

nagisa commented Jul 16, 2023

Done! I tailored that part of the documentation specifically towards the end-users (people compiling code/crates,) as that whom this documentation appeared to be aimed at.

@thomcc
Copy link
Member

thomcc commented Jul 16, 2023

This all looks good to me, I'll take another look some time it's not 2AM before I merge, though.

Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

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

LGTM

@thomcc thomcc merged commit d2a6839 into rust-lang:main Jul 17, 2023
16 checks passed
@nagisa nagisa deleted the nagisa/flag-population branch July 18, 2023 08:33
@nagisa
Copy link
Member Author

nagisa commented Jul 18, 2023

Do you have a time in mind for then there might be a new version? I can submit a PR with version bumps if that all it needs.

@thomcc thomcc mentioned this pull request Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants