From b31e4c8ac19b880594ef7fac726b5bed5e053555 Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Mon, 29 May 2023 19:18:49 -0700 Subject: [PATCH] feat: Add `CARGO_RUSTC_CURRENT_DIR` This is an alternative to #12158's `CARGO_WORKSPACE_DIR` that was implementing the solution to #3946 that previously discussed in the cargo team meeting. `CARGO_WORKSPACE_DIR` is a bit awkward to document / describe because its the effective workspace directory of the thing being built. If the thing being built doesn't have a workspace, it falls back to `CARGO_MANIFEST_DIR`. It would also be hard to take into account what the `CARGO_WORKSPACE_DIR` would be for path dependencies into foreign workspaces *and* it wouldn't solve the problem the user is having. What the user really wants is the CWD of rustc when it is invoked. This is much simpler to describe and is accurate when using a path dependency to a foreign package. Because the CWD is a much simpler mechanism to talk about, I figured we could diverge from our prior consensus and make it always present, rather than limiting it to tests. Remaining work for #3946: get this stabilized --- src/cargo/core/compiler/mod.rs | 10 + .../src/reference/environment-variables.md | 1 + tests/testsuite/build.rs | 206 +++++++++++++++++- 3 files changed, 213 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index a72214d3babe..a318a8575a94 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -680,6 +680,16 @@ fn prepare_rustc(cx: &Context<'_, '_>, unit: &Unit) -> CargoResult