.. _vscode: VS Code + DevContainer ====================== Here's a guide for using Visual Studio Code (VS Code) to develop with Yocto in a containerized environment. If your host is already a Yocto-supported Linux distribution, you can also build natively — see :doc:`Native Build Environment <../native/index>`. .. admonition:: Linux distribution :class: tip When using a containerized environment for building yocto, the host does not have to be a Yocto-supported distro. Requirements ------------ - Linux system (**Ubuntu-based** distribution recommended) - Docker Engine installed and running (see `Docker Engine Installation Guide`_) - VS Code installed (see `VS Code Setup Guide`_) - VS Code **Dev Containers** extension Setup ----- **1**. Check out the BSP as described in the :doc:`BSP Setup <../../bsp-setup/index>` page. **2**. Open the BSP root folder with VS Code. - Starting from the ``scarthgap`` branch, VS Code should directly prompt you to reopen the current directory in a Container. If that is the case, **skip to step 4**. **3**. Create the folder: ``.devcontainer`` **4**. Add these files inside ``.devcontainer``: - :download:`Dockerfile `: - Keep it as it is. - :download:`devcontainer.json `: - Replace the ```` placeholder with the codename of the Yocto version used. - Replace the ```` placeholder with a supported Ubuntu Version of the used Yocto version. .. admonition:: Shared Yocto files :class: tip This setups uses shared docker volumes for Yocto cache files. For each Yocto release (e.g. mickledore, scarthgap) a different volume needs to be used to avoid cache corruption between versions. **5**. In VS Code reopen the folder in a Container. If not prompted, search for ``Dev Container: Reopen in Container`` command using ``strg + shift + P``. | The container is setup automatically to be able to build Yocto. Furthermore it configures VS Code and the environment to develop with Yocto more easily. Key aspects include: - Supported Linux distribution for building with Yocto - Shared Yocto downloads and sstate-cache in docker volume. - Yocto Project BitBake VS Code Extension - Pre-configured VS Code for Yocto Development | Finally you can set up the build directory and build images as described on the :doc:`Building Images <../../build/index>` page. Yocto Project BitBake Extension ------------------------------- The Dev Container comes with the Yocto Project BitBake VS Code Extension preinstalled. It is configured to automatically detect the build folder by the name ``build-karo``. The extension provides a GUI to manage, build and develop recipes. A devtool workspace can be created to directly edit a recipe's source and also create patches automatically. For more information on how to use the Yocto Project Extension see `Yocto Project BitBake`_. - The Yocto Project extension is configured to use ``build-karo`` as the build directory. If needed change it in the extension settings. It is also possible to define multiple build-directories, see official documentation. - When creating a new devtool workspace via the Yocto Project extension, skip SDK toolkit configuration for now, as it may cause errors in this setup. - If a build fails while using a devtool workspace, try adding the following in the ``local.conf``: .. code-block:: PACKAGE_DEBUG_SPLIT_STYLE = "debug-without-src" .. _`Docker Engine Installation Guide`: https://docs.docker.com/engine/install/ .. _`VS Code Setup Guide`: https://code.visualstudio.com/docs/setup/setup-overview .. _`Yocto Project BitBake`: https://marketplace.visualstudio.com/items?itemName=yocto-project.yocto-bitbake