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

feat: Stablize CARGO_RUSTC_CURRENT_DIR #13644

Closed
wants to merge 1 commit into from

Commits on Mar 26, 2024

  1. feat: Stablize CARGO_RUSTC_CURRENT_DIR

    This provides what cargo sets as the `current_dir` for the `rustc`
    process.
    While `std::file!` is unspecified in what it is relative to,
    it is relatively safe, it is generally relative to `rustc`s
    `current_dir`.
    
    This can be useful for snapshot testing.
    For example, `snapbox` has been using this macro on nightly since
    assert-rs/snapbox#247, falling back to finding a parent of
    `CARGO_MANIFEST_DIR`, if present.
    This has been in use in Cargo since rust-lang#13441.
    
    This was added in rust-lang#12996.
    Relevant points discussed in that issue:
    - This diverged from the original proposal from the Cargo team of having
      a `CARGO_WORKSPACE_DIR` that is the "workspace" of the package being
      built (ie registry packages would map to `CARGO_MANIFEST_DIR`).
      In looking at the `std::file!` use case, `CARGO_MANIFEST_DIR`, no
      matter how we defined it, would only sort of work because no sane
      definition of that maps to `rustc`'s `current_dir`.a
      This instead focuses on the mechanism currently being used.
    - Using "current dir" in the name is meant to be consistent with
      `std::env::current_dir`.
    - I can go either way on `CARGO_RUSTC` vs `RUSTC`.  Existing related
      variables:
      - `RUSTC`
      - `RUSTC_WRAPPER`
      - `RUSTC_WORKSPACE_WRAPPER`
      - `RUSTFLAGS` (no `C`)
      - `CARGO_CACHE_RUSTC_INFO`
    
    Note that rust-lang#3946 was overly broad and covered many use cases.
    One of those was for packages to look up information on their
    dependents.
    Issue rust-lang#13484 is being left open to track that.
    
    Fixes rust-lang#3946
    epage committed Mar 26, 2024
    Configuration menu
    Copy the full SHA
    d60e025 View commit details
    Browse the repository at this point in the history