Skip to content

Support exporting informations to execute cargo test artifact separately #17026

@foriequal0

Description

@foriequal0

Problem

RustRover and rust-analyzer do a two-step method to launch a debug session for the target binary:

  1. cargo test --no-run (for rust-analyzer: https://github.com/rust-lang/rust-analyzer/blob/2cf14f4d34fd96fb763cfd9f909472a61145674a/editors/code/src/toolchain.ts#L54)
  2. execute the artifact by themselves.

But they don't set environment variables as cargo test does at the second step.

There are at least two kinds of environment variables that cargo sets:

  1. Dynamic library path (https://github.com/rust-lang/cargo/blob/2da24c9172cd638f63713aa191c9aff51c16f476/src/doc/src/reference/environment-variables.md#dynamic-library-paths)
  2. Environment variables from Cargo config (https://github.com/rust-lang/cargo/blob/2da24c9172cd638f63713aa191c9aff51c16f476/src/doc/src/reference/config.md#env)
  3. Accidential ones? (https://github.com/rust-lang/cargo/blob/2da24c9172cd638f63713aa191c9aff51c16f476/src/doc/src/reference/environment-variables.md#environment-variables-cargo-sets-for-crates)

rust-analyzer doesn't set all of them, while RustRover sets the 2. and (part of)3. (YouTrack issue)

I guess it's time to introduce a standard supporting mechanism for that?

Proposed Solution

some flags to print them (--print-info?)

{
  "executable": ".../target/debug/deps/...",
  "arguments": [ ... ],
  "environment_variables": {
    "FOO": "BAR",
    "LD_LIBRARY_PATH": "...",
    "CARGO_PKG_AUTHORS": "",
    ...
  }
}

generate new message (when --message-format=json is used)

make some

impl<'a> Message for DryRun<'a> {
    fn reason(&self) -> &str {
        "dry-run"
    }
}

and print this when --no-run is given?

{
  "reason": "dry-run",
  "executable": ".../target/debug/deps/...",
  "arguments": [ ... ],
  "environment_variables": {
    "FOO": "BAR",
    "LD_LIBRARY_PATH": "...",
    "CARGO_PKG_AUTHORS": "",
    ...
  }
}

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-json-outputArea: JSON message outputC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-testS-needs-team-inputStatus: Needs input from team on whether/how to proceed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions