Skip to content

Instantly share code, notes, and snippets.

@kumar8600
Last active November 20, 2016 08:58
Show Gist options
  • Save kumar8600/62f48235d212a3b3f2e615f3953d277c to your computer and use it in GitHub Desktop.
Save kumar8600/62f48235d212a3b3f2e615f3953d277c to your computer and use it in GitHub Desktop.
Generates cargo executable project and debugging configurations for vscode.
# -*- coding: utf-8 -*-
"""Generates cargo executable project and debugging configurations for vscode.
Calls `cargo new <project_name> --bin`
and generates vscode configurations for debugging via the Native Debug extension.
Usage: python gen_cargo_vscode.py <project_name>
"""
import sys
import os
import subprocess
from string import Template
def main():
"""A main function.
"""
project_name = sys.argv[1]
subprocess.check_call(["cargo", "new", project_name, "--bin"])
os.mkdir("{}/.vscode".format(project_name))
launch_template = Template("""\
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "gdb",
"request": "launch",
"target": "./target/debug/${project_name}",
"cwd": "$${workspaceRoot}",
"preLaunchTask": "build",
"internalConsoleOptions": "openOnSessionStart"
}
]
}
""")
launch_file = open("{}/.vscode/launch.json".format(project_name), 'w')
launch_file.write(launch_template.substitute(project_name=project_name))
launch_file.close()
tasks_file = open("{}/.vscode/tasks.json".format(project_name), 'w')
tasks_file.write("""\
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "cargo",
"isShellCommand": true,
"args": [],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "build",
"args": ["build"]
}
]
}
""")
tasks_file.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment