Skip to content

Add option to pass environment variables to rustc with a flag #80792

Description

@dcbaker

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 make include() work like cargo, but without needing to resort to wrapping rustc and making things slower than they need to be.

Activity

  1. jyn514 commented on Jan 7, 2021

    @jyn514
    Member

    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.

    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

    What would be nice is the ability to pass environment variables to rustc directly, much like --cfg, something like --env "OUT_DIR=/some/dir".

    To be clear, you only need this to support env!, right, not actual environment variables?

  2. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    on Jan 7, 2021
  3. dcbaker commented on Jan 7, 2021

    @dcbaker
    Author

    Yes exactly, just env!.

  4. jyn514 commented on Jan 7, 2021

    @jyn514
    Member

    Just so you know, I doubt anyone will pick this up as-is. Normally the way small things like this get implemented is by making a PR implementing it, which then goes through FCP. If you don't know how to implement it, you could make an MCP and hope someone picks it up instead.

  5. dcbaker commented on Jan 7, 2021

    @dcbaker
    Author

    Thanks, I'm new in these parts and don't know all of the process yet :)

  6. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 7, 2021
  7. GuillaumeGomez commented on Jul 13, 2023

    @GuillaumeGomez
    Member

    Opened an MCP about it: rust-lang/compiler-team#653

  8. added a commit that references this issue on Dec 10, 2023
  9. added 2 commits that reference this issue on Dec 16, 2023
  10. added a commit that references this issue on Dec 17, 2023
  11. added a commit that references this issue on Dec 20, 2023
  12. added a commit that references this issue on Dec 20, 2023
  13. GuillaumeGomez commented on Dec 20, 2023

    @GuillaumeGomez
    Member

    The option is now available in nightly.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions