import * as path from 'path';
import * as ra from './lsp_ext';
-import { Cargo, getSysroot } from './toolchain';
+import { Cargo, getRustcId, getSysroot } from './toolchain';
import { Ctx } from "./ctx";
import { prepareEnv } from "./run";
let sourceFileMap = debugOptions.sourceFileMap;
if (sourceFileMap === "auto") {
// let's try to use the default toolchain
+ const commitHash = await getRustcId(wsFolder);
const sysroot = await getSysroot(wsFolder);
const rustlib = path.normalize(sysroot + "/lib/rustlib/src/rust");
- sourceFileMap = { "/rustc/*": rustlib };
+ sourceFileMap = {};
+ sourceFileMap[`/rustc/${commitHash}/`] = rustlib;
}
const debugConfig = knownEngines[debugEngine.id](runnable, simplifyPath(executable), env, sourceFileMap);
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");