FWIW future visitors might try this script. I'm meant to be learning Rust, but I don't know much about it yet so the script's in Python.
Sample output:
Add this to your .vscode/settings.json if you're using the vadimcn.vscode-lldb extension:
"lldb.launch.sourceMap": {
"/rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src": "/Users/joeuser/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src"
}
Script
#!/usr/bin/env python3
import sys
if len(sys.argv) > 1 and sys.argv[1] in ('-h', '--help'):
print(
'This script will try to generate a "lldb.launch.sourceMap" entry you can add '
"to your .vsode/settings.json file for use with the 'vadimcn.vscode-lldb' "
'extension. This script also requirest that the python package `requests` '
'be installed for "{}"'.format(sys.executable)
)
sys.exit(1)
import requests # noqa: E402
import json # noqa: E402
from subprocess import Popen, PIPE # noqa: E402
PATH_MAP_DOC_URL = 'https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#source-path-remapping'
def get_active_toolchain_root():
sout2, _ = Popen(['rustc', '--print', 'sysroot'], stdout=PIPE).communicate()
sysroot = sout2.decode('utf_8').strip()
return '{}/lib/rustlib/src/rust/src'.format(sysroot)
def get_full_commit_hash():
sout1, _ = Popen(['rustc', '--version'], stdout=PIPE).communicate()
hsh = sout1.decode().split('(')[1].split()[0]
rsp = requests.get(
url='https://api.github.com/repos/rust-lang/rust/commits/{}'.format(hsh),
headers={'Accept': 'application/vnd.github.v3+json'}
)
rsp.raise_for_status()
return rsp.json()['sha']
def get_suggested_src_mapping(fullhash, localsrcs):
compiletime_srcdir = '/rustc/{}/src'.format(fullhash)
return json.dumps({compiletime_srcdir: localsrcs}, indent=4)
if __name__ == '__main__':
srcdir = get_active_toolchain_root()
print("\nYour active toolchain's local sources: '{}'".format(srcdir))
fullhash = get_full_commit_hash()
print("Full hash of your active toolchain's git commit: {}".format(fullhash))
sourceMap = get_suggested_src_mapping(fullhash, srcdir)
print("Add this to your .vscode/settings.json if you're using the vadimcn.vscode-lldb extension:")
print('\n\t"lldb.launch.sourceMap": {}\n'.format(sourceMap.replace('\n', '\n\t')))
print('You can read more about it here: {}\n'.format(PATH_MAP_DOC_URL))