Skip to content

Commit d3b129f

Browse files
committed
Auto merge of rust-lang#14444 - zapkub:runable-debug-env-is-not-passing-properly, r=Veykril
Missing runnable env on debug target Fix bug in Rust Analyzer VSCode where runnable debugging did not pass environment variable from configuration to child process of Cargo on binary build stage There is a missing env passing along to `cargo` in debug target which give an in-consistent result from debug and run target For example ```json { "rust-analyzer.runnableEnv": { "OUT_DIR": "/test/path2" } } ``` ## run ![image](https://user-images.githubusercontent.com/4373581/228749503-fa55f62c-13d3-4d3c-bee6-1cfbe042bdd0.png) ## debug compiling binary is failed. Missing env ![image](https://user-images.githubusercontent.com/4373581/228749688-3fe42efb-b5ca-41be-862d-f2d97ecab7be.png) ## debug (after fix) ![image](https://user-images.githubusercontent.com/4373581/228750057-1db60051-3465-47db-8b18-4159ec58cfdb.png)
2 parents 562477b + fb9a1dd commit d3b129f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

editors/code/src/debug.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ async function getDebugConfiguration(
118118
return path.normalize(p).replace(wsFolder, "${workspaceFolder" + workspaceQualifier + "}");
119119
}
120120

121-
const executable = await getDebugExecutable(runnable);
122121
const env = prepareEnv(runnable, ctx.config.runnableEnv);
122+
const executable = await getDebugExecutable(runnable, env);
123123
let sourceFileMap = debugOptions.sourceFileMap;
124124
if (sourceFileMap === "auto") {
125125
// let's try to use the default toolchain
@@ -156,8 +156,11 @@ async function getDebugConfiguration(
156156
return debugConfig;
157157
}
158158

159-
async function getDebugExecutable(runnable: ra.Runnable): Promise<string> {
160-
const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput);
159+
async function getDebugExecutable(
160+
runnable: ra.Runnable,
161+
env: Record<string, string>
162+
): Promise<string> {
163+
const cargo = new Cargo(runnable.args.workspaceRoot || ".", debugOutput, env);
161164
const executable = await cargo.executableFromArgs(runnable.args.cargoArgs);
162165

163166
// if we are here, there were no compilation errors.

editors/code/src/toolchain.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export interface ArtifactSpec {
1818
}
1919

2020
export class Cargo {
21-
constructor(readonly rootFolder: string, readonly output: vscode.OutputChannel) {}
21+
constructor(
22+
readonly rootFolder: string,
23+
readonly output: vscode.OutputChannel,
24+
readonly env: Record<string, string>
25+
) {}
2226

2327
// Made public for testing purposes
2428
static artifactSpec(args: readonly string[]): ArtifactSpec {
@@ -102,6 +106,7 @@ export class Cargo {
102106
const cargo = cp.spawn(path, cargoArgs, {
103107
stdio: ["ignore", "pipe", "pipe"],
104108
cwd: this.rootFolder,
109+
env: this.env,
105110
});
106111

107112
cargo.on("error", (err) => reject(new Error(`could not launch cargo: ${err}`)));

0 commit comments

Comments
 (0)