about summary refs log tree commit diff
path: root/editors/code/src/toolchain.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/toolchain.ts')
-rw-r--r--editors/code/src/toolchain.ts20
1 files changed, 19 insertions, 1 deletions
diff --git a/editors/code/src/toolchain.ts b/editors/code/src/toolchain.ts
index a5dc3cf0ccf..68826c478d3 100644
--- a/editors/code/src/toolchain.ts
+++ b/editors/code/src/toolchain.ts
@@ -4,7 +4,7 @@ import * as path from 'path';
 import * as fs from 'fs';
 import * as readline from 'readline';
 import { OutputChannel } from 'vscode';
-import { log, memoize } from './util';
+import { execute, log, memoize } from './util';
 
 interface CompilationArtifact {
     fileName: string;
@@ -121,6 +121,24 @@ export class Cargo {
     }
 }
 
+/** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
+export function getSysroot(dir: string): Promise<string> {
+    const rustcPath = getPathForExecutable("rustc");
+
+    // do not memoize the result because the toolchain may change between runs
+    return execute(`${rustcPath} --print sysroot`, { cwd: dir });
+}
+
+export async function getRustcId(dir: string): Promise<string> {
+    const rustcPath = getPathForExecutable("rustc");
+
+    // do not memoize the result because the toolchain may change between runs
+    const data = await execute(`${rustcPath} -V -v`, { cwd: dir });
+    const rx = /commit-hash:\s(.*)$/m.compile();
+
+    return rx.exec(data)![1];
+}
+
 /** Mirrors `toolchain::cargo()` implementation */
 export function cargoPath(): string {
     return getPathForExecutable("cargo");