@@ -3,7 +3,7 @@ import * as os from "os";
3
3
import * as path from "path" ;
4
4
import * as readline from "readline" ;
5
5
import * as vscode from "vscode" ;
6
- import { execute , log , memoizeAsync , unwrapNullable , unwrapUndefinable } from "./util" ;
6
+ import { log , memoizeAsync , unwrapUndefinable } from "./util" ;
7
7
import type { CargoRunnableArgs } from "./lsp_ext" ;
8
8
9
9
interface CompilationArtifact {
@@ -55,7 +55,10 @@ export class Cargo {
55
55
return result ;
56
56
}
57
57
58
- private async getArtifacts ( spec : ArtifactSpec ) : Promise < CompilationArtifact [ ] > {
58
+ private async getArtifacts (
59
+ spec : ArtifactSpec ,
60
+ env ?: Record < string , string > ,
61
+ ) : Promise < CompilationArtifact [ ] > {
59
62
const artifacts : CompilationArtifact [ ] = [ ] ;
60
63
61
64
try {
@@ -78,6 +81,7 @@ export class Cargo {
78
81
}
79
82
} ,
80
83
( stderr ) => this . output . append ( stderr ) ,
84
+ env ,
81
85
) ;
82
86
} catch ( err ) {
83
87
this . output . show ( true ) ;
@@ -90,6 +94,7 @@ export class Cargo {
90
94
async executableFromArgs ( runnableArgs : CargoRunnableArgs ) : Promise < string > {
91
95
const artifacts = await this . getArtifacts (
92
96
Cargo . artifactSpec ( runnableArgs . cargoArgs , runnableArgs . executableArgs ) ,
97
+ runnableArgs . environment ,
93
98
) ;
94
99
95
100
if ( artifacts . length === 0 ) {
@@ -106,8 +111,9 @@ export class Cargo {
106
111
cargoArgs : string [ ] ,
107
112
onStdoutJson : ( obj : any ) => void ,
108
113
onStderrString : ( data : string ) => void ,
114
+ env ?: Record < string , string > ,
109
115
) : Promise < number > {
110
- const path = await cargoPath ( ) ;
116
+ const path = await cargoPath ( env ) ;
111
117
return await new Promise ( ( resolve , reject ) => {
112
118
const cargo = cp . spawn ( path , cargoArgs , {
113
119
stdio : [ "ignore" , "pipe" , "pipe" ] ,
@@ -133,29 +139,12 @@ export class Cargo {
133
139
}
134
140
}
135
141
136
- /** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
137
- export async function getSysroot ( dir : string ) : Promise < string > {
138
- const rustcPath = await getPathForExecutable ( "rustc" ) ;
139
-
140
- // do not memoize the result because the toolchain may change between runs
141
- return await execute ( `${ rustcPath } --print sysroot` , { cwd : dir } ) ;
142
- }
143
-
144
- export async function getRustcId ( dir : string ) : Promise < string > {
145
- const rustcPath = await getPathForExecutable ( "rustc" ) ;
146
-
147
- // do not memoize the result because the toolchain may change between runs
148
- const data = await execute ( `${ rustcPath } -V -v` , { cwd : dir } ) ;
149
- const rx = / c o m m i t - h a s h : \s ( .* ) $ / m;
150
-
151
- const result = unwrapNullable ( rx . exec ( data ) ) ;
152
- const first = unwrapUndefinable ( result [ 1 ] ) ;
153
- return first ;
154
- }
155
-
156
142
/** Mirrors `toolchain::cargo()` implementation */
157
143
// FIXME: The server should provide this
158
- export function cargoPath ( ) : Promise < string > {
144
+ export function cargoPath ( env ?: Record < string , string > ) : Promise < string > {
145
+ if ( env ?. [ "RUSTC_TOOLCHAIN" ] ) {
146
+ return Promise . resolve ( "cargo" ) ;
147
+ }
159
148
return getPathForExecutable ( "cargo" ) ;
160
149
}
161
150
0 commit comments