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

Allow cargo:rustc-env in build scripts #3929

Merged
merged 4 commits into from May 15, 2017

Conversation

Projects
None yet
6 participants
@Xion
Contributor

Xion commented Apr 17, 2017

This is an attempt to address issue #2875. Basically, I'm trying to allow build scripts to producecargo:rustc-env=FOO=foo lines in their output. These are then translated to env!()-friendly env. vars that rustc is run with.

@rust-highfive

This comment has been minimized.

Show comment
Hide comment
@rust-highfive

rust-highfive Apr 17, 2017

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

rust-highfive commented Apr 17, 2017

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton

Looking good to me, thanks @Xion!

I wonder if we want to maybe pursue namespacing the env vars though? Righw now cargo exports env vars as CARGO_* and we may wish to scope the custom env vars here to ensure they don't clash with future significant env vars and such.

Show outdated Hide outdated src/cargo/ops/cargo_rustc/mod.rs
"#)
.file("src/main.rs", r#"
const FOO: &'static str = env!("FOO");
fn main() {}

This comment has been minimized.

@alexcrichton

alexcrichton Apr 20, 2017

Member

Could this assert the right value of FOO as well?

@alexcrichton

alexcrichton Apr 20, 2017

Member

Could this assert the right value of FOO as well?

This comment has been minimized.

@Xion

Xion May 12, 2017

Contributor

Done.

@Xion

Xion May 12, 2017

Contributor

Done.

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton Apr 20, 2017

Member

Note that another use case in #2875 is to export git information which I think Cargo should just do by default.

In any case I feel like this is a totally fine feature to have, it's certainly more ergonomic than using include!!

Member

alexcrichton commented Apr 20, 2017

Note that another use case in #2875 is to export git information which I think Cargo should just do by default.

In any case I feel like this is a totally fine feature to have, it's certainly more ergonomic than using include!!

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton Apr 20, 2017

Member

cc @matklad, @carols10cents, @wycats, @brson, an upcoming feature in Cargo!

Member

alexcrichton commented Apr 20, 2017

cc @matklad, @carols10cents, @wycats, @brson, an upcoming feature in Cargo!

@petrochenkov

This comment has been minimized.

Show comment
Hide comment
@petrochenkov

petrochenkov Apr 20, 2017

Contributor

@Xion
Build script overrides need to be updated as well.

Contributor

petrochenkov commented Apr 20, 2017

@Xion
Build script overrides need to be updated as well.

@matklad

This comment has been minimized.

Show comment
Hide comment
@matklad

matklad Apr 21, 2017

Member

Looks great! It needs to be documented though :)

Member

matklad commented Apr 21, 2017

Looks great! It needs to be documented though :)

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors May 8, 2017

Contributor

