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

Allow passing through environment variables #91

Merged
merged 8 commits into from
Jun 10, 2017

Conversation

kamalmarhubi
Copy link
Contributor

@kamalmarhubi kamalmarhubi commented Apr 18, 2017

This adapts @dflemstr's work in #77, removing the whitelist_all functionality as requested in review.

fixes #76
closes #77

@kamalmarhubi
Copy link
Contributor Author

@japaric please critique the configuration UX (location in toml file). I'm happy to change it.

@Susurrus
Copy link

@kamalmarhubi Comments in #77 also suggested an addition to the README describing the new variables.

@Susurrus
Copy link

Having used this in testing where I think the whitelist functionality is working correctly, it'd be helpful if during the CI run the specific whitelisted variables and their values were output to stdout. This would make it clear that a) the values got passed through and b) they're the right values.

@japaric
Copy link
Contributor

japaric commented Apr 19, 2017

@kamalmarhubi Looks good to me. I'm wondering if we should also have a target.$T.env.whitelist option for target specific variables but that can be added later if needed. Oh, and could you document this feature in the README?

@Susurrus perhaps we could print the env vars to stdout/stderr if the -v (verbose) flag is used.

@Susurrus
Copy link

@japaric Yeah, I think that would be useful. I'd be fine deferring that to a later PR however in the interest of getting this released.

@kamalmarhubi
Copy link
Contributor Author

I should be able to do this in the next day or so if that timeline is ok. Otherwise happy to make a follow-up PR.

@japaric
Copy link
Contributor

japaric commented Apr 19, 2017

I should be able to do this in the next day or so if that timeline is ok.

That'd be fine. Thanks!

@kamalmarhubi
Copy link
Contributor Author

@japaric could you take a look? I'm unable to test it right now as I'm on a restricted network and downloading docker images isn't an easy option.

Also, I'm not super happy with calling this env.whitelist. I'd think something like pass_through or passthrough would be better, but I'm terrible at names.

README.md Outdated
### Passing environment variables into the build environemnt

By default, `cross` does not pass any environment variables into the build
environment from the calling shell. Sometimes this is really useful, for

Choose a reason for hiding this comment

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

Minor nitpick, but "this" on this line seems to refer to the fact that cross doesn't pass through environment variables by default when I think you want it to mean the opposite. Maybe instead say "This is chosen as a safe default as most use cases will not want the calling environment leaking into the inner execution environment. But in the instances that you do want to pass through environment variables, this can be done through the use of a whitelist."

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @Susurrus here.

Choose a reason for hiding this comment

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

Also, given what came up in japaric/trust#73, I suggest it also be made clear that Mac doesn't use docker and so all environment variables are automatically "passed through" and this whitelist is only used for docker-targets (currently just Linux).

README.md Outdated
```toml
[build.env]
whitelist = [
"TRAVIS",

Choose a reason for hiding this comment

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

#74 specifically talks about RUST_BACKTRACE. Maybe add that here as well as a hint to users that that might be useful?

@Susurrus
Copy link

@kamalmarhubi I slilghtly prefer passthrough instead of env_whitelist, but I don't have a strong opinion either way.

@japaric
Copy link
Contributor

japaric commented Apr 20, 2017

I too think that passthrough fits better.

@kamalmarhubi Do you think you could add a test for this? Perhaps create a library crate that has a unit test that checks for the presence of some env variable, set that var on the host, place a Cross.toml in that crate and then run cross test on the targets that support testing.

@Susurrus
Copy link

@kamalmarhubi just wanted to ping you on finishing this up. Do you have some time soon here to wrap up this PR?

@kamalmarhubi
Copy link
Contributor Author

I'm sorry for the delay on this. It's easiest for me to work on non-work stuff at the weekends. I'll get to it this weekend!

@Susurrus
Copy link

Susurrus commented May 1, 2017

Any updates on this @kamalmarhubi?

@kamalmarhubi
Copy link
Contributor Author

I'm having a bit of trouble testing this, as I can't get cross to run at all. I get this error, seemingly with whichever target I use. @japaric any idea what's up?

error: couldn't execute `"rustc" "--print" "target-list"`
caused by: No such file or directory (os error 2)

@Susurrus
Copy link

Susurrus commented May 3, 2017

I can try to reproduce on my end, what's your test environment?

@kamalmarhubi
Copy link
Contributor Author

Oh I think I see the issue: to use docker I have to be root, but rust and rustup are installed in my home directory.

@kamalmarhubi
Copy link
Contributor Author

Temporarily added myself to the docker group, and it's working. I'll have to test in the evening though. Work beckons!

@kamalmarhubi
Copy link
Contributor Author

Apologies for letting this languish. I've rebased and pushed up stuff addressing the review comments. I have tests in progress but not ready to push.

Copy link

@Susurrus Susurrus left a comment

Choose a reason for hiding this comment

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

Otherwise this LGTM.

src/main.rs Outdated
@@ -461,6 +461,46 @@ impl Toml {
Ok(None)
}
}

/// Returns the list of environment variables to pass through for `target`,
/// including variables sepcified under `build` and under `target`.
Copy link

Choose a reason for hiding this comment

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

Misspelled specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eep, fixed!

@kamalmarhubi
Copy link
Contributor Author

@japaric can you take a look and let me know if you need any changes? Also, let me know if I should try to wrap up the tests or if it can be merged as is.

@japaric
Copy link
Contributor

japaric commented Jun 10, 2017

Thanks for updating this, @kamalmarhubi. It looks good to me. Let's land it.

@homunkulus r+

@homunkulus
Copy link
Contributor

📌 Commit 40a3f1c has been approved by japaric

@homunkulus
Copy link
Contributor

⌛ Testing commit 40a3f1c with merge 40a3f1c...

@homunkulus
Copy link
Contributor

💔 Test failed - status-travis

@kamalmarhubi
Copy link
Contributor Author

I'll looking into the failure in a couple hours.

dflemstr and others added 8 commits June 10, 2017 04:52
This addresses comments on cross-rs#77.
Add support for environment variables to be specified in `Cross.toml`
under the `target.<triple>.env.whitelist` key.
Use nested matching to make it easier to see what's going on.
- rename `whitelist` to `passthrough`
- reword description of feature in readme
- add `RUST_BACKTRACE` to the example in readme
@kamalmarhubi
Copy link
Contributor Author

Pushed a build fix, should be good to try again.

@japaric
Copy link
Contributor

japaric commented Jun 10, 2017

@homunkulus r+

@homunkulus
Copy link
Contributor

📌 Commit 280917f has been approved by japaric

@homunkulus
Copy link
Contributor

⌛ Testing commit 280917f with merge 280917f...

@homunkulus
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: japaric
Pushing 280917f to master...

@homunkulus homunkulus merged commit 280917f into cross-rs:master Jun 10, 2017
@Susurrus
Copy link

Awesome work guys, thanks!

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.

Propagate environment variables
5 participants