Using Visual Studio Code for ARM Development – Build Tasks

It isn’t strictly necessary to use Visual Studio Code to build your code. You can still drop to the command line and build it more directly. However, it is handy to be able to build with a shortcut key or not have to manage another window.

For my example code, I have a Makefile that I use with “make all” as the default target, and “make clean” to delete everything.

You can set up custom tasks within VSCode that can execute any shell command, even specifying which shell to use. There is a special “Default Build” task.

To start, select the “Task” menu, then “Configure Tasks”. If this is the first time, it will ask for a type – select “Others”; VSCode will create the .vscode/tasks.json file for you.

I have the following in my tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Make",
            "type": "shell",
            "command": "make",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "taskName": "Make Clean",
            "type": "shell",
            "command": "make clean",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared"
            },
            "group": "build"
        }
    ]
}

The first task just runs the command-line “make”. The Terminal pane will be opened to show the results. This is the default build task, so it can be performed using ctrl-shift-B.

The second task is similar, but it runs “make clean”. It doesn’t have a defined shortcut key. However, this can be performed by selecting Tasks/Run Task from the menu or alt-shift-B. You can then select from the defined tasks.

(VSCode does have configurable keybindings, so if you want to assign a task to a shortcut key, you can do this easily!)

A caveat: GNU Make does not play particularly well with Windows. While my current project Makefile does work, I have had other Makefiles that will not run under the Windows cmd shell. In those cases, I had to use the MinGW shell. While it is possible to specify other shell executables from the tasks.json file, I have not figured out how use the MinGW shell. The new Linux Subsystem could be an alternative solution, but I have not yet tried it. This should work without problems on Linux and Mac.

Leave a Reply

1 Comment on "Using Visual Studio Code for ARM Development – Build Tasks"

Notify of
avatar
Sort by:   newest | oldest | most voted
hubmartin
Guest

Hello, thanks for these tutorials. In case someone would like to use Black Magic Probe with VS Code, I’ve created short article how to configure launch.json. It need some tweaking but works perfectly.
https://sites.google.com/site/hubmartin/arm/black-magic-probe-vs-code

wpDiscuz