-
Notifications
You must be signed in to change notification settings - Fork 628
How to build FAST with Visual Studio 2019+CMake+Ninja on Windows #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
076effa
Add curl via vcpkg to WIndows builds
maxgolov 0f13e20
Merge branch 'main' of http://github.com/open-telemetry/opentelemetry…
maxgolov 840dba2
CMake+ninja build process plus clean-up of build warnings associated …
maxgolov 6dbb610
Merge branch 'main' of http://github.com/open-telemetry/opentelemetry…
maxgolov 5521c10
Formatting cleanup
maxgolov 095e489
Update building-with-vs2019.md
maxgolov 26297ea
Update building-with-vs2019.md
maxgolov c4e3942
Update building-with-vs2019.md
maxgolov 0730e51
Update building-with-vs2019.md
maxgolov a0ddc06
Fix typo
maxgolov af46050
Update CMakeLists.txt
maxgolov 6757293
Merge branch 'main' into maxgolov/winbuild_with_ninja
maxgolov 1a4df5c
Merge branch 'main' of http://github.com/open-telemetry/opentelemetry…
maxgolov 55cd43a
Merge branch 'maxgolov/winbuild_with_ninja' of http://github.com/open…
maxgolov 6c1423c
Merge branch 'main' into maxgolov/winbuild_with_ninja
maxgolov 96bdb90
Merge branch 'main' into maxgolov/winbuild_with_ninja
lalitb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| # Building OpenTelemetry C++ SDK with Visual Studio 2019, CMake and Ninja | ||
|
|
||
| ## Preface | ||
|
|
||
| These instructions are focused on developers and integrators, providing a hassle-free | ||
| and FAST option of building OpenTelemetry C++ SDK with Visual Studio on Windows. | ||
|
|
||
| The process is optimized for both scenarios: | ||
|
|
||
| - SDK developer experience on developer machine. | ||
| - final product CI/CD pipeline. | ||
|
|
||
| ## Build System Components | ||
|
|
||
| Visual Studio 2019 is a Full-featured integrated development environment (IDE) for | ||
| Android, iOS, Windows, web, and cloud. There are three editions: | ||
|
|
||
| - FREE [Community Edition](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=16) | ||
| - [Professional Edition](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Professional&rel=16) | ||
| - [Enterprise Edition](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Enterprise&rel=16) | ||
|
|
||
| There is also no-IDE 'headless' set of command line tools available as | ||
| `Visual Studio 2019 Build Tools` package. You may install it on Windows | ||
| via [Chocolatey package manager](https://community.chocolatey.org/packages/visualstudio2019buildtools). | ||
|
|
||
| You may also use Visual Studio with Windows 10 Subsystem for Linux to cross-compile | ||
| the SDK [targeting Linux distributions](https://code.visualstudio.com/docs/cpp/config-wsl). | ||
| Linux build process is largely identical to Windows process described below, | ||
| with `tools/setup-buildtools.sh` and `tools/build.sh` running on Linux. | ||
|
|
||
| Older versions of Visual Studio, such as 2015 and 2017 are known to work well | ||
| with CMake and Ninja. However, these old versions are not covered by instructions | ||
| below. If you would like to contribute additional instructions for older versions, | ||
| feel free to contribute a Pull Request detailing your build experience with older | ||
| versions. | ||
|
|
||
| [CMake](https://cmake.org/) is cross-platform free and open-source software for | ||
| build automation, testing, packaging and installation of software by using a | ||
| compiler-independent method. CMake is not a build system but rather it generates | ||
| another system's build files. | ||
|
|
||
| [MSBuild](https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2019) | ||
| is a default build system used by Visual Studio for loading and building software | ||
| projects. | ||
|
|
||
| [Ninja](https://ninja-build.org/) is a small build system with a focus on speed. | ||
| It differs from other build systems in two major respects: it is designed to have | ||
| its input files generated by a higher-level build system, and it is designed | ||
| to run builds as fast as possible. | ||
|
|
||
| [Chocolatey package manager](https://chocolatey.org/) has the largest online registry | ||
| of Windows packages. Chocolatey packages encapsulate everything required to manage | ||
| a particular piece of software into one deployment artifact by wrapping installers, | ||
| executables, zips, and/or scripts into a compiled package file. | ||
|
|
||
| [vcpkg](https://vcpkg.io/en/index.html) is a free C/C++ package manager for acquiring | ||
| and managing libraries. Choose from over 1500 open source libraries to download | ||
| and build in a single step or add your own private libraries to simplify your | ||
| build process. Maintained by the Microsoft C++ team and open source contributors. | ||
|
|
||
| ## Installing Prerequisites | ||
|
|
||
| Please install the following software: | ||
|
|
||
| - Install Visual Studio 2019 with C/C++ development tools, including CMake tools. | ||
| [This article](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-160) | ||
| explains the fundamentals of working with CMake projects in Visual Studio. | ||
|
|
||
| - Install [Git tools for Windows](https://git-scm.com/downloads). | ||
|
|
||
| Setup script below uses Chocolatey to install the following components: | ||
|
|
||
| - `vswhere` - utility to auto-discover Visual Studio installation. | ||
| - `cmake` | ||
| - `git` | ||
| - `vcpkg` to download, compile and install 3rd party C++ libraries from source. | ||
|
|
||
| List of C++ dependencies compiled and installed via `vcpkg`: | ||
|
|
||
| - [Google Test](https://github.com/google/googletest) | ||
| - [Google Benchmark](https://github.com/google/benchmark) | ||
| - [Microsoft GSL](https://github.com/microsoft/GSL) | ||
| - [nlohmann/json](https://github.com/nlohmann/json) | ||
| - [Abseil](https://github.com/abseil/abseil-cpp) | ||
| - [Protocol Buffers](https://github.com/protocolbuffers/protobuf) | ||
| - [gRPC](https://github.com/grpc/grpc) | ||
| - [Prometheus C++ client](https://github.com/jupp0r/prometheus-cpp) | ||
| - [cURL](https://github.com/curl/curl) | ||
|
|
||
| ## Command Line Build Process | ||
|
|
||
| Start `Command Prompt` as Administrator and execute the following commands: | ||
|
|
||
| ```console | ||
| git clone --recursive https://github.com/open-telemetry/opentelemetry-cpp | ||
| cd opentelemetry-cpp | ||
| tools\setup-buildtools.cmd | ||
| tools\build.cmd | ||
| ``` | ||
|
|
||
| Let's dissect the flow: | ||
|
|
||
| ```console | ||
| git clone --recursive https://github.com/open-telemetry/opentelemetry-cpp | ||
| ``` | ||
|
|
||
| SDK will be cloned recursively with remote submodule dependencies. | ||
|
|
||
| ```console | ||
| cd opentelemetry-cpp | ||
| tools\setup-buildtools.cmd | ||
| ``` | ||
|
|
||
| The necessary build tools are installed. This step requires elevation to install | ||
| additional tooling, e.g. CMake to `Program Files`. The necessary dependencies are | ||
| being built using [vcpkg package manager](https://vcpkg.io/en/index.html). This | ||
| one-time step is time-consuming - about up to 5-10 minutes. It has to be done once | ||
| during the initial installation and configuration of build tools and dependencies. | ||
|
|
||
| ```console | ||
| tools\build.cmd | ||
| ``` | ||
|
|
||
| The build of all SDK components is done using CMake + ninja in less than couple | ||
| minutes. Above script shows you how to build both configurations: | ||
|
|
||
| - `nostd` - OpenTelemetry implementation of standard containers. | ||
| - `stdlib` - Standard Template Library containers. | ||
|
|
||
| You may execute this workflow in a docker container. Please refer to generic | ||
| instructions that detail how to [run build build tools in a docker container](https://docs.microsoft.com/en-us/visualstudio/install/build-tools-container?view=vs-2019). | ||
|
|
||
| ## Building in Visual Studio 2019 IDE | ||
|
|
||
| - Run as Administrator: `tools\setup-buildtools.cmd` to install the necessary | ||
| build tooling. This script installs all build tools and builds all 3rd party | ||
| dependencies from source using [vcpkg package manager](https://vcpkg.io/en/index.html). | ||
| - Launch Visual Studio 2019 IDE. | ||
| - Use `Open a local folder` option to open the folder where you cloned the source code. | ||
| - Right-click on `CMakeLists.txt` and choose `Generate Cache for opentelemetry-cpp`. | ||
| - In the top bar menu - select `Build -> Build All` to build SDK, Exporters and Tests. | ||
| - You can use [Google Test Adapter](https://marketplace.visualstudio.com/items?itemName=ChristianSoltenborn.GoogleTestAdapter) | ||
| Visual Studio extension to run all SDK and Exporter tests in IDE. | ||
| - You can individually select and run only given tests or examples. | ||
|
|
||
| Visual Studio provides an excellent debugging and troubleshooting experience, | ||
| with incremental builds using Ninja typically taking just one click to build | ||
| and less than a few seconds for the build to complete. | ||
|
|
||
| ## Build time comparison between `MSBuild` and `Ninja` | ||
|
|
||
| After the initial set of 3rd party dependencies have been built via | ||
| `tools\setup-buildtools.cmd`, we can benchmark the OpenTelemetry C++ SDK build | ||
| times with [MSBuild](https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2019) | ||
| vs with [Ninja](https://ninja-build.org/). | ||
|
|
||
| [ptime utility](https://community.chocolatey.org/packages/ptime) may be used | ||
| to measure the total execution time for two build configurations built in one | ||
| run: `nostd-debug` and `stdlib-debug`. | ||
|
|
||
| ### MSBuild build timing | ||
|
|
||
| ```console | ||
| set CMAKE_GEN=Visual Studio 16 2019 | ||
| ptime build.cmd | ||
| ... | ||
| Execution time: 543.701 s | ||
| ``` | ||
|
|
||
| ### Ninja build timing | ||
|
|
||
| ```console | ||
| REM Unset CMAKE_GEN= - default is ninja with autodetection of ninja.exe tool path | ||
| set CMAKE_GEN= | ||
| ptime build.cmd | ||
| ... | ||
| Execution time: 105.158 s | ||
| ``` | ||
|
|
||
| ## Conclusion | ||
|
|
||
| It is strongly recommended to build the SDK with *Ninja* since it is at least x5 | ||
| times faster than MSBuild for a full clean build. Incremental builds with *Ninja* | ||
| are also considerably faster. Each incremental build is taking about 10 seconds | ||
| total for 2 build configurations. Absolute time may differ depending on machine | ||
| being benchmarked. Relative ratio on most machines demonstrates that building | ||
| with *Ninja* build system greatly optimizes your development cycle. Not only it | ||
| saves your development time, optimizes your CI/CD cycle, but it is also much more | ||
| environmentally friendly. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we scope this option to only test code compilation?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the issue is that we have so many different test projects, and it appears like it would have to be applied to all projects that use Google Test. The warning comes from Google Test header. I wonder if there is a trick that can be used to selectively add compile options if target name matches
*test*, but it may not be sufficient.The root cause fix is in the latest Google Test. But that latest Google Test is not yet getting pulled via
vcpkg, so I see this error. It'd have to be added to too many files, pretty much to all test project files. I can do that if you insist.My logical reasoning here as follows:
So suppressing this DLL export warning globally does not anyhow regress any of our other code.