Integrate with VSCode#
To integrate your custom SDK with our Simpleswitch Build Tools extension for VSCode, you will need to create a few additional files to be installed into your SDK.
Creating a recipe#
First you need to create a settings file to let VSCode know what to run when the user requests e.g. to compile.
Create a file named after the SDK flavor in your project layer, like
mkdir -p recipes-devtools/simpleswitch-vscode/
touch recipes-devtools/simpleswitch-vscode/nativesdk-simpleswitch-vscode-templates-myflavor_1.0.bb
mkdir -p recipes-devtools/simpleswitch-vscode/files
touch recipes-devtools/simpleswitch-vscode/files/myflavor.json
with the following content
SUMMARY = "vscode SimpleSwitch extension config for my SDK flavor"
require recipes-devtools/simpleswitch-vscode/nativesdk-simpleswitch-vscode-template.inc
SRC_URI:append = " \
file://myflavor.json \
"
do_install() {
install -m 0644 ${WORKDIR}/myflavor.json ${D}${datadir}/simpleswitch-vscode-templates
}
RDEPENDS:${PN} += "\
nativesdk-executable-helper \
nativesdk-zip \
"
Note
myflavor
should of course be replaced by something more meaningful.
Creating the language mapping#
Now it’s time to edit the language settings at recipes-devtools/simpleswitch-vscode/files/myflavor.json
.
{
"_debug": { "<VSCode launch.json settings for debugging go here>" },
"_startup_debug_command": "<the command to start a debug session for the application goes here>",
"_startup_command": "<the command to start the application goes here>",
"_exec_finder": "<the command to find the compiled application name goes here - see below for more details>",
"clean": "rm -rf ${workspaceFolder}/${workspace.work_dir}",
"compile": "<the command to compile goes here>",
"createproject": "unzip $(ssst get '${OECORE_NATIVE_SYSROOT}/usr/share/simpleswitch-vscode-templates/project-template-myflavor.zip') -d ${workspaceFolder}",
"deploy": "simpleswitch-deploy-package ${configuration.allow_update} --work-dir ${workspace.work_dir} --start ${workspace.container_name} ${configuration.board_ip}",
"extrapackages": "<the command to install 3rd party packages goes here>",
"meta-recommended-extension": [
"<a list of VSCode extension you would recommend with the language framework goes here>"
],
"package": "<the command to create a SimpleSwitch™ package goes here>"
}
The individual commands can make use of a variety of dynamic variables, depending on the SDK and configuration used. For instance all environment variables of the SDK, as they would be available to you from the command line, can be used.
For the available variables to be used in this template, please see the Simpleswitch Build Tools extension documentation.
Example#
If your custom SDK uses classic Makefiles and can be debugged with GDB, it could look like this
{
"_debug": {
"args": [],
"cwd": "${workspaceFolder}",
"environment": [],
"miDebuggerPath": "${env:GDB}",
"miDebuggerServerAddress": "${configuration.board_ip}:2159",
"MIMode": "gdb",
"name": "SimpleSwitch: debug",
"program": "${workspace.source_location}/${workspace.application_name}",
"request": "launch",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"ignoreFailures": true,
"text": "-enable-pretty-printing"
}
],
"stopAtEntry": true,
"type": "cppdbg"
},
"_startup_command": "${workspace.application_name} ${workspace.opt_args}",
"_startup_debug_command": "while true; do gdbserver :2159 ${workspace.application_name} ${workspace.opt_args}; done",
"_exec_finder": "find-executables ${workspaceFolder}/${workspace.source_location}",
"clean": "make -C ${workspaceFolder}/${workspace.source_location} clean; rm -rf ${workspaceFolder}/${workspace.work_dir}",
"compile": "make -C ${workspaceFolder}/${workspace.source_location} -j$(nproc)",
"createproject": "unzip $(ssst get '${OECORE_NATIVE_SYSROOT}/usr/share/simpleswitch-vscode-templates/project-template-c.zip') -d ${workspaceFolder}",
"deploy": "simpleswitch-deploy-package ${configuration.allow_update} --work-dir ${workspaceFolder}/${workspace.work_dir} --start ${workspace.container_name} ${configuration.board_ip}",
"extrapackages": "",
"meta-recommended-extension": [
"ms-vscode.cpptools"
],
"package": "simpleswitch-generate-package --name ${workspace.container_name} --template myflavor --makefile-dir ${workspaceFolder}/${workspace.source_location} --startup-command \"${workspace.startup_command}\" --copy-dir ${workspaceFolder}/externals:/ --work-dir ${workspaceFolder}/${workspace.work_dir} --size-factor ${configuration.package_size_factor} ${configuration.allow_update}"
}
Tip
you can also write more complex scriptlets as a JSON list of strings.
They will be concatenated with ;
.
e.g.
{
"deploy": [
"operation 1",
"operation 2",
"operation 3"
]
}
would assemble to operation 1;operation 2;operation 3
Creating a template project#
You can optionally create a project template, so users can get started easily with your addition to the SDK.
Just create a basic workspace as folder structure under recipes-devtools/simpleswitch-vscode/files/new-project
and then add
the following to recipes-devtools/simpleswitch-vscode/nativesdk-simpleswitch-vscode-templates-myflavor_1.0.bb
SRC_URI:append = " \
file://new-project \
"
do_install:append() {
install -d ${WORKDIR}/new-project
cd ${WORKDIR}/new-project; zip -rq ${D}${datadir}/simpleswitch-vscode-templates/project-template-myflavor.zip .; cd -
}
Finding applications in the workspace#
As the VSCode extension doesn’t know about the details of the compilation process of your language framework, it cannot predict how the resulting code or binary is called.
By adding instructions to _exec_finder
in recipes-devtools/simpleswitch-vscode/files/myflavor.json
you can give the user
a way to pick the right result from a list directly out of the VSCode IDE.
Basically these are tiny tools that scan the workspace in VSCode for application that can be run.
We offer a few utilities that already come with our SimpleSwitch™ SDK
find-executables
will look for executables, such a compiled programs and shell scriptsfind-python-paths
will look for python modules and files to be runfind-flutter-apps
will look for application names of Flutter projects [1]
You can also combine multiple tools in one run, e.g.
{
"_exec_finder": "find-executables ${workspaceFolder}/${workspace.source_location}; find-python-paths ${workspaceFolder}"
}
would look for executables, shell scripts and any kind of python code.
Notes