diff --git a/tools/build-benchmark.cmd b/tools/build-benchmark.cmd index 39b9f180d9..379cb1313a 100644 --- a/tools/build-benchmark.cmd +++ b/tools/build-benchmark.cmd @@ -1,5 +1,5 @@ @echo off -set VS_TOOLS_VERSION=vs2019 +set BUILDTOOLS_VERSION=vs2019 set CMAKE_GEN="Visual Studio 16 2019" echo Building Google Benchmark (test only dependency)... @setlocal ENABLEEXTENSIONS diff --git a/tools/build-clang-12.cmd b/tools/build-clang-12.cmd new file mode 100644 index 0000000000..a41c5bb6c1 --- /dev/null +++ b/tools/build-clang-12.cmd @@ -0,0 +1,7 @@ +@echo off +pushd %~dp0 +set "PATH=%ProgramFiles%\LLVM-12\bin;%PATH%" +set BUILDTOOLS_VERSION=clang-12 +set CMAKE_GEN=Ninja +call build.cmd %* +popd diff --git a/tools/build-clang.cmd b/tools/build-clang.cmd new file mode 100644 index 0000000000..c160fd661b --- /dev/null +++ b/tools/build-clang.cmd @@ -0,0 +1,7 @@ +@echo off +pushd %~dp0 +set "PATH=%ProgramFiles%\LLVM\bin;%PATH%" +set BUILDTOOLS_VERSION=clang +set CMAKE_GEN=Ninja +call build.cmd %* +popd diff --git a/tools/build-vs2015.cmd b/tools/build-vs2015.cmd index 30bb41c3c9..ed230d1559 100644 --- a/tools/build-vs2015.cmd +++ b/tools/build-vs2015.cmd @@ -1,11 +1,33 @@ REM Build with Visual Studio 2015 -set "VS_TOOLS_VERSION=vs2015" -set ARCH=Win64 +set "PATH=%ProgramFiles(x86)%\MSBuild\14.0\Bin;%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\bin;%PATH%" + +REM ### Note that vcpkg built with 2019/2017 can't be used with 2015! +REM ### Consider to specify custom VCPKG_ROOT for 2015 as follows: +REM +REM set VCPKG_ROOT=C:\vcpkg.2015 +REM + +set BUILDTOOLS_VERSION=vs2015 +set ARCH=x64 if NOT "%1"=="" ( set ARCH=%1 ) -set "CMAKE_GEN=Visual Studio 14 2015 %ARCH%" +set "CMAKE_GEN=Ninja" +set "VCPKG_VISUAL_STUDIO_PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0" + +REM Building with Windows SDK 8.1 +set "PATH=%ProgramFiles(x86)%\Windows Kits\8.1\bin\%ARCH%;%PATH%" +set WINSDK_VERSION=8.1 +set CMAKE_SYSTEM_VERSION=8.1 +set VCPKG_PLATFORM_TOOLSET=v140 + +REM ### Replace above Windows SDK 8.1 by Windows 10 SDK if necessary. +REM ### Resulting binaries may not be compatible with Windows 8 +REM +REM set WINSDK_VERSION=10.0.19041.0 +REM set "PATH=%ProgramFiles(x86)%\Windows Kits\10\bin\10.0.19041.0\%ARCH%\;%PATH%" +REM + cd %~dp0 call setup-buildtools.cmd -REM TODO: currently we cannot build without Abseil variant for Visual Studio 2015 -call build.cmd -DWITH_ABSEIL:BOOL=ON +call build.cmd -DMSVC_TOOLSET_VERSION=140 diff --git a/tools/build-vs2017.cmd b/tools/build-vs2017.cmd index de84593123..3a95d9b110 100644 --- a/tools/build-vs2017.cmd +++ b/tools/build-vs2017.cmd @@ -1,10 +1,17 @@ REM Build with Visual Studio 2017 -set "VS_TOOLS_VERSION=vs2017" -set ARCH=Win64 +set "BUILDTOOLS_VERSION=vs2017" +set ARCH=x64 if NOT "%1"=="" ( set ARCH=%1 ) -set "CMAKE_GEN=Visual Studio 15 2017 %ARCH%" + +REM ### Uncomment below to use Visual Studio MSBuild solution. +REM ### Ninja generator produces much faster builds. But it is +REM ### easier to debug MSBuild solution in vs2017 IDE : +REM +REM set "CMAKE_GEN=Visual Studio 15 2017" +REM + cd %~dp0 call setup-buildtools.cmd call build.cmd diff --git a/tools/build-vs2019.cmd b/tools/build-vs2019.cmd index b4a39938a3..2fd6dbc59e 100644 --- a/tools/build-vs2019.cmd +++ b/tools/build-vs2019.cmd @@ -1,15 +1,13 @@ REM Build with Visual Studio 2017 -set "VS_TOOLS_VERSION=vs2019" -set ARCH=Win64 +set "BUILDTOOLS_VERSION=vs2019" +set ARCH=x64 if NOT "%1"=="" ( set ARCH=%1 ) -if "%ARCH%"=="Win64" ( +if "%ARCH%"=="x64" ( REM Parameter needed for CMake Visual Studio 2019 generator set CMAKE_ARCH=x64 ) - -set "CMAKE_GEN=Visual Studio 16 2019" cd %~dp0 call setup-buildtools.cmd call build.cmd diff --git a/tools/build.cmd b/tools/build.cmd index 14da784661..7558f4efff 100644 --- a/tools/build.cmd +++ b/tools/build.cmd @@ -1,6 +1,6 @@ @echo off REM ########################################################################################## -REM # Build SDK with Visual Studio + CMake + MSBUild or Ninja. # +REM # Build SDK with (msvc or clang) + CMake + (MSBuild or Ninja). # REM # # REM # CMake arguments may be passed as parameters to this script. # REM # If Visual Studio is not installed, then this script falls back to LLVM-CLang, # @@ -10,7 +10,7 @@ REM ############################################################################ REM # # REM # Options passed as environment variables: # REM # # -REM # VS_TOOLS_VERSION - specify visual studio version. See `vcvars.cmd` for details. # +REM # BUILDTOOLS_VERSION - specify build tools version. See `vcvars.cmd` for details. # REM # CMAKE_GEN - specify CMake generator. # REM # VCPKG_ROOT - path to vcpkg root # REM # ARCH - architecture to build for (default: x64) # @@ -20,36 +20,43 @@ set "PATH=%PATH%;%ProgramFiles%\CMake\bin" pushd %~dp0 setlocal enableextensions setlocal enabledelayedexpansion -if not defined VS_TOOLS_VERSION ( - set VS_TOOLS_VERSION=vs2019 +if not defined BUILDTOOLS_VERSION ( + set BUILDTOOLS_VERSION=vs2019 ) REM ########################################################################################## REM Set up CMake generator. Use Ninja if available. REM ########################################################################################## -if not defined CMAKE_GEN ( - set CMAKE_GEN=Visual Studio 16 2019 - for /f "tokens=*" %%F in ('where ninja') do ( - set NINJA=%%F - ) - if defined VCPKG_ROOT ( - if not defined NINJA ( - for /f "tokens=*" %%F in ('where /R %VCPKG_ROOT%\vcpkg\downloads\tools ninja') do ( - set NINJA=%%F - ) - popd - ) - ) +for /f "tokens=*" %%F in ('where ninja') do ( + set NINJA=%%F +) + +if defined VCPKG_ROOT ( if not defined NINJA ( - for /f "tokens=*" %%F in ('where /R %CD%\vcpkg\downloads\tools ninja') do ( + for /f "tokens=*" %%F in ('where /R %VCPKG_ROOT%\vcpkg\downloads\tools ninja') do ( set NINJA=%%F ) + popd ) - if defined NINJA ( - echo Using ninja at !NINJA! +) + +if not defined NINJA ( + for /f "tokens=*" %%F in ('where /R %CD%\vcpkg\downloads\tools ninja') do ( + set NINJA=%%F + ) +) + +if defined NINJA ( + echo Found ninja: !NINJA! + if not defined CMAKE_GEN ( set CMAKE_GEN=Ninja ) ) + +if not defined CMAKE_GEN ( + set CMAKE_GEN=Visual Studio 16 2019 +) + set "ROOT=%~dp0\.." if not defined ARCH ( set ARCH=x64 @@ -80,23 +87,18 @@ REM The following two configurations are built below: REM - nostd - build with OpenTelemetry C++ Template library REM - stl - build with Standard Template Library REM ########################################################################################## -REM Build with nostd implementation. Supported VS_TOOLS_VERSION: -REM - vs2015 (C++11) -REM - vs2017 (C++14) -REM - vs2019 (C++20) +REM Build with nostd implementation. REM ########################################################################################## set CONFIG=-DWITH_STL:BOOL=OFF %* -set "OUTDIR=%ROOT%\out\%VS_TOOLS_VERSION%\nostd" +set "OUTDIR=%ROOT%\out\%BUILDTOOLS_VERSION%\nostd" call :build_config REM ########################################################################################## -REM Build with STL implementation (only for vs2017+). Supported VS_TOOLS_VERSION: -REM - vs2017 (C++14) -REM - vs2019 (C++20) - optimal config with all OpenTelemetry API classes using STL only. +REM Build with STL implementation. This option does not yield benefits for vs2015 build. REM ########################################################################################## -if "%VS_TOOLS_VERSION%" neq "vs2015" ( +if "%BUILDTOOLS_VERSION%" neq "vs2015" ( set CONFIG=-DWITH_STL:BOOL=ON %* - set "OUTDIR=%ROOT%\out\%VS_TOOLS_VERSION%\stl" + set "OUTDIR=%ROOT%\out\%BUILDTOOLS_VERSION%\stl" call :build_config ) @@ -110,18 +112,36 @@ REM TODO: consider rmdir for clean builds if not exist "%OUTDIR%" mkdir "%OUTDIR%" cd "%OUTDIR%" -if "!VS_TOOLS_VERSION!" == "vs2019" ( - REM Prefer ninja if available - if "!CMAKE_GEN!" == "Ninja" ( - call :build_config_ninja - exit /b - ) - REM Only latest vs2019 generator supports and requires -A parameter +REM Prefer ninja if available +if "!CMAKE_GEN!" == "Ninja" ( + call :build_config_ninja + exit /b +) + +if "!BUILDTOOLS_VERSION!" == "vs2015" ( cmake -G "!CMAKE_GEN!" -A !ARCH! -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" -) else ( - REM Old vs2017 generator does not support -A parameter - cmake -G "!CMAKE_GEN!" -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + call :build_msbuild + exit /b ) + +if "!BUILDTOOLS_VERSION!" == "vs2017" ( + cmake -G "!CMAKE_GEN!" -A !ARCH! -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + call :build_msbuild + exit /b +) + +if "!BUILDTOOLS_VERSION!" == "vs2019" ( + cmake -G "!CMAKE_GEN!" -A !ARCH! -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + call :build_msbuild + exit /b +) + +REM ########################################################################################## +REM Exotic CMake generators, like MSYS and MinGW MAY work, but untested +REM ########################################################################################## +cmake -G "!CMAKE_GEN!" -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" + +:build_msbuild set "SOLUTION=%OUTDIR%\opentelemetry-cpp.sln" msbuild "%SOLUTION%" /p:Configuration=Release /p:VcpkgEnabled=true exit /b diff --git a/tools/ports/benchmark/portfile.cmake b/tools/ports/benchmark/portfile.cmake index dba57ab53d..fdb988c538 100644 --- a/tools/ports/benchmark/portfile.cmake +++ b/tools/ports/benchmark/portfile.cmake @@ -1,11 +1,7 @@ if (VCPKG_PLATFORM_TOOLSET STREQUAL "v140") - # set(CMAKE_C_COMPILER_WORKS 1) - # set(CMAKE_CXX_COMPILER_WORKS 1) set(CMAKE_C_COMPILER cl.exe) set(CMAKE_CXX_COMPILER cl.exe) set(MSVC_TOOLSET_VERSION 140) - # set(VCPKG_VISUAL_STUDIO_PATH "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0") - # set(VCPKG_PLATFORM_TOOLSET v140) else() # Make sure vs2019 compiled binaries are compat with vs2017 set(VCPKG_CXX_FLAGS "/Zc:__cplusplus /d2FH4-") diff --git a/tools/setup-buildtools.cmd b/tools/setup-buildtools.cmd index fd31eb21fd..956c8ddfe4 100644 --- a/tools/setup-buildtools.cmd +++ b/tools/setup-buildtools.cmd @@ -1,8 +1,12 @@ @echo off setlocal enableextensions setlocal enabledelayedexpansion -set "PATH=%ProgramFiles%\CMake\bin;%~dp0;%~dp0vcpkg;%ProgramData%\chocolatey\bin;%PATH%" -if "%VCPKG_ROOT%" NEQ "" set "PATH=%VCPKG_ROOT%;%PATH%" +set "PATH=%ProgramFiles%\CMake\bin;%~dp0;%ProgramData%\chocolatey\bin;%PATH%" +if defined VCPKG_ROOT ( + set "PATH=%VCPKG_ROOT%;%PATH%" +) else ( + set "PATH=%~dp0vcpkg;%PATH%" +) pushd %~dp0 net session >nul 2>&1 @@ -22,11 +26,13 @@ if %errorLevel% == 0 ( echo Running without Administrative privilege... ) -REM Print current Visual Studio installations detected -where /Q vswhere -if %ERRORLEVEL% == 0 ( - echo Visual Studio installations detected: - vswhere -property installationPath +if not defined BUILDTOOLS_VERSION ( + REM Print current Visual Studio installations detected + where /Q vswhere + if %ERRORLEVEL% == 0 ( + echo Visual Studio installations detected: + vswhere -property installationPath + ) ) REM This script allows to pass architecture in ARCH env var diff --git a/tools/vcvars.cmd b/tools/vcvars.cmd index 69308778a7..94f5cca95a 100644 --- a/tools/vcvars.cmd +++ b/tools/vcvars.cmd @@ -1,7 +1,7 @@ @echo off REM +-------------------------------------------------------------------+ -REM | Autodetect and set up the build environment for Visual Studio. | -REM | Visual Studio version may be specified as 1st argument. | +REM | Autodetect and set up the build environment. | +REM | Build Tools version may be specified as 1st argument. | REM +-------------------------------------------------------------------+ REM | Description | Argument value | REM +-----------------------------------------+-------------------------+ @@ -18,6 +18,12 @@ REM | Visual Studio 2017 Community | vs2017_community | REM | Visual Studio 2017 Build Tools (no IDE) | vs2017_buildtools | REM | | | REM | Visual Studio 2015 Build Tools (no IDE) | vs2015 | +REM | | | +REM | LLVM Clang (any version) | clang | +REM | LLVM Clang 9 | clang-9 | +REM | LLVM Clang 10 | clang-10 | +REM | LLVM Clang 11 | clang-11 | +REM | LLVM Clang 11 | clang-12 | REM +-----------------------------------------+-------------------------+ set "VSCMD_START_DIR=%CD%" @@ -29,8 +35,8 @@ if "%1" neq "" ( goto %1 ) -if defined VS_TOOLS_VERSION ( - goto %VS_TOOLS_VERSION% +if defined BUILDTOOLS_VERSION ( + goto %BUILDTOOLS_VERSION% ) :vs2019 @@ -100,10 +106,10 @@ if exist %TOOLS_VS2017% ( ) :vs2015 -set TOOLS_VS2015="%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\bin\vcvarsall.bat" +set TOOLS_VS2015="%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" if exist %TOOLS_VS2015% ( echo Building with vs2015 BuildTools... - call %TOOLS_VS2015% %ARCH% + call %TOOLS_VS2015% %ARCH% %WINSDK_VERSION% set "VCPKG_VISUAL_STUDIO_PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0" set VCPKG_PLATFORM_TOOLSET=v140 goto tools_configured @@ -115,4 +121,38 @@ REM is not set up by checking TOOLS_VS_NOTFOUND set TOOLS_VS_NOTFOUND=1 exit /b 0 +REM +-------------------------------------------------------------------+ +REM | There is no auto-detection of LLVM Clang version. | +REM | LLVM Clang of any version is installed in the same directory | +REM | at %ProgramFiles%\LLVM\bin . Developers choose their own custom | +REM | layout for installing multiple clang toolchains side-by-side. | +REM | | +REM | Example layout (merely a guideline, layout could differ): | +REM | | +REM | %ProgramFiles%\LLVM-9\bin | +REM | %ProgramFiles%\LLVM-10\bin | +REM | %ProgramFiles%\LLVM-11\bin | +REM | %ProgramFiles%\LLVM-12\bin | +REM +-------------------------------------------------------------------+ +REM +REM ## Example 1: use clang-10 located in LLVM-10 directory: +REM set BUILDTOOLS_VERSION=clang-10 +REM set "PATH=%ProgramFiles%\LLVM-10\bin;%PATH%" +REM tools\build.cmd +REM +REM ## Example 2: use whatever clang located in LLVM directory: +REM set BUILDTOOLS_VERSION=clang +REM set "PATH=%ProgramFiles%\LLVM\bin;%PATH%" +REM tools\build.cmd +REM +REM BUILDTOOLS_VERSION determines the output directory location. +REM Store build artifacts produced by different toolchains - +REM side-by-side, each in its own separate output directory. +REM +:clang +:clang-9 +:clang-10 +:clang-11 +:clang-12 + :tools_configured