-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 option to pass environment variables to rustc with a flag #80792
Comments
For what it's worth, this is exactly what x.py does: https://github.com/rust-lang/rust/blob/master/src/bootstrap/bin/rustc.rs
To be clear, you only need this to support |
Yes exactly, just |
Thanks, I'm new in these parts and don't know all of the process yet :) |
Opened an MCP about it: rust-lang/compiler-team#653 |
Implement `--env` compiler flag (without `tracked_env` support) Part of rust-lang#80792. Implementation of rust-lang/compiler-team#653. Not an implementation of rust-lang/rfcs#2794. It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`. Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value. As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR. r? rust-lang/compiler
Implement `--env` compiler flag (without `tracked_env` support) Part of rust-lang/rust#80792. Implementation of rust-lang/compiler-team#653. Not an implementation of rust-lang/rfcs#2794. It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`. Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value. As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR. r? rust-lang/compiler
…Nilstrieb Add support for `--env` on `tracked_env::var` Follow-up of rust-lang#118368. Part of Part of rust-lang#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
…Nilstrieb Add support for `--env` on `tracked_env::var` Follow-up of rust-lang#118368. Part of Part of rust-lang#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? ``@Nilstrieb``
…lstrieb Add support for `--env` on `tracked_env::var` Follow-up of rust-lang#118368. Part of Part of rust-lang#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
Add support for `--env` on `tracked_env::var` Follow-up of rust-lang/rust#118368. Part of Part of rust-lang/rust#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
Add support for `--env` on `tracked_env::var` Follow-up of rust-lang/rust#118368. Part of Part of rust-lang/rust#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
Update documentation for `--env` compilation flag Part of rust-lang#80792. As mentioned in rust-lang#118830. It adds a mention to `tracked_env::var` and also clarifies what triggers a new compilation. r? `@Nilstrieb`
Rollup merge of rust-lang#119115 - GuillaumeGomez:env-docs, r=Nilstrieb Update documentation for `--env` compilation flag Part of rust-lang#80792. As mentioned in rust-lang#118830. It adds a mention to `tracked_env::var` and also clarifies what triggers a new compilation. r? `@Nilstrieb`
The option is now available in nightly. |
Implement `--env` compiler flag (without `tracked_env` support) Part of rust-lang/rust#80792. Implementation of rust-lang/compiler-team#653. Not an implementation of rust-lang/rfcs#2794. It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`. Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value. As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR. r? rust-lang/compiler
Add support for `--env` on `tracked_env::var` Follow-up of rust-lang/rust#118368. Part of Part of rust-lang/rust#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
Implement `--env` compiler flag (without `tracked_env` support) Part of rust-lang/rust#80792. Implementation of rust-lang/compiler-team#653. Not an implementation of rust-lang/rfcs#2794. It adds the `--env` compiler flag option which allows to set environment values used by `env!` and `option_env!`. Important to note: When trying to retrieve an environment variable value, it will first look into the ones defined with `--env`, and if there isn't one, then only it will look into the environment variables. So if you use `--env PATH=a`, then `env!("PATH")` will return `"a"` and not the actual `PATH` value. As mentioned in the title, `tracked_env` support is not added here. I'll do it in a follow-up PR. r? rust-lang/compiler
Add support for `--env` on `tracked_env::var` Follow-up of rust-lang/rust#118368. Part of Part of rust-lang/rust#80792. It adds support of the `--env` option for proc-macros through `tracked_env::var`. r? `@Nilstrieb`
See #78913 for more background.
I'm a meson developer, working to make rust work better with meson. I know that cargo is the official build system for rust, but for me and the projects I work on cargo is unacceptable, we have a massive C/C++ codebase already using meson, with interest in migrating some (but not all) of our code to rust. Mostly things work fine, but one problem we do have is including generated code.
Cargo handles generated code by setting an
OUT_DIR
environment variable, this works for cargo because it has a number of unique design decisions compared to most build systems. For Cmake and meson and particular this is problematic because we generate a declarative build system which the user invokes, visual-studio, ninja, make, etc; so there are separate "configure" and "build" stages. For ninja in particular environment variables are problematic because it's made an explicit design choice not to support them. As such, we have no way to set environment variables at build time without resorting to something ugly like wrapping rustc in a script to proxy the variables.What would be nice is the ability to pass environment variables to rustc directly, much like
--cfg
, something like--env "OUT_DIR=/some/dir"
. This would allow us to makeinclude()
work like cargo, but without needing to resort to wrapping rustc and making things slower than they need to be.The text was updated successfully, but these errors were encountered: