- Edited
After a little tinkering, I've come up with a way to get working syntax checking and refactoring for Bela projects in VSCode. I prefer working with the build scripts with Bela, but I miss the syntax checking in the browser IDE for catching silly errors. I'm not a big fan of Eclipse myself, so I figured I'd try to get VSCode to recognize Bela projects.
The Eclipse workspace tutorial, using @AndyCap 's awesome cross-compiler, is a good starting point, so all that really needs to be done is to set the include and compiler paths, and set up a build task for building the project.
Here's how I did it for my system (I'm on macOS 10.13):
- If you don't already have it, install the C/C++ for VSCode extension.
- Follow the Eclipse tutorial until you get to "Setup Eclipse."
- The
SyncBelaSysroot.sh
script doesn't currently copy the newlibraries
folder correctly, so from your Bela root directory, runcp -r libraries/ /usr/local/linaro/BelaSysroot/root/Bela/include
- Now, in your VSCode workspace, open or create
.vscode/c_cpp_properties.json
and add the following under"configurations"
:
Restart the IDE. If all goes well, all the handy features like refactoring, code completion, and syntax checking should now work in your Bela project. Note that since this configuration is local to the current workspace, you'll have to do the same setup in any other Bela projects you want to work on in VSCode.{ "configurations": [ { "name": "Bela", "includePath": [ "/usr/local/linaro/BelaSysroot/root/Bela/include", "/usr/local/linaro/BelaSysroot/usr/include", "/usr/local/linaro/BelaSysroot/usr/local/include" ], "intelliSenseMode": "gcc-x64", "compilerPath": "/usr/local/linaro/arm-bela-linux-gnueabihf/bin/arm-bela-linux-gnueabihf-g++", } ], "version": 4 }
For the build task, I have a little script called ./build.sh
in my project's root directory. It essentially calls the Bela build script build_project.sh
with a few arguments, which you can obviously customize:
#/bin/sh
../path/to/Bela/scripts/build_project.sh . --force -c "-H -6 --disable-led 1"
To set this script as the default build task in your workspace, open or create .vscode/tasks.json
and add this:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "./build.sh",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Now, you can build the project on the Bela by selecting Terminal > Run Build Task
in the menu bar.
Let me know if this works for other people! I have not implemented all of the features that the Eclipse tutorial does, namely debug builds and the oscilloscope. The cross-compiler's gdb
executable should probably work with VSCode, I haven't tested it though. The oscilloscope is still accessible by going to http://bela.local/scope/
in a browser while a Scope project is running. Still, I'm glad that it works as well as it does, and I bet a similar process could be used to get this working in other IDEs too.
edit: SyncBelaSysroot.sh misbehaves if /usr/local/linaro
and its children are not owned by your user, fix this by running sudo chown yourUser /usr/local/linaro
and sudo chown yourUser /usr/local/linaro/*
and running the script again.