{"id":30481,"date":"2022-04-25T16:57:46","date_gmt":"2022-04-25T16:57:46","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=30481"},"modified":"2022-04-25T19:21:18","modified_gmt":"2022-04-25T19:21:18","slug":"customizing-github-codespaces-for-cpp-projects","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/customizing-github-codespaces-for-cpp-projects\/","title":{"rendered":"Customizing GitHub Codespaces for C++ Projects"},"content":{"rendered":"<blockquote><p>&#8220;There&#8217;s no worse punishment than worthless, hopeless labor.&#8221; \u2014 <em>The Myth of Sisyphus<\/em> by Albert Camus<\/p><\/blockquote>\n<p>Configuring a development environment for a non-trivial C++ project is a process that can be error-prone, tedious, and time-consuming. For would-be contributors to projects, struggling with these initial steps can be a frustrating introduction to a project. Even seasoned developers may run into issues with their existing development environments when working on projects that have different, and sometimes conflicting, dependencies.<\/p>\n<p>A <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/using-github-codespaces-and-visual-studio-code-for-cplusplus-development\/\">GitHub Codespace<\/a> provides a cloud-hosted development container that can be customized specifically for a project, even permitting different customizations for different branches. In this walkthrough, you&#8217;ll learn how to create a codespace, customize the development container, and configure Visual Studio Code&#8217;s C++ extensions by walking through the steps for the <a href=\"https:\/\/github.com\/microsoft\/vcpkg-tool\">vcpkg-tool<\/a> repository.<\/p>\n<p>&nbsp;<\/p>\n<h2>Preparation<\/h2>\n<p>&nbsp;<\/p>\n<h3>Availability of GitHub Codespaces<\/h3>\n<p>GitHub Codespaces are currently available to GitHub accounts that are members of organizations on a <a href=\"https:\/\/docs.github.com\/en\/get-started\/learning-about-github\/githubs-products#github-team\">GitHub Team<\/a> or <a href=\"https:\/\/docs.github.com\/en\/get-started\/learning-about-github\/githubs-products#github-enterprise\">GitHub Enterprise Cloud<\/a> plan. Access for individual users is currently in <a href=\"https:\/\/github.com\/features\/codespaces\/signup\">beta<\/a> testing. An organization owner can <a href=\"https:\/\/docs.github.com\/en\/codespaces\/managing-codespaces-for-your-organization\/enabling-codespaces-for-your-organization\">enable or disable codespaces for an organization<\/a> and <a href=\"https:\/\/docs.github.com\/en\/billing\/managing-billing-for-github-codespaces\/managing-spending-limits-for-codespaces\">set spending limits<\/a> with only a few clicks. Organization owners can also apply policies that <a href=\"https:\/\/docs.github.com\/en\/codespaces\/managing-codespaces-for-your-organization\/restricting-access-to-machine-types\">restrict what machine types<\/a> are available to repositories in order to prevent excessive resource usage. If you are a C++ developer that currently does not have access to this feature, we&#8217;d like to <a href=\"https:\/\/www.surveymonkey.com\/r\/QLCBY56\">learn more (survey link)<\/a> about your environment and interest in the feature.<\/p>\n<h3>Preparing your vcpkg-tool repository<\/h3>\n<p>vcpkg-tool is the repository for the front-end executable of the <a href=\"https:\/\/vcpkg.io\/\">vcpkg dependency manager<\/a>, which helps you manage C and C++ libraries for your project. The vcpkg ecosystem currently has around 2000 distinct <a href=\"https:\/\/vcpkg.io\/en\/packages.html\">packages<\/a> in its catalog. You can learn more about vcpkg at the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/category\/vcpkg\/\">Microsoft C++ Blog<\/a>. Since you are unlikely to have permissions to modify the <a href=\"https:\/\/github.com\/microsoft\/vcpkg-tool\">microsoft\/vcpkg-tool<\/a> directly, you should use GitHub&#8217;s fork feature to obtain a copy of the repository into an account that you control. Navigate to <a href=\"https:\/\/github.com\/microsoft\/vcpkg-tool\">https:\/\/github.com\/microsoft\/vcpkg-tool<\/a>, login, and click the <strong>Fork<\/strong> button for the repository. On the following page, click the <strong>Create fork<\/strong> button.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/github-fork-vcpkg-tool.png\" alt=\"Screenshot of page to create a fork for the microsoft\/vcpkg-tool repository.\" \/><\/p>\n<p>After a few seconds, you should have a vcpkg-tool repository that you control and from which you can submit pull requests to the upstream repository. Since this is an active repository, the requirements for building it might have changed since this was written. So that you can reliably follow along, you should create a branch from commit <code>48006ab<\/code> and work from that point in history. To create a branch from that specific commit, append <code>\/tree\/48006ab<\/code> to the URL for your forked vcpkg-tool repository to browse the repository at that point in history, then click the dropdown branch button on the left of the page (it should show the commit hash <code>48006ab73a<\/code>), type in the desired name for your branch, and then click <strong>Create branch: &lt;your-branch-name-here&gt; from &#8216;48006ab&#8217;<\/strong>. Now, let&#8217;s explore the repository some to get an understanding of what is required to be able to build and test the project.<\/p>\n<p>&nbsp;<\/p>\n<h2>Using github.dev to Explore a Repository with Visual Studio Code<\/h2>\n<p><a href=\"https:\/\/github.dev\">github.dev<\/a> is an instance of Visual Studio Code running in the browser, with no backing computation or storage behind it. It allows you to use many of the editor features of Visual Studio Code, including source control operations and many extensions, without requiring a clone of the repository or any tools beyond a web browser. It is a great way to explore a repository or to make simple changes that do not require building or testing your code. We&#8217;ll use it to explore our newly created repository so that we know what we need to do to properly set up a build and test environment for our codespace later on. This allows us to do a lot of the &#8220;busy work&#8221; without incurring charges for a codespace environment.<\/p>\n<p>Press the <strong>.<\/strong> (period) key on your keyboard to open up github.dev for that repository. Alternatively, you can change the <code>github.com<\/code> domain for the URL to <code>github.dev<\/code> and load that web page. This works for any GitHub repository. After Visual Studio Code loads in the browser, you should notice that the Remote &#8220;Quick Access&#8221; status bar button in the lower left will indicate that you are connected directly to GitHub.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/github-dev-remote-quick-access.png\" alt=\"Screenshot of the Remote &quot;Quick Access&quot; status bar showing a connection to GitHub\" width=\"418\" height=\"63\" \/><\/p>\n<p>Feel free at this time to familiarize yourself with the features of Visual Studio Code by opening up the Command Palette by pressing <strong>Ctrl+Shift+P<\/strong> (<strong>Cmd+Shift+P<\/strong> on macOS) and running the <strong>Get Started: Open Walkthrough.<\/strong>.. command and selecting a walkthrough. Once you feel comfortable progressing, continue on with our exploration of the repository.<\/p>\n<h3>Build and Test Prerequisites<\/h3>\n<p>If you read through the Markdown (<code>.md<\/code>) files in the root of the repository and in the <code>docs\/<\/code> directory, you&#8217;ll find a handful of tools that will need to be installed in order to build and test the repository. You may find further requirements in the root <code>CMakeLists.txt<\/code> file, such as requiring a C++17-capable compiler. The collection of things that must exist on the system in order to work in the project are:<\/p>\n<ul>\n<li>A C++17-capable compiler that CMake recognizes<\/li>\n<li>CMake 3.15 or higher<\/li>\n<li>A build system that CMake can generate files for (e.g. Ninja)<\/li>\n<li>A copy of the <a href=\"https:\/\/github.com\/microsoft\/vcpkg\">primary vcpkg repository<\/a>, and an environment variable <code>VCPKG_ROOT<\/code> that you&#8217;ve set to its location<\/li>\n<li>clang-format for formatting source code according to the style provided by the <code>.clang-format<\/code> file<\/li>\n<\/ul>\n<p>Now we are ready to create our codespace!<\/p>\n<p>&nbsp;<\/p>\n<h2>Creating and Managing Your Codespace<\/h2>\n<p>There are several ways you can create a new codespace for your newly forked vcpkg-tool repository.<\/p>\n<ul>\n<li>On the default page for your repository on github.com, you can click the <strong>&lt;&gt; Code<\/strong>\u00a0button, click the <strong>Codespaces<\/strong> tab, and click the <strong>Create codespace on <em>&lt;branch-name&gt;<\/em><\/strong> button where <strong><em>&lt;branch-name&gt;<\/em><\/strong> is the name of the currently selected branch.. This button is actually a <a href=\"https:\/\/docs.microsoft.com\/windows\/win32\/windowsribbon\/windowsribbon-controls-splitbutton\">split button<\/a>, that allows you to select customizations for your codespace environment such as the checked-out branch, the machine type, the region to use for the the GitHub-managed cloud instance, and the development container (i.e. devcontainer) configuration file to use.<\/li>\n<li>At <a href=\"https:\/\/github.com\/codespaces\">https:\/\/github.com\/codespaces<\/a>, you can click the <strong>New codespace<\/strong> button and select the repository and the customization options you&#8217;d like (as described above).<\/li>\n<li>From within Visual Studio Code, you can create a codespace in two ways:\n<ul>\n<li>Open the Command Palette and run the <strong>Codespaces: Create New Codespace<\/strong> command and follow the prompts to provide the repository and customization options you&#8217;d like.<\/li>\n<li>If you have the GitHub Codespaces extension installed, you can open the Remote Explorer in the side bar, hovering your mouse over the <strong>GITHUB CODESPACES<\/strong> section and clicking the <strong>+<\/strong> icon. You will be prompted for options similar to those if you ran the command from the Command Palette.<\/li>\n<\/ul>\n<\/li>\n<li>You can create, manage, and connect to a codespace by using the <a href=\"https:\/\/cli.github.com\/\">GitHub CLI tool<\/a> and the <code>gh codespaces create<\/code> <a href=\"https:\/\/cli.github.com\/manual\/gh_codespace_create\">command<\/a>.<\/li>\n<\/ul>\n<p>Because we should already have our default page for the newly forked repository open, we&#8217;ll use that method. Click the <strong>&lt;&gt; Code<\/strong> button, click the <strong>Codespaces<\/strong> tab, and click the selection arrow on the <strong>Create codespace&#8230;<\/strong> split button and select <strong>Configure and create codespace<\/strong>. Now click the split button to load the page where we can select our customizations.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/github-new-codespace-ext.png\" alt=\"Screenshot of creating a codespace from within the repository on github.com\" \/><\/p>\n<p>On the next page, select the options you&#8217;d like. Make sure that the branch you created earlier is selected, so that the codespace loads with the correct branch already checked out.\u00a0Normally, you should let <strong>Region<\/strong> remain the default unless you know that you want your devcontainer virtual machine to be created in a specific cloud region. We&#8217;ll come back to <strong>Dev container configuration<\/strong> later on in the walkthrough.<\/p>\n<h3>Selecting a Machine Type<\/h3>\n<p>The most impactful option to choose when you are creating a new codespace is the machine type. The machine type is the combination of virtualized hardware resources that will be available to your codespace, including number of CPU cores, amount of RAM, and the size of filesystem storage. The machine types that are allowed for a codespace are controlled by a combination of organization and account settings and constraints specified by the repository for which the codespace is being created. Currently, the available machine types and their <a href=\"https:\/\/docs.github.com\/en\/billing\/managing-billing-for-github-codespaces\/about-billing-for-codespaces\">costs<\/a> (storage is an additional $0.07\/GB-month) are*:<\/p>\n<ul>\n<li>2-core, 4GB RAM, 32GB disk &#8211; $0.18\/hour<\/li>\n<li>4-core, 8GB RAM, 32GB disk &#8211; $0.36\/hour<\/li>\n<li>8-core, 16GB RAM, 64GB disk &#8211; $0.72\/hour<\/li>\n<li>16-core, 32GB RAM, 128GB disk &#8211; $1.44\/hour<\/li>\n<li>32-core, 64GB RAM, 128GB disk &#8211; $2.88\/hour<\/li>\n<\/ul>\n<p><sub>* Monetary units are in USD<\/sub><\/p>\n<p>We&#8217;ll choose the cheapest available machine type while we work to get the codespace and the development container created and customized. Select the <strong>2-core<\/strong> option from the <strong>Machine type<\/strong> drop-down button and click <strong>Create codespace<\/strong>.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/github-create-codespace-dialog-vcpkg-tool.png\" alt=\"Screenshot of codespace creation dialog\" \/><\/p>\n<p>You should see a new page load in the browser that shows status information on the starting of the codespace and the initiation of a connection to the codespace. Once the codespace is ready to go, an instance of Visual Studio Code will load in the browser, remotely connected to the codespace.<\/p>\n<h3>Managing Your Codespace<\/h3>\n<p>Your cloud-hosted codespace is available for you to connect to for as long as it exists. In order to control costs, a codespace will automatically shut down after a period of no activity, meaning you don&#8217;t have to worry about running up a large bill because you forgot to stop it before ending your workday. When you restart the codespace and reconnect, it will be in the same state it was when it shut down. Any non-committed or not-yet-pushed changes are still present, just as you left them.<\/p>\n<p>You can manage your codespace directly from within Visual Studio Code by choosing one of the <strong>Codespaces:<\/strong> commands in the Command Palette, or you can execute the fundamental commands (starting, stopping, etc&#8230;) from the <a href=\"https:\/\/github.com\/codespaces\">GitHub Codespaces web page<\/a>. You can also use the GitHub CLI to manage your codespaces if you prefer working from a terminal window or scripting actions. A subset of the Command Palette commands are also available if you click on the Remote &#8220;Quick Access&#8221; status bar button, which now shows you that you are connected to a codespace.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/github-codespaces-remote-quick-access.png\" alt=\"Screenshot of the Remote &quot;Quick Access&quot; status bar showing a connection to a codespace\" width=\"471\" height=\"59\" \/><\/p>\n<p>Let&#8217;s go ahead and stop your newly created codespace and reconnect, so that you are comfortable with the experience. Run the <strong>Codespaces: Stop Current Codespace<\/strong> from the Command Palette. You could restart the codespace by clicking on the <strong>Restart codespace<\/strong> button, but let&#8217;s see what the experience is like from the main GitHub Codespaces web page. Navigate in your browser to <a href=\"https:\/\/github.com\/codespaces\">https:\/\/github.com\/codespaces<\/a>. There, you should see your new codespace listed. If you click on the <strong>&#8230;<\/strong> to the right of your codespace entry, you&#8217;ll get a menu of management commands. If you would like to try out Visual Studio Code outside of the browser, and have it installed, click on <strong>Open in Visual Studio Code<\/strong>. Otherwise, click <strong>Open in browser<\/strong> to restart and connect to the codespace.<\/p>\n<p>After you start your codespace, you can see a change on the GitHub Codespaces web page: your codespace has the <em>Active<\/em> label applied to it, and there&#8217;s a new <strong>Stop codespace<\/strong> action available. Now that you know how to start and stop your codespace and connect to it in different ways, let&#8217;s customize the development container used for it so that we can build the vcpkg-tool repository.<\/p>\n<p>&nbsp;<\/p>\n<h2>Customizing Your Development Container<\/h2>\n<p>Development containers, or <em>devcontainers<\/em>, are customized environments capable of building a specific project, delivered using a container technology like Docker. Codespaces uses devcontainers for customizing the codespace environment, but the idea and tools are distinct and can be used for local container environments as well. In order to enable the use of devcontainers by the tools that recognize them, you have to add certain files into your repository. This allows the definition of your devcontainer to evolve along with the project itself, including tracking evolving requirements along different branches of your repository. Let&#8217;s add a <a href=\"https:\/\/code.visualstudio.com\/docs\/remote\/create-dev-container\">devcontainer specification<\/a> to our vcpkg-tool fork. GitHub recently added the ability to have <a href=\"https:\/\/github.blog\/2022-04-20-codespaces-multi-repository-monorepo-scenarios\/\">multiple devcontainer definitions in your repository<\/a>. If you have multiple devcontainer definitions, you will be prompted for which one to use whenever you initially create a codespace.<\/p>\n<p>From within your codespace, run the <strong>Codespaces: Add Development Container Configuration Files&#8230;<\/strong> command from the Command Palette. Follow the prompts and select the <strong>C++<\/strong> container configuration definition, the <strong>ubuntu21.04<\/strong> operating system version, and any of the <em>additional features to install<\/em> that you want (you won&#8217;t strictly need them for this walkthrough). Visual Studio Code will create a <code>.devcontainer<\/code> directory in the root of your project and it will contain a <code>devcontainer.json<\/code> file, a <code>Dockerfile<\/code> file, and a <code>reinstall-cmake.sh<\/code> file. The <code>reinstall-cmake.sh<\/code> file is just a helper file used by <code>Dockerfile<\/code> to help customize the version of CMake that gets installed on the system, and we can ignore its contents. You may also notice two notifications from Visual Studio Code asking whether you&#8217;d like to install recommended extensions for Docker or if you&#8217;d like to rebuild the container. Ignore them for now. Let&#8217;s take a look at the two relevant files and how we need to change them.<\/p>\n<h3>The Dockerfile<\/h3>\n<p><code>Dockerfile<\/code> is the file that Docker uses to assemble a container image. The syntax is <a href=\"https:\/\/docs.docker.com\/engine\/reference\/builder\/\">well documented<\/a> by Docker and is fairly straightforward to understand. The Dockerfile that was created for us specifies the base container image to use, copies the CMake helper script to it, and optionally runs it on the container that is being built. The Dockerfile also has commented-out commands that would use vcpkg to install specific libraries and another set of commented-out commands that would install additional packages provided by the operating system&#8217;s package manager.<\/p>\n<p>For our case, you&#8217;ll want to make the following changes (shown in &#8220;diff&#8221; format) to make sure that we are using a capable version of CMake, <code>clang-format<\/code> is installed, and that we have a copy of the vcpkg repository with the <code>VCPKG_ROOT<\/code> environment variable set. If you have additional packages you&#8217;d like installed, you can add them to the command after <code>clang-format<\/code>. After you make the changes, save the file.<\/p>\n<pre><code class=\"language-diff\">diff --git a\/.devcontainer\/Dockerfile b\/.devcontainer\/Dockerfile\r\nindex 7072fc9..4c8e31a 100644\r\n--- a\/.devcontainer\/Dockerfile\r\n+++ b\/.devcontainer\/Dockerfile\r\n@@ -6,7 +6,7 @@ FROM mcr.microsoft.com\/vscode\/devcontainers\/cpp:0-${VARIANT}\r\n\r\n # [Optional] Install CMake version different from what base image has already installed. \r\n # CMake reinstall choices: none, 3.21.5, 3.22.2, or versions from https:\/\/cmake.org\/download\/\r\n-ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE=\"none\"\r\n+ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE=\"3.23\"\r\n\r\n # Optionally install the cmake for vcpkg\r\n COPY .\/reinstall-cmake.sh \/tmp\/\r\n@@ -19,5 +19,9 @@ RUN if [ \"${REINSTALL_CMAKE_VERSION_FROM_SOURCE}\" != \"none\" ]; then \r\n # RUN su vscode -c \"${VCPKG_ROOT}\/vcpkg install &lt;your-port-name-here&gt;\"\r\n\r\n # [Optional] Uncomment this section to install additional packages.\r\n-# RUN apt-get update &amp;&amp; export DEBIAN_FRONTEND=noninteractive \r\n-#     &amp;&amp; apt-get -y install --no-install-recommends &lt;your-package-list-here&gt;\r\n No newline at end of file\r\n+RUN apt-get update &amp;&amp; export DEBIAN_FRONTEND=noninteractive \r\n+    &amp;&amp; apt-get -y install --no-install-recommends clang-format\r\n+\r\n+# Obtain vcpkg repository and set VCPKG_ROOT\r\n+RUN git clone --depth 1 https:\/\/github.com\/microsoft\/vcpkg \/vcpkg\r\n+ENV VCPKG_ROOT=\"\/vcpkg\"\r\n No newline at end of file<\/code><\/pre>\n<h3>devcontainer.json<\/h3>\n<p><code>devcontainer.json<\/code> is the file that the tools use to drive the devcontainer creation process. It has an <a href=\"https:\/\/github.com\/microsoft\/dev-container-spec\">open and evolving specification<\/a> and should soon have a <a href=\"https:\/\/github.com\/microsoft\/dev-container-spec\/issues\/9\">published reference implementation<\/a> as well. Currently, the syntax for the JSON is documented by Visual Studio Code <a href=\"https:\/\/code.visualstudio.com\/docs\/remote\/devcontainerjson-reference\">documentation<\/a>.<\/p>\n<p>We&#8217;ll want to make the following change (shown in &#8220;diff&#8221; format) to our devcontainer.json file. This change will tweak the Visual Studio Code extensions that are installed. Feel free to add any additional extensions to the list that you are interested in using. After you make the change, save the file.<\/p>\n<pre><code class=\"language-diff\">diff --git a\/.devcontainer\/devcontainer.json b\/.devcontainer\/devcontainer.json\r\nindex 60ce4dc..11560db 100644\r\n--- a\/.devcontainer\/devcontainer.json\r\n+++ b\/.devcontainer\/devcontainer.json\r\n@@ -15,8 +15,8 @@\r\n\r\n        \/\/ Add the IDs of extensions you want installed when the container is created.\r\n        \"extensions\": [\r\n-               \"ms-vscode.cpptools\",\r\n-               \"ms-vscode.cmake-tools\"\r\n+               \"ms-azuretools.vscode-docker\",      \/\/ Tools for working with Dockerfiles\r\n+               \"ms-vscode.cpptools-extension-pack\" \/\/ Collection of C and C++ extensions, including CMake\r\n        ],\r\n\r\n        \/\/ Use 'forwardPorts' to make a list of ports inside the container available locally.<\/code><\/pre>\n<p>Now that we&#8217;ve modified our container configuration files, we need to rebuild the codespace container for the changes to apply. If the notification from Visual Studio Code about rebuilding the devcontainer is still visible, you can click <strong>Rebuild Now<\/strong> on that notification, otherwise, you can rebuild the container by clicking the Remote &#8220;Quick Access&#8221; status bar button and selecting <strong>Rebuild Container<\/strong> or by running the <strong>Codespaces: Rebuild Container<\/strong> command from the Command Palette.<\/p>\n<p>Since a new Docker container image has to be created, this could take a short while. GitHub offers the ability to use GitHub Actions to <a href=\"https:\/\/docs.github.com\/en\/codespaces\/prebuilding-your-codespaces\/about-codespaces-prebuilds\">generate prebuilt images<\/a> if it turns out that you might need to create these custom container images regularly.<\/p>\n<p>Once the codespace is restarted and Visual Studio Code has reconnected, we should check and make sure that we have suitable C++ compilers installed on the system. We can do that by running some commands in the Terminal pane, which you can open up by pressing <strong>Ctrl+`<\/strong> (<em>note: that is a &#8216;backtick&#8217;<\/em>). The commands and your results should look like:<\/p>\n<pre><code class=\"language-bash\">@michaelbprice \u279c \/workspaces\/vcpkg-tool (main \u2717) $ which g++ &amp;&amp; g++ -dumpversion &amp;&amp; g++ -std=c++17\r\n\/usr\/bin\/g++\r\n10\r\ng++: fatal error: no input files\r\ncompilation terminated.\r\n@michaelbprice \u279c \/workspaces\/vcpkg-tool (main \u2717) $ which clang++ &amp;&amp; clang++ -dumpversion &amp;&amp; clang++ -std=c++17\r\n\/usr\/bin\/clang++\r\n12.0.0\r\nclang: error: no input files\r\n@michaelbprice \u279c \/workspaces\/vcpkg-tool (main \u2717) $<\/code><\/pre>\n<p>You will also notice that on the Activity Bar on the left side of Visual Studio Code, we now have icons for Docker and CMake, just as we expected. Next, we&#8217;ll configure the extensions in the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cpptools-extension-pack\">C\/C++ Extension Pack<\/a> so that we can build, test, and work with the C++ code in the project.<\/p>\n<p>&nbsp;<\/p>\n<h2>Configuring Visual Studio Code for C++<\/h2>\n<p>We have been consistently making improvements to the C++ experience in Visual Studio Code, much of which we&#8217;ve documented in <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/category\/visual-studio-code\/\">blog posts on the Microsoft C++ Blog<\/a>. This section will describe the changes you need to make, but won&#8217;t go into a lot of the details. We suggest exploring our other blog posts and <a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/introvideos-cpp\">documentation<\/a> to get a better understanding.<\/p>\n<h3>Configuring CMake with CMakePresets.json<\/h3>\n<p>CMake introduced a <a href=\"https:\/\/cmake.org\/cmake\/help\/latest\/manual\/cmake-presets.7.html?highlight=presets#manual:cmake-presets(7)\">presets<\/a> feature in version 3.19 which has continued to evolve in subsequent releases. This feature allows for the definition of idiomatic configuration, build, and test command lines for a project. This increases consistency for developers and reduces the startup overhead for new contributors. It also provides a useful way to document the common patterns in a way that is &#8220;live&#8221; and is less likely to become stale documentation. In addition to all of those benefits for individual users, it also simplifies automated systems like continuous integration systems.<\/p>\n<p>For our purposes, you should add the following <code>CMakePresets.json<\/code> file in the root of the repository. It must live directly beside the project&#8217;s root <code>CMakeLists.txt<\/code> file in order for CMake to locate it. You can do this via the Command Palette by making sure the root of the repository is selected in the Explorer and running the command <strong>File: New File<\/strong>. Then provide the name <code>CMakePresets.json<\/code> and copy the contents from here into the open JSON file in the source editor.<\/p>\n<pre><code class=\"language-json\">{\r\n    \"version\": 3,\r\n    \"configurePresets\": [\r\n        {\r\n            \"name\": \"base\",\r\n            \"hidden\": true,\r\n            \"generator\": \"Ninja\",\r\n            \"binaryDir\": \"${workspaceRoot}\/out\",\r\n            \"cacheVariables\": {\r\n                \"CMAKE_INSTALL_PREFIX\": \"${workspaceRoot}\/out\/install\/${presetName}\"\r\n            }\r\n        },\r\n        {\r\n            \"name\": \"benchmark-base\",\r\n            \"hidden\": true,\r\n            \"cacheVariables\": { \"VCPKG_BUILD_BENCHMARKING\": \"On\" }\r\n        },\r\n        {\r\n            \"name\": \"debug\",\r\n            \"displayName\": \"Debug\",\r\n            \"cacheVariables\": { \"CMAKE_BUILD_TYPE\": \"Debug\" }\r\n        },\r\n        {\r\n            \"name\": \"release\",\r\n            \"displayName\": \"Release\",\r\n            \"cacheVariables\": { \"CMAKE_BUILD_TYPE\": \"Release\" }\r\n        },\r\n        {\r\n            \"name\": \"debug-benchmarks\",\r\n            \"displayName\": \"Debug + Benchmarks\",\r\n            \"inherits\": [ \"debug\", \"benchmark-base\"]\r\n        },\r\n        {\r\n            \"name\": \"release-benchmarks\",\r\n            \"displayName\": \"Release + Benchmarks\",\r\n            \"inherits\": [ \"release\", \"benchmark-base\" ]\r\n        }\r\n    ]\r\n}<\/code><\/pre>\n<p>After saving that file, delete the existing CMake cache and reconfigure by running the <strong>CMake: Delete Cache and Reconfigure<\/strong> command from the Command Palette. Select whichever configuration you are interested in. After configuration completes you should now be able to build the project! Click the <strong>Build<\/strong> button in the status bar or press the <strong>F7<\/strong> key.<\/p>\n<h3>Configuring IntelliSense for Visual Studio Code<\/h3>\n<p>Congratulations! Because this project is using CMake and we are using the Visual Studio Code CMake extension, IntelliSense was set up based on the information that the CMake extension determined. There&#8217;s nothing additional you need to do in order to enable IntelliSense and use all of its great productivity features.<\/p>\n<p>&nbsp;<\/p>\n<h2>Summary<\/h2>\n<p>Using GitHub Codespaces and Visual Studio Code makes it easy to set up a repeatable, isolated, and accessible development environment for your C++ projects on GitHub. You can configure your environment to have all of the tools and features that a new contributor would need to get started quickly and be productive. Say goodbye to the days of new contributors struggling through hours or days of trying to get a system working, and bid farewell to having to push your not-yet-ready changes just so you can work from a different system.<\/p>\n<h3>Call to Action<\/h3>\n<p>If you are a member of an organization using GitHub Team or GitHub Enterprise Cloud, contact your organization owner today to <a href=\"https:\/\/docs.github.com\/en\/codespaces\/managing-codespaces-for-your-organization\/enabling-codespaces-for-your-organization\">get started<\/a>. If you aren&#8217;t a member of such an organization, <a href=\"https:\/\/github.com\/features\/codespaces\/signup\">sign up<\/a> for the GitHub Codespaces beta program now and optionally <a href=\"https:\/\/www.surveymonkey.com\/r\/QLCBY56\">fill out our survey<\/a> to help us understand the demand from the C++ community. Once you have access, use this walkthrough to guide you to setting up your first codespace for C++ and then try it out on your own projects!<\/p>\n<p>The vcpkg ecosystem is currently an <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/vcpkg-april-2022-release-is-now-available\/\">active, open-source community<\/a>. If you are interested in contributing to the vcpkg or vcpkg-tool projects, we&#8217;d love to have your help (<a href=\"https:\/\/twitter.com\/vcpkg_io\/status\/1515008498458931200\">we are also currently hiring<\/a>), and we encourage you to read and carefully follow the contribution sections of the respective repositories. We want to hear about your experiences with GitHub Codespaces and C++ in Visual Studio Code. Please let us know more what you liked and what improvements you&#8217;d like to see by contacting us on Twitter <a href=\"https:\/\/twitter.com\/visualc\">@VisualC<\/a> or by using the <a href=\"https:\/\/twitter.com\/search?q=%23CodespacePlusPlus\">#CodespacePlusPlus<\/a> hashtag. You can also email us at <a href=\"mailto:\/\/visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>. If you have specific features to request or bugs to report, you can open a <a href=\"https:\/\/github.com\/github\/feedback\/discussions\/categories\/codespaces-feedback\">discussion on GitHub Codespaces<\/a> or you can file bugs with us at the <a href=\"https:\/\/developercommunity.visualstudio.com\/search?space=62&amp;q=%5Bvs-cpp-roadmap&amp;stateGroup=active\">Microsoft Developer Community site<\/a>.<\/p>\n<p><strong>Happy Coding!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A walkthrough for creating a GitHub Codespace, customizing the Codespace development container, and configuring Visual Studio Code for developing in a C++ project such as microsoft\/vcpkg-tool.<\/p>\n","protected":false},"author":85414,"featured_media":30482,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,292,3920,279,272,275],"tags":[],"class_list":["post-30481","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","category-containers","category-github","category-linux","category-vcpkg","category-visual-studio-code"],"acf":[],"blog_post_summary":"<p>A walkthrough for creating a GitHub Codespace, customizing the Codespace development container, and configuring Visual Studio Code for developing in a C++ project such as microsoft\/vcpkg-tool.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/85414"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=30481"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30481\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/30482"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=30481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=30481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=30481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}