Skip to content

Conversation

dpaoliello
Copy link
Contributor

@dpaoliello dpaoliello commented Aug 27, 2025

First issue:

Currently cargo_config_env assumes that cargo config always serializes each entry in the env table to an object, but it is valid to use just a string for the value in the env table and this is converted to a string in the JSON:

> type .\.cargo\config.toml
[env]
IS_OBJECT = { value = "Hello" }
NOT_OBJECT = "World!"
> cargo +nightly -Z unstable-options config get --format json
{"env":{"IS_OBJECT":{"value":"Hello"},"NOT_OBJECT":"World!"}}

The fix for this is to handle JSON strings as well as objects.

Second issue:

Currently the only values available to the env! macro are those set in the env table of the Cargo configuration file (plus a few other hard coded values). This makes it difficult to simulate having environment variables set (e.g., to match a CI system) without either modifying the current project's configuration (which is usually checked-in) or the user's configuration (which is shared between projects).

This change makes the values set in the cargo.extraEnv configuration option available via the env! macro when loading a project via Cargo manifests. This provides a straightforward way for users to set custom values for env! and for those values to be consistent between language services and cargo check.

Note that this feature respects the force option in the env table, so it will only overwrite the values from extraEnv if force is set to true.

Fixes #13004
Partial fix for #17593 (changes env! but not include!)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 27, 2025
@dpaoliello dpaoliello marked this pull request as draft August 28, 2025 18:06
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2025
@dpaoliello dpaoliello changed the title Allow env vars set in cargo.extraEnv to be resolved by the env! macro Improvements for resolving the value of the env! macro Aug 28, 2025
@dpaoliello dpaoliello marked this pull request as ready for review August 28, 2025 18:33
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to pass values to env! macro in VS Code
2 participants