☔️ The latest upstream changes (presumably #3974) made this pull request unmergeable. Please resolve the merge conflicts.

Contributor

bors commented May 8, 2017

☔️ The latest upstream changes (presumably #3974) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton May 11, 2017

Member

ping @Xion, would you be willing to rebase and/or add docs?

Member

alexcrichton commented May 11, 2017

ping @Xion, would you be willing to rebase and/or add docs?

@Xion

This comment has been minimized.

Show comment
Hide comment
@Xion

Xion May 12, 2017

Contributor

Sorry, I've been busy with onboarding at a new job. I'll try to get to it this weekend.

Contributor

Xion commented May 12, 2017

Sorry, I've been busy with onboarding at a new job. I'll try to get to it this weekend.

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton May 12, 2017

Member

No worries! Let me know if you run out of time for this and I'd be happy to take it over

Member

alexcrichton commented May 12, 2017

No worries! Let me know if you run out of time for this and I'd be happy to take it over

"#)
.file("src/main.rs", r#"
const FOO: &'static str = env!("FOO");
fn main() {}

This comment has been minimized.

@Xion

Xion May 12, 2017

Contributor

Done.

@Xion

Xion May 12, 2017

Contributor

Done.

Show outdated Hide outdated src/cargo/ops/cargo_rustc/mod.rs
Show outdated Hide outdated tests/build-script.rs
@Xion

This comment has been minimized.

Show comment
Hide comment
@Xion

Xion May 12, 2017

Contributor

As for namespacing, what prefix would not clash with any of the tooling? I was thinking about RUSTC_ENV_ to match the script output, or CARGO_ENV_ to call dibs on that one already.

On the other hand, I'm not sure such prefixing is necessary nor desirable. Since the values for the env vars are purely in the user's discretion, the names should be too. There may even be some valid use cases for shadowing the CARGO_ variables -- which the user can already do by invoking CARGO_FOO=x cargo rustc -- so I wouldn't preclude that either.

Contributor

Xion commented May 12, 2017

As for namespacing, what prefix would not clash with any of the tooling? I was thinking about RUSTC_ENV_ to match the script output, or CARGO_ENV_ to call dibs on that one already.

On the other hand, I'm not sure such prefixing is necessary nor desirable. Since the values for the env vars are purely in the user's discretion, the names should be too. There may even be some valid use cases for shadowing the CARGO_ variables -- which the user can already do by invoking CARGO_FOO=x cargo rustc -- so I wouldn't preclude that either.

@alexcrichton

Yeah I think you're right in that we may wish to eschew the prefix, that sounds ok to me.

I think there's some tests failing here related to rustdoc as well? Could you also add tests that execute cargo doc to ensure that works as well?

Show outdated Hide outdated src/cargo/ops/cargo_rustc/mod.rs
Show outdated Hide outdated src/cargo/ops/cargo_rustc/mod.rs
@Xion

This comment has been minimized.

Show comment
Hide comment
@Xion

Xion May 13, 2017

Contributor

I've fixed the problem the test for cargo test, and also added one for rustdoc. Documentation is also included.

Contributor

Xion commented May 13, 2017

I've fixed the problem the test for cargo test, and also added one for rustdoc. Documentation is also included.

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton May 15, 2017

Member

@bors: r+

Looks great to me, thanks so much for tackling this @Xion!

Member

alexcrichton commented May 15, 2017

@bors: r+

Looks great to me, thanks so much for tackling this @Xion!

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors May 15, 2017

Contributor

📌 Commit 8e6ffa5 has been approved by alexcrichton

Contributor

bors commented May 15, 2017

📌 Commit 8e6ffa5 has been approved by alexcrichton

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors May 15, 2017

Contributor

⌛️ Testing commit 8e6ffa5 with merge 6709508...

Contributor

bors commented May 15, 2017

⌛️ Testing commit 8e6ffa5 with merge 6709508...

bors added a commit that referenced this pull request May 15, 2017

Auto merge of #3929 - Xion:master, r=alexcrichton
Allow cargo:rustc-env in build scripts

**Warning**: This PR isn't ready yet (for one, the `env_test` test is failing), but I wanted to gather some feedback on the approach & get some help.

This is an attempt to address issue #2875. Basically, I'm trying to allow build scripts to produce`cargo:rustc-env=FOO=foo` lines in their output. These are then translated to `env!()`-friendly env. vars that rustc is run with.
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors May 15, 2017

Contributor

💔 Test failed - status-travis

Contributor

bors commented May 15, 2017

💔 Test failed - status-travis

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton May 15, 2017

Member
Member

alexcrichton commented May 15, 2017

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors May 15, 2017

Contributor

⌛️ Testing commit 8e6ffa5 with merge 00af72e...

Contributor

bors commented May 15, 2017

⌛️ Testing commit 8e6ffa5 with merge 00af72e...

bors added a commit that referenced this pull request May 15, 2017

Auto merge of #3929 - Xion:master, r=alexcrichton
Allow cargo:rustc-env in build scripts

This is an attempt to address issue #2875. Basically, I'm trying to allow build scripts to produce`cargo:rustc-env=FOO=foo` lines in their output. These are then translated to `env!()`-friendly env. vars that rustc is run with.
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors May 15, 2017

Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 00af72e to master...

Contributor

bors commented May 15, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 00af72e to master...

@bors bors merged commit 8e6ffa5 into rust-lang:master May 15, 2017

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

durka added a commit to durka/foreman that referenced this pull request May 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment