Compiler Tools Layout in Visual Studio 2017

点这里看中文版

This post was written by Andrew Pardoe, Mark Levine, and Iyyappa Murugandi.

Thank you for your feedback! We’ve made some changes to the layouts based on your feedback.

Update Dec 8 2016 Finding the location of a VC++ install: Some folks have asked about how to find instances of Visual C++ on a developer’s machine. There’s no longer a registry key you can query. If you can launch a VS command prompt, you’ll find that the %VCInstallDir% environment variable points to the root of the VC++ install. If you need to query the install programmatically, you’ll need to query COM to find instances of Visual Studio and VC++. Heath Stewart has written a great blog post on this topic with sample code in many languages.

You’ll see many improvements for C++ developers in Visual Studio 2017 as soon as you load your first project. But some of the changes in the product aren’t so obvious. One in particular might surprise you: we’ve moved where the MSVC compiler toolset is laid out on disk.

Why we moved the compiler toolset

The layout of the compiler tools on the disk in VS 2015 reflects decisions made years ago. When we shipped Visual Studio .NET in 2002, we shipped compilers that targeted only the x86 architecture. The x64 and Itanium architectures had only recently been announced when development of Visual Studio .NET started. The layout of the compiler on-disk reflected a world where x86 was the only compiler you would need.

When we introduced support for the Itanium and x64 architectures we added the compilers where it made sense: in the bin directory. We already had a compiler for x86 in the bin directory, so we added subdirectories x86_ia64 and x86_amd64 for compilers that run on x86 and target 64-bit platforms as well as an amd64 directory for compilers that run on x64.

Unfortunately, it didn’t stop there. We added compilers for ARM. And we added cross-targeting compilers that are hosted on x64 and target x86 and ARM. Eventually we ended up with a directory tree that made little sense. Every time a developer wants to write automation that deals with our compilers they have to write special cases in their scripts for the x86 hosted and targeting compiler. Moreover, this layout limits our ability to do interesting things such as having two versions of a compiler or two different compilers installed side-by-side on the one build machine.

Where the compiler toolset moved to in VS 2017

First, let’s discuss the major parts of the compiler toolset. These are reflected in the top-level directory, e.g., %ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\VC. (Note that this directory, %VCINSTALLDIR%, changed from its VS 2015 location of %ProgramFiles(x86)%\Microsoft Visual Studio 14\VC.)

  • Tools: The tools are what you traditionally think of as the MSVC compiler toolset. This includes the old bin, crt, include, and lib directories and the binaries that are placed in them. These binaries include cl.exe and link.exe as well as header files and link libraries for the Visual C++ runtime.
  • Redist: The redistributable directory contains files that can be redistributed by the end developer with the built application. The CRT redistributables are located here, as well as the other runtimes such as those for AMP and OpenMP.
  • Auxiliary: The auxiliary directory contains tools and scripts that are not part of the compilation process but are needed to help with various compilation scenarios. These include files like the CppCoreCheckers or the Unit Test libraries as well as the vcvars*.bat scripts used to configure developer environments.

Note that the compiler toolset layout in Preview 5 is just that–a preview. We may end up changing the layout or even the top-level %VCINSTALLDIR% directory depending on feedback and requirements from internal and external developers.

The tools directory

Let’s take a closer look at the Tools directory–the directory contains the compiler toolsets. Unlike in VS 2015, the Microsoft Visual C++ compiler is in a directory called MSVC. If you installed the “Clang with Microsoft Codegen” option, you’ll see a directory next to MSVC called ClangC2 that contains the Clang/C2 binaries.

path1

There’s a subdirectory in the MSVC directory with a compiler version number. For VS 2017 RC, that version number is 14.10.24629. In that directory are the familiar subdirectories from the %VCINSTALLDIR% directory in VS 2015: bin, crt, include, and lib.

We’ve encountered two big differences so far. First, the MSVC directory means that the Visual C++ tools can sit beside another toolset, in this instance, ClangC2. Second, the fact that the tools are versioned inside of the MSVC directory means that we can have multiple versions of the Visual C++ compiler installed on the same build machine. Right now, there’s no simple way to install multiple versions. But we’ve designed the directory structure to make it possible in the future to easily switch between versions of the Visual C++ tools.

Hosts and targets

We find even more changes when looking inside the 14.10.24629\bin directory. While in VS 2015 the x86 toolset was the “standard” toolset and we had directories with names like amd64_arm representing the AMD64-ARM cross-targeting compiler, in VS 2017 these have been split up into directories labelled HostXXX and a subdirectory called x86 or x64. What’s the distinction here?

path2

Let’s pause to define a couple of terms. “Host” refers to the platform that the compiler toolset runs on. “Target” refers to the platform that the compiler builds applications to run on. In the VS 2015 world, amd64_arm included the compilers that were hosted on x64, and targeted ARM. In VS 2017 it’s more structured: all of the x64 hosted compilers live in a directory called HostX64. In that directory we find x86, x64, etc., indicating the target architecture.

The bin directory is the only one with a set of HostXXX directories. This is because the executables need to run on the host. The include directory, which contains only source files, is specific to neither the host nor the target. The lib directory is specific to only the target architecture. Likewise, many of the tools in the Auxiliary directory are specific to the target architecture but not to the host.

Benefits of the new layout

We hope you can see that there are a lot of benefits to refreshing our compiler toolset layout on disk. As Visual C++ grows to include more scenarios like Android and iOS targeting we need to include more compiler toolsets. And as we release our tools more frequently we increase the chance that our developers might want to have multiple versions of the Visual C++ compiler tools installed side-by-side. This new layout is flexible and extensible and should (hopefully!) serve us for many years to come.

As in VS 2015, the Windows SDKs are not installed alongside the Visual C++ binaries, headers and libs. They are installing in the same location under the Program Files(x86) directory. Visual C++ SDKs (such as the DIA SDK) will continue to be installed alongside the VC++ toolset.

Drawbacks of the new layout

Even though change can be good, it’s still change. We know that a lot of people have scripts that are going to break with this layout change. We decided to do this with VS 2017 as we also had to change the top-level directory to accommodate restrictions with the new installer. But any change can be a breaking change.

Please, please, please check out the scripts that you use and make sure you can migrate them to use the new layout. We want to know if you run into any problems. We want to know how hard the migration experience was for your code. Please leave comments on this blog post or send mail directly to our team at visualcpp@microsoft.com.

Finding the default MSVC tools

One last note: a lot of build systems need to find the default version of the Visual C++ tools. When you install Visual Studio it creates a file, %VCINSTALLDIR%\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt, that contains the version string for the default toolset installed with VS. In a typical Preview 5 installation, %VCINSTALLDIR% would point to %Program Files(x86)%\Microsoft Visual Studio\Visual Studio 15.0\Common7\IDE\VisualCpp.

You can parse this file with one extra line and variable in your command script:

@rem set BINDIR=get directory for x86-hosted, x86-targeting binaries
set /P VCTOOLS_VERSION=<"%VCINSTALLDIR%\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
set BINDIR=%VCINSTALLDIR%\Tools\MSVC\%VCTOOLS_VERSION%\bin\HostX86\x86

Feedback

You’ll see a number of benefits from the new layout of the compiler toolset but we know that a lot of you will have to fix up scripts that you might not have looked at for years. We’re working on making this experience simple and smooth for everyone so please do reach out to us with details of your experience. If you have feedback on any part of this design please let us know in the comments below or by mailing visualcpp@microsoft.com. Thank you!

 

Known issue

Update 10/10/2016: It turns out that Tools->Visual Studio Command Prompt can’t find vcvars32.bat when it launches. This issue has been fixed for the next release. In the interim, please launch a developer command prompt from the Windows shell, e.g., from the Start button or by pinning it to your Taskbar.