diff --git a/CMakeLists.txt b/CMakeLists.txt index 515c48895e..5f0009d1d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,9 +65,17 @@ if(WITH_STL) # Optimize for speed to reduce the hops if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(CMAKE_CXX_FLAGS_SPEED "/O2") + if(CMAKE_BUILD_TYPE MATCHES Debug) + # Turn off optimizations for DEBUG + set(MSVC_CXX_OPT_FLAG "/Od") + else() + string(REGEX MATCH "\/O" result ${CMAKE_CXX_FLAGS}) + if(NOT ${result} MATCHES "\/O") + set(MSVC_CXX_OPT_FLAG "/O2") + endif() + endif() set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} /Zc:__cplusplus ${CMAKE_CXX_FLAGS_SPEED}") + "${CMAKE_CXX_FLAGS} /Zc:__cplusplus ${MSVC_CXX_OPT_FLAG}") endif() endif() @@ -84,12 +92,22 @@ option(WITH_JAEGER "Whether to include the Jaeger exporter" OFF) option(BUILD_TESTING "Whether to enable tests" ON) if(WIN32) + if(BUILD_TESTING) + if(MSVC) + # GTest bug: https://github.com/google/googletest/issues/860 + add_compile_options(/wd4275) + endif() + endif() option(WITH_ETW "Whether to include the ETW Exporter in the SDK" ON) if(WITH_ETW) add_definitions(-DHAVE_MSGPACK) endif(WITH_ETW) endif(WIN32) +option( + WITH_API_ONLY + "Only build the API (use as a header-only library). Overrides WITH_EXAMPLES" + OFF) option(WITH_EXAMPLES "Whether to build examples" ON) option(WITH_METRICS_PREVIEW "Whether to build metrics preview" OFF) @@ -206,17 +224,21 @@ endif() include(CMakePackageConfigHelpers) include_directories(api/include) -include_directories(sdk/include) -include_directories(sdk) -include_directories(ext/include) add_subdirectory(api) -add_subdirectory(sdk) -add_subdirectory(exporters) -if(WITH_EXAMPLES) - add_subdirectory(examples) + +if(NOT WITH_API_ONLY) + include_directories(sdk/include) + include_directories(sdk) + include_directories(ext/include) + + add_subdirectory(sdk) + add_subdirectory(exporters) + if(WITH_EXAMPLES) + add_subdirectory(examples) + endif() + add_subdirectory(ext) endif() -add_subdirectory(ext) # Add nlohmann/json submodule to include directories include_directories(third_party/nlohmann-json/single_include) diff --git a/docs/building-with-vs2019.md b/docs/building-with-vs2019.md new file mode 100644 index 0000000000..c2783e60ca --- /dev/null +++ b/docs/building-with-vs2019.md @@ -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. diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 8eae69449c..731cb2335c 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -17,14 +17,14 @@ package(default_visibility = ["//visibility:public"]) load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark") cc_library( - name = "recordable", + name = "otlp_recordable", srcs = [ - "src/recordable.cc", + "src/otlp_recordable.cc", ], hdrs = [ + "include/opentelemetry/exporters/otlp/otlp_recordable.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", - "include/opentelemetry/exporters/otlp/recordable.h", ], strip_include_prefix = "include", deps = [ @@ -46,7 +46,7 @@ cc_library( ], strip_include_prefix = "include", deps = [ - ":recordable", + ":otlp_recordable", "//sdk/src/trace", # For gRPC @@ -56,10 +56,10 @@ cc_library( ) cc_test( - name = "recordable_test", - srcs = ["test/recordable_test.cc"], + name = "otlp_recordable_test", + srcs = ["test/otlp_recordable_test.cc"], deps = [ - ":recordable", + ":otlp_recordable", "@com_google_googletest//:gtest_main", ], ) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 1bc3a78939..044222e30e 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(opentelemetry_exporter_otprotocol src/recordable.cc +add_library(opentelemetry_exporter_otprotocol src/otlp_recordable.cc src/otlp_exporter.cc) set_target_properties(opentelemetry_exporter_otprotocol @@ -27,14 +27,14 @@ target_include_directories( PUBLIC "$") if(BUILD_TESTING) - add_executable(recordable_test test/recordable_test.cc) + add_executable(otlp_recordable_test test/otlp_recordable_test.cc) target_link_libraries( - recordable_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + otlp_recordable_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_otprotocol) gtest_add_tests( - TARGET recordable_test + TARGET otlp_recordable_test TEST_PREFIX exporter.otlp. - TEST_LIST recordable_test) + TEST_LIST otlp_recordable_test) if(MSVC) add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY=1) endif() diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h similarity index 97% rename from exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h rename to exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h index 6ebe0511aa..8b3051860d 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/recordable.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_recordable.h @@ -14,7 +14,7 @@ namespace exporter { namespace otlp { -class Recordable final : public sdk::trace::Recordable +class OtlpRecordable final : public sdk::trace::Recordable { public: const proto::trace::v1::Span &span() const noexcept { return span_; } diff --git a/exporters/otlp/src/otlp_exporter.cc b/exporters/otlp/src/otlp_exporter.cc index 7a1a56c26c..2c9dc74f43 100644 --- a/exporters/otlp/src/otlp_exporter.cc +++ b/exporters/otlp/src/otlp_exporter.cc @@ -1,5 +1,5 @@ #include "opentelemetry/exporters/otlp/otlp_exporter.h" -#include "opentelemetry/exporters/otlp/recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable.h" #include #include @@ -27,7 +27,7 @@ void PopulateRequest(const nostd::span> for (auto &recordable : spans) { - auto rec = std::unique_ptr(static_cast(recordable.release())); + auto rec = std::unique_ptr(static_cast(recordable.release())); *instrumentation_lib->add_spans() = std::move(rec->span()); if (!has_resource) @@ -91,7 +91,7 @@ OtlpExporter::OtlpExporter( std::unique_ptr OtlpExporter::MakeRecordable() noexcept { - return std::unique_ptr(new Recordable); + return std::unique_ptr(new OtlpRecordable); } sdk::common::ExportResult OtlpExporter::Export( diff --git a/exporters/otlp/src/recordable.cc b/exporters/otlp/src/otlp_recordable.cc similarity index 88% rename from exporters/otlp/src/recordable.cc rename to exporters/otlp/src/otlp_recordable.cc index 666a370574..b3b26246d2 100644 --- a/exporters/otlp/src/recordable.cc +++ b/exporters/otlp/src/otlp_recordable.cc @@ -1,4 +1,4 @@ -#include "opentelemetry/exporters/otlp/recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace exporter @@ -12,8 +12,8 @@ namespace otlp const int kAttributeValueSize = 15; const int kOwnedAttributeValueSize = 15; -void Recordable::SetIdentity(const opentelemetry::trace::SpanContext &span_context, - opentelemetry::trace::SpanId parent_span_id) noexcept +void OtlpRecordable::SetIdentity(const opentelemetry::trace::SpanContext &span_context, + opentelemetry::trace::SpanId parent_span_id) noexcept { span_.set_trace_id(reinterpret_cast(span_context.trace_id().Id().data()), trace::TraceId::kSize); @@ -216,7 +216,7 @@ void PopulateAttribute(opentelemetry::proto::common::v1::KeyValue *attribute, } } -proto::resource::v1::Resource Recordable::ProtoResource() const noexcept +proto::resource::v1::Resource OtlpRecordable::ProtoResource() const noexcept { proto::resource::v1::Resource proto; if (resource_) @@ -230,21 +230,21 @@ proto::resource::v1::Resource Recordable::ProtoResource() const noexcept return proto; } -void Recordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept +void OtlpRecordable::SetResource(const opentelemetry::sdk::resource::Resource &resource) noexcept { resource_ = &resource; }; -void Recordable::SetAttribute(nostd::string_view key, - const opentelemetry::common::AttributeValue &value) noexcept +void OtlpRecordable::SetAttribute(nostd::string_view key, + const opentelemetry::common::AttributeValue &value) noexcept { auto *attribute = span_.add_attributes(); PopulateAttribute(attribute, key, value); } -void Recordable::AddEvent(nostd::string_view name, - common::SystemTimestamp timestamp, - const common::KeyValueIterable &attributes) noexcept +void OtlpRecordable::AddEvent(nostd::string_view name, + common::SystemTimestamp timestamp, + const common::KeyValueIterable &attributes) noexcept { auto *event = span_.add_events(); event->set_name(name.data(), name.size()); @@ -256,8 +256,8 @@ void Recordable::AddEvent(nostd::string_view name, }); } -void Recordable::AddLink(const opentelemetry::trace::SpanContext &span_context, - const common::KeyValueIterable &attributes) noexcept +void OtlpRecordable::AddLink(const opentelemetry::trace::SpanContext &span_context, + const common::KeyValueIterable &attributes) noexcept { auto *link = span_.add_links(); link->set_trace_id(reinterpret_cast(span_context.trace_id().Id().data()), @@ -272,18 +272,18 @@ void Recordable::AddLink(const opentelemetry::trace::SpanContext &span_context, // TODO: Populate trace_state when it is supported by SpanContext } -void Recordable::SetStatus(trace::StatusCode code, nostd::string_view description) noexcept +void OtlpRecordable::SetStatus(trace::StatusCode code, nostd::string_view description) noexcept { span_.mutable_status()->set_code(opentelemetry::proto::trace::v1::Status_StatusCode(code)); span_.mutable_status()->set_message(description.data(), description.size()); } -void Recordable::SetName(nostd::string_view name) noexcept +void OtlpRecordable::SetName(nostd::string_view name) noexcept { span_.set_name(name.data(), name.size()); } -void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept +void OtlpRecordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept { opentelemetry::proto::trace::v1::Span_SpanKind proto_span_kind = opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_UNSPECIFIED; @@ -325,18 +325,18 @@ void Recordable::SetSpanKind(opentelemetry::trace::SpanKind span_kind) noexcept span_.set_kind(proto_span_kind); } -void Recordable::SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept +void OtlpRecordable::SetStartTime(opentelemetry::common::SystemTimestamp start_time) noexcept { span_.set_start_time_unix_nano(start_time.time_since_epoch().count()); } -void Recordable::SetDuration(std::chrono::nanoseconds duration) noexcept +void OtlpRecordable::SetDuration(std::chrono::nanoseconds duration) noexcept { const uint64_t unix_end_time = span_.start_time_unix_nano() + duration.count(); span_.set_end_time_unix_nano(unix_end_time); } -void Recordable::SetInstrumentationLibrary( +void OtlpRecordable::SetInstrumentationLibrary( const opentelemetry::sdk::instrumentationlibrary::InstrumentationLibrary &instrumentation_library) noexcept { diff --git a/exporters/otlp/test/otlp_exporter_benchmark.cc b/exporters/otlp/test/otlp_exporter_benchmark.cc index 76ae3871cc..b20149f21d 100644 --- a/exporters/otlp/test/otlp_exporter_benchmark.cc +++ b/exporters/otlp/test/otlp_exporter_benchmark.cc @@ -1,5 +1,5 @@ #include "opentelemetry/exporters/otlp/otlp_exporter.h" -#include "opentelemetry/exporters/otlp/recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable.h" #include @@ -73,7 +73,7 @@ void CreateEmptySpans(std::array, kBatch { for (int i = 0; i < kBatchSize; i++) { - auto recordable = std::unique_ptr(new Recordable); + auto recordable = std::unique_ptr(new OtlpRecordable); recordables[i] = std::move(recordable); } } @@ -83,7 +83,7 @@ void CreateSparseSpans(std::array, kBatc { for (int i = 0; i < kBatchSize; i++) { - auto recordable = std::unique_ptr(new Recordable); + auto recordable = std::unique_ptr(new OtlpRecordable); recordable->SetIdentity(kSpanContext, kParentSpanId); recordable->SetName("TestSpan"); @@ -99,7 +99,7 @@ void CreateDenseSpans(std::array, kBatch { for (int i = 0; i < kBatchSize; i++) { - auto recordable = std::unique_ptr(new Recordable); + auto recordable = std::unique_ptr(new OtlpRecordable); recordable->SetIdentity(kSpanContext, kParentSpanId); recordable->SetName("TestSpan"); diff --git a/exporters/otlp/test/recordable_test.cc b/exporters/otlp/test/otlp_recordable_test.cc similarity index 91% rename from exporters/otlp/test/recordable_test.cc rename to exporters/otlp/test/otlp_recordable_test.cc index b4ceef03e8..be373434ac 100644 --- a/exporters/otlp/test/recordable_test.cc +++ b/exporters/otlp/test/otlp_recordable_test.cc @@ -1,4 +1,4 @@ -#include "opentelemetry/exporters/otlp/recordable.h" +#include "opentelemetry/exporters/otlp/otlp_recordable.h" #include OPENTELEMETRY_BEGIN_NAMESPACE @@ -6,7 +6,7 @@ namespace exporter { namespace otlp { -TEST(Recordable, SetIdentity) +TEST(OtlpRecordable, SetIdentity) { constexpr uint8_t trace_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; constexpr uint8_t span_id_buf[] = {1, 2, 3, 4, 5, 6, 7, 8}; @@ -20,7 +20,7 @@ TEST(Recordable, SetIdentity) opentelemetry::trace::TraceFlags{opentelemetry::trace::TraceFlags::kIsSampled}, true, trace_state}; - Recordable rec; + OtlpRecordable rec; rec.SetIdentity(span_context, parent_span_id); @@ -34,25 +34,25 @@ TEST(Recordable, SetIdentity) trace::SpanId::kSize)); } -TEST(Recordable, SetName) +TEST(OtlpRecordable, SetName) { - Recordable rec; + OtlpRecordable rec; nostd::string_view name = "Test Span"; rec.SetName(name); EXPECT_EQ(rec.span().name(), name); } -TEST(Recordable, SetSpanKind) +TEST(OtlpRecordable, SetSpanKind) { - Recordable rec; + OtlpRecordable rec; opentelemetry::trace::SpanKind span_kind = opentelemetry::trace::SpanKind::kServer; rec.SetSpanKind(span_kind); EXPECT_EQ(rec.span().kind(), opentelemetry::proto::trace::v1::Span_SpanKind::Span_SpanKind_SPAN_KIND_SERVER); } -TEST(Recordable, SetStartTime) +TEST(OtlpRecordable, SetStartTime) { - Recordable rec; + OtlpRecordable rec; std::chrono::system_clock::time_point start_time = std::chrono::system_clock::now(); common::SystemTimestamp start_timestamp(start_time); @@ -63,9 +63,9 @@ TEST(Recordable, SetStartTime) EXPECT_EQ(rec.span().start_time_unix_nano(), unix_start); } -TEST(Recordable, SetDuration) +TEST(OtlpRecordable, SetDuration) { - Recordable rec; + OtlpRecordable rec; // Start time is 0 common::SystemTimestamp start_timestamp; @@ -78,9 +78,9 @@ TEST(Recordable, SetDuration) EXPECT_EQ(rec.span().end_time_unix_nano(), unix_end); } -TEST(Recordable, SetStatus) +TEST(OtlpRecordable, SetStatus) { - Recordable rec; + OtlpRecordable rec; trace::StatusCode code(trace::StatusCode::kOk); nostd::string_view description = "For test"; rec.SetStatus(code, description); @@ -89,9 +89,9 @@ TEST(Recordable, SetStatus) EXPECT_EQ(rec.span().status().message(), description); } -TEST(Recordable, AddEventDefault) +TEST(OtlpRecordable, AddEventDefault) { - Recordable rec; + OtlpRecordable rec; nostd::string_view name = "Test Event"; std::chrono::system_clock::time_point event_time = std::chrono::system_clock::now(); @@ -107,9 +107,9 @@ TEST(Recordable, AddEventDefault) EXPECT_EQ(rec.span().events(0).attributes().size(), 0); } -TEST(Recordable, AddEventWithAttributes) +TEST(OtlpRecordable, AddEventWithAttributes) { - Recordable rec; + OtlpRecordable rec; const int kNumAttributes = 3; std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3"}; int values[kNumAttributes] = {4, 7, 23}; @@ -126,9 +126,9 @@ TEST(Recordable, AddEventWithAttributes) } } -TEST(Recordable, AddLink) +TEST(OtlpRecordable, AddLink) { - Recordable rec; + OtlpRecordable rec; const int kNumAttributes = 3; std::string keys[kNumAttributes] = {"attr1", "attr2", "attr3"}; int values[kNumAttributes] = {5, 12, 40}; @@ -150,9 +150,9 @@ TEST(Recordable, AddLink) } } -TEST(Recordable, SetResource) +TEST(OtlpRecordable, SetResource) { - Recordable rec; + OtlpRecordable rec; const std::string service_name_key = "service.name"; std::string service_name = "test-otlp"; auto resource = @@ -173,9 +173,9 @@ TEST(Recordable, SetResource) } // Test non-int single types. Int single types are tested using templates (see IntAttributeTest) -TEST(Recordable, SetSingleAtrribute) +TEST(OtlpRecordable, SetSingleAtrribute) { - Recordable rec; + OtlpRecordable rec; nostd::string_view bool_key = "bool_attr"; common::AttributeValue bool_val(true); rec.SetAttribute(bool_key, bool_val); @@ -200,9 +200,9 @@ TEST(Recordable, SetSingleAtrribute) } // Test non-int array types. Int array types are tested using templates (see IntAttributeTest) -TEST(Recordable, SetArrayAtrribute) +TEST(OtlpRecordable, SetArrayAtrribute) { - Recordable rec; + OtlpRecordable rec; const int kArraySize = 3; bool bool_arr[kArraySize] = {true, false, true}; @@ -246,7 +246,7 @@ TYPED_TEST(IntAttributeTest, SetIntSingleAttribute) IntType i = 2; common::AttributeValue int_val(i); - Recordable rec; + OtlpRecordable rec; rec.SetAttribute("int_attr", int_val); EXPECT_EQ(rec.span().attributes(0).value().int_value(), nostd::get(int_val)); } @@ -259,7 +259,7 @@ TYPED_TEST(IntAttributeTest, SetIntArrayAttribute) IntType int_arr[kArraySize] = {4, 5, 6}; nostd::span int_span(int_arr); - Recordable rec; + OtlpRecordable rec; rec.SetAttribute("int_arr_attr", int_span); for (int i = 0; i < kArraySize; i++) diff --git a/third_party/benchmark b/third_party/benchmark index 73d4d5e8d6..c05843a9f6 160000 --- a/third_party/benchmark +++ b/third_party/benchmark @@ -1 +1 @@ -Subproject commit 73d4d5e8d6d449fc8663765a42aa8aeeee844489 +Subproject commit c05843a9f622db08ad59804c190f98879b76beba diff --git a/tools/build.cmd b/tools/build.cmd index 74ba5db875..14da784661 100644 --- a/tools/build.cmd +++ b/tools/build.cmd @@ -1,57 +1,99 @@ @echo off -REM Currently we require Visual Studio 2019 for C++20 build targeting Release/x64. -REM -REM TODO: allow specifying compiler version as argument. -REM -REM Supported versions for nostd build: -REM - vs2015 (C++11) -REM - vs2017 (C++14) -REM - vs2019 (C++20) -REM -REM Supported versions for STL build: -REM - vs2017 (C++14) -REM - vs2019 (C++20) -REM - -if "%VS_TOOLS_VERSION%" == "" set "VS_TOOLS_VERSION=vs2019" -if "%CMAKE_GEN%" == "" set "CMAKE_GEN=Visual Studio 16 2019" - +REM ########################################################################################## +REM # Build SDK with Visual Studio + 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, # +REM # Emscripten or any other C++ compiler of your choice. # +REM # # +REM ########################################################################################## +REM # # +REM # Options passed as environment variables: # +REM # # +REM # VS_TOOLS_VERSION - specify visual studio 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) # +REM # # +REM ########################################################################################## +set "PATH=%PATH%;%ProgramFiles%\CMake\bin" pushd %~dp0 setlocal enableextensions setlocal enabledelayedexpansion -set "ROOT=%~dp0\.." +if not defined VS_TOOLS_VERSION ( + set VS_TOOLS_VERSION=vs2019 +) -if ("%CMAKE_ARCH%"=="") ( - set CMAKE_ARCH=x64 +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 + ) + ) + if not defined NINJA ( + for /f "tokens=*" %%F in ('where /R %CD%\vcpkg\downloads\tools ninja') do ( + set NINJA=%%F + ) + ) + if defined NINJA ( + echo Using ninja at !NINJA! + set CMAKE_GEN=Ninja + ) +) +set "ROOT=%~dp0\.." +if not defined ARCH ( + set ARCH=x64 ) -REM Use preinstalled vcpkg if installed or use our local -if "%VCPKG_ROOT%" neq "" ( +REM ########################################################################################## +REM Use preinstalled vcpkg from %VCPKG_ROOT% if installed or use our local snapshot of it. +REM ########################################################################################## +if defined VCPKG_ROOT ( set "VCPKG_CMAKE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" ) else ( set "VCPKG_CMAKE=%CD%\vcpkg\scripts\buildsystems\vcpkg.cmake" ) -REM ******************************************************************** -REM Setup compiler environment -REM ******************************************************************** +REM ########################################################################################## +REM Setup Microsoft Visual C++ compiler environment (if found, if not - fallback to alternate) +REM ########################################################################################## call "%~dp0\vcvars.cmd" -REM ******************************************************************** -REM Use cmake -REM ******************************************************************** -set "PATH=%PATH%;C:\Program Files\CMake\bin\" +REM Prefer Visual Studio C++ compiler if found +for /f "tokens=*" %%F in ('where cl.exe') do ( + set CONFIG=!CONFIG! -DCMAKE_C_COMPILER:FILEPATH="%%F" -DCMAKE_CXX_COMPILER:FILEPATH="%%F" + echo !CONFIG! +) -REM ******************************************************************** -REM Build with nostd implementation -REM ******************************************************************** +REM ########################################################################################## +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 ########################################################################################## set CONFIG=-DWITH_STL:BOOL=OFF %* set "OUTDIR=%ROOT%\out\%VS_TOOLS_VERSION%\nostd" call :build_config -REM ******************************************************************** -REM Build with STL implementation only for vs2017+ -REM ******************************************************************** +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 ########################################################################################## if "%VS_TOOLS_VERSION%" neq "vs2015" ( set CONFIG=-DWITH_STL:BOOL=ON %* set "OUTDIR=%ROOT%\out\%VS_TOOLS_VERSION%\stl" @@ -59,22 +101,54 @@ if "%VS_TOOLS_VERSION%" neq "vs2015" ( ) popd -REM ******************************************************************** - - -REM ******************************************************************** -REM Function that allows to build given build configuration -REM ******************************************************************** +exit +REM ########################################################################################## +REM Function that allows to build given build configuration with MSBuild or Ninja +REM ########################################################################################## :build_config REM TODO: consider rmdir for clean builds if not exist "%OUTDIR%" mkdir "%OUTDIR%" cd "%OUTDIR%" -if ("%VS_TOOLS_VERSION%"=="vs2019") ( + +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 - cmake %ROOT% -G "%CMAKE_GEN%" -A %CMAKE_ARCH% -DCMAKE_TOOLCHAIN_FILE="%VCPKG_CMAKE%" %CONFIG% + cmake -G "!CMAKE_GEN!" -A !ARCH! -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" ) else ( - cmake %ROOT% -G "%CMAKE_GEN%" -DCMAKE_TOOLCHAIN_FILE="%VCPKG_CMAKE%" %CONFIG% + REM Old vs2017 generator does not support -A parameter + cmake -G "!CMAKE_GEN!" -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" ) set "SOLUTION=%OUTDIR%\opentelemetry-cpp.sln" msbuild "%SOLUTION%" /p:Configuration=Release /p:VcpkgEnabled=true -exit /b 0 +exit /b + +REM ########################################################################################## +REM Build using CMake+ninja: vs2019 is known to work well. vs2017 was not tested. +REM ########################################################################################## +REM +REM Optional parameters may be passed to `build.cmd ARG1 ARG2 .. ARGN`. +REM +REM These arguments get appended to CONFIG and passed to CMake. +REM +REM To build for Debug: +REM -DCMAKE_BUILD_TYPE:STRING="Debug" +REM +REM To specify alternate installation path: +REM -DCMAKE_INSTALL_PREFIX:PATH=C:\path\to\install +REM +REM To specify alternate toolchain version: +REM -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe" +REM -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe" +REM +REM To specify alternate version of Ninja.exe: +REM -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\ENTERPRISE\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" +REM +REM ########################################################################################## +:build_config_ninja +cmake -G "Ninja" -DCMAKE_MAKE_PROGRAM="!NINJA!" -DCMAKE_TOOLCHAIN_FILE="!VCPKG_CMAKE!" !CONFIG! "!ROOT!" +%NINJA% +exit /b diff --git a/tools/ports/benchmark/CONTROL b/tools/ports/benchmark/CONTROL index 62b80dffae..4e522eb83d 100644 --- a/tools/ports/benchmark/CONTROL +++ b/tools/ports/benchmark/CONTROL @@ -1,5 +1,5 @@ Source: benchmark -Version: 1.5.1 +Version: 1.5.3 Homepage: https://github.com/google/benchmark Description: A library to support the benchmarking of functions, similar to unit-tests. -Supports: !uwp \ No newline at end of file +Supports: !(arm|uwp) diff --git a/tools/ports/benchmark/portfile.cmake b/tools/ports/benchmark/portfile.cmake index e89fafca6c..5a2779c493 100644 --- a/tools/ports/benchmark/portfile.cmake +++ b/tools/ports/benchmark/portfile.cmake @@ -1,7 +1,3 @@ -if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") - message(FATAL_ERROR "${PORT} does not currently support UWP") -endif() - if (VCPKG_PLATFORM_TOOLSET STREQUAL "v140") # set(CMAKE_C_COMPILER_WORKS 1) # set(CMAKE_CXX_COMPILER_WORKS 1) @@ -17,14 +13,18 @@ else() set(PREFER PREFER_NINJA) endif() -include(vcpkg_common_functions) +#https://github.com/google/benchmark/issues/661 +vcpkg_fail_port_install(ON_TARGET "uwp") vcpkg_check_linkage(ONLY_STATIC_LIBRARY) vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO google/benchmark + REF c05843a9f622db08ad59804c190f98879b76beba # v1.5.3 + SHA512 1 HEAD_REF master + PATCHES "version.patch" ) vcpkg_configure_cmake( @@ -41,9 +41,10 @@ vcpkg_copy_pdbs() vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/benchmark) +vcpkg_fixup_pkgconfig(SYSTEM_LIBRARIES pthread) + file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share) # Handle copyright -file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/benchmark) -file(RENAME ${CURRENT_PACKAGES_DIR}/share/benchmark/LICENSE ${CURRENT_PACKAGES_DIR}/share/benchmark/copyright) +file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) diff --git a/tools/ports/benchmark/version.patch b/tools/ports/benchmark/version.patch new file mode 100644 index 0000000000..067dc58927 --- /dev/null +++ b/tools/ports/benchmark/version.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 1007254..47e4a1b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -78,8 +78,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + + + # Read the git tags to determine the project version +-include(GetGitVersion) +-get_git_version(GIT_VERSION) ++# include(GetGitVersion) ++# get_git_version(GIT_VERSION) ++set(GIT_VERSION 1.5.3) + + # Tell the user what versions we are using + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION}) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 35d559e..e9dec6d 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -77,9 +77,13 @@ set(targets_export_name "${PROJECT_NAME}Targets") + set(namespace "${PROJECT_NAME}::") + + include(CMakePackageConfigHelpers) ++# Avoid architecture compatibility check ++set(DOCTEST_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) ++unset(CMAKE_SIZEOF_VOID_P) + write_basic_package_version_file( + "${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion + ) ++set(CMAKE_SIZEOF_VOID_P ${DOCTEST_SIZEOF_VOID_P}) + + configure_file("${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${project_config}" @ONLY) + configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY) diff --git a/tools/setup-buildtools.cmd b/tools/setup-buildtools.cmd index 39270b9c7c..7a215fc3cf 100644 --- a/tools/setup-buildtools.cmd +++ b/tools/setup-buildtools.cmd @@ -1,5 +1,7 @@ @echo off -set "PATH=%ProgramFiles%\CMake\bin;%~dp0;%~dp0vcpkg;%PATH%" +setlocal enableextensions +setlocal enabledelayedexpansion +set "PATH=%ProgramFiles%\CMake\bin;%~dp0;%~dp0vcpkg;%ProgramData%\chocolatey\bin;%PATH%" if "%VCPKG_ROOT%" NEQ "" set "PATH=%VCPKG_ROOT%;%PATH%" pushd %~dp0 @@ -27,18 +29,25 @@ if %ERRORLEVEL% == 0 ( vswhere -property installationPath ) +REM This script allows to pass architecture in ARCH env var +if not defined ARCH ( + set ARCH=x64 +) + REM Try to autodetect Visual Studio -call "%~dp0vcvars.cmd" x64 +call "%~dp0vcvars.cmd" if "%TOOLS_VS_NOTFOUND%" == "1" ( - REM Cannot detect MSBuild path - REM TODO: no command line tools.. - REM TODO: use MSBuild from vswhere? + echo WARNING: cannot autodetect Visual Studio installation! ) where /Q vcpkg.exe if %ERRORLEVEL% == 1 ( REM Build our own vcpkg from source - pushd .\vcpkg + REM Prefer building in VCPKG_ROOT + if not defined VCPKG_ROOT ( + set "VCPKG_ROOT=%~dp0\vcpkg" + ) + pushd "!VCPKG_ROOT!" call bootstrap-vcpkg.bat popd ) else ( @@ -46,14 +55,14 @@ if %ERRORLEVEL% == 1 ( ) REM Install dependencies -vcpkg install gtest:x64-windows -vcpkg install --head --overlay-ports=%~dp0ports benchmark:x64-windows -vcpkg install ms-gsl:x64-windows -vcpkg install nlohmann-json:x64-windows -vcpkg install abseil:x64-windows -vcpkg install protobuf:x64-windows -vcpkg install gRPC:x64-windows -vcpkg install prometheus-cpp:x64-windows -vcpkg install curl:x64-windows +vcpkg install gtest:%ARCH%-windows +vcpkg install --head --overlay-ports=%~dp0ports benchmark:%ARCH%-windows +vcpkg install ms-gsl:%ARCH%-windows +vcpkg install nlohmann-json:%ARCH%-windows +vcpkg install abseil:%ARCH%-windows +vcpkg install protobuf:%ARCH%-windows +vcpkg install gRPC:%ARCH%-windows +vcpkg install prometheus-cpp:%ARCH%-windows +vcpkg install curl:%ARCH%-windows popd exit /b 0 diff --git a/tools/vcvars.cmd b/tools/vcvars.cmd index fe728367a6..69308778a7 100644 --- a/tools/vcvars.cmd +++ b/tools/vcvars.cmd @@ -1,85 +1,117 @@ @echo off -REM -REM Make sure to enable the 'Visual C++ ATL' components for all platforms during the setup. -REM -REM This build script auto-detects and configures Visual Studio in the following order: -REM 1. Visual Studio 2017 Enterprise -REM 2. Visual Studio 2017 BuildTools -REM 3. Visual Studio 2019 Enterprise -REM 4. Visual Studio 2019 Community -REM 5. Visual Studio 2019 BuildTools -REM +REM +-------------------------------------------------------------------+ +REM | Autodetect and set up the build environment for Visual Studio. | +REM | Visual Studio version may be specified as 1st argument. | +REM +-------------------------------------------------------------------+ +REM | Description | Argument value | +REM +-----------------------------------------+-------------------------+ +REM | Autodetect Visual Studio 2019 | vs2019 | +REM | Visual Studio 2019 Enterprise | vs2019_enterprise | +REM | Visual Studio 2019 Professional | vs2019_professional | +REM | Visual Studio 2019 Community | vs2019_community | +REM | Visual Studio 2019 Build Tools (no IDE) | vs2019_buildtools | +REM | | | +REM | Autodetect Visual Studio 2017 | vs2017 | +REM | Visual Studio 2017 Enterprise | vs2017_enterprise | +REM | Visual Studio 2017 Professional | vs2017_professional | +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 +-----------------------------------------+-------------------------+ +set "VSCMD_START_DIR=%CD%" + +if not defined ARCH ( + set ARCH=x64 +) -REM 1st parameter - Visual Studio version if "%1" neq "" ( goto %1 ) -if "%VS_TOOLS_VERSION%" neq "" ( +if defined VS_TOOLS_VERSION ( goto %VS_TOOLS_VERSION% ) -REM vs2017 Enterprise -:vs2017 -:vs2017_enterprise -set TOOLS_VS2017_ENTERPRISE="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat" -if exist %TOOLS_VS2017_ENTERPRISE% ( - echo Building with vs2017 Enterprise... - call %TOOLS_VS2017_ENTERPRISE% - goto tools_configured -) - -REM vs2017 BuildTools -:vs2017_buildtools -set TOOLS_VS2017="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" -if exist %TOOLS_VS2017% ( - echo Building with vs2017 BuildTools... - call %TOOLS_VS2017% - goto tools_configured -) - -REM vs2019 Enterprise :vs2019 :vs2019_enterprise -set TOOLS_VS2019_ENTERPRISE="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" +set TOOLS_VS2019_ENTERPRISE="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" if exist %TOOLS_VS2019_ENTERPRISE% ( echo Building with vs2019 Enterprise... - call %TOOLS_VS2019_ENTERPRISE% + call %TOOLS_VS2019_ENTERPRISE% %ARCH% + goto tools_configured +) + +:vs2019_professional +set TOOLS_VS2019_PRO="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat" +if exist %TOOLS_VS2019_PRO% ( + echo Building with vs2019 Professional... + call %TOOLS_VS2019_PRO% %ARCH% goto tools_configured ) -REM vs2019 Community :vs2019_community -set TOOLS_VS2019_COMMUNITY="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat" +set TOOLS_VS2019_COMMUNITY="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" if exist %TOOLS_VS2019_COMMUNITY% ( echo Building with vs2019 Community... - call %TOOLS_VS2019_COMMUNITY% + call %TOOLS_VS2019_COMMUNITY% %ARCH% goto tools_configured ) -REM vs2019 BuildTools :vs2019_buildtools -set TOOLS_VS2019="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat" +set TOOLS_VS2019="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" if exist %TOOLS_VS2019% ( echo Building with vs2019 BuildTools... - call %TOOLS_VS2019% + call %TOOLS_VS2019% %ARCH% + goto tools_configured +) + +:vs2017 +:vs2017_enterprise +set TOOLS_VS2017_ENTERPRISE="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" +if exist %TOOLS_VS2017_ENTERPRISE% ( + echo Building with vs2017 Enterprise... + call %TOOLS_VS2017_ENTERPRISE% %ARCH% + goto tools_configured +) + +:vs2017_professional +set TOOLS_VS2017_PRO="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat" +if exist %TOOLS_VS2017_PRO% ( + echo Building with vs2017 Professional... + call %TOOLS_VS2017_PRO% %ARCH% + goto tools_configured +) + +:vs2017_community +set TOOLS_VS2017_COMMUNITY="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\VC\Auxiliary\Build\vcvarsall.bat" +if exist %TOOLS_VS2017_COMMUNITY% ( + echo Building with vs2017 Community... + call %TOOLS_VS2017_COMMUNITY% %ARCH% + goto tools_configured +) + +:vs2017_buildtools +set TOOLS_VS2017="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" +if exist %TOOLS_VS2017% ( + echo Building with vs2017 BuildTools... + call %TOOLS_VS2017% %ARCH% goto tools_configured ) -REM vs2015 :vs2015 -set TOOLS_VS2015="%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" +set TOOLS_VS2015="%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\bin\vcvarsall.bat" if exist %TOOLS_VS2015% ( echo Building with vs2015 BuildTools... - call %TOOLS_VS2015% + call %TOOLS_VS2015% %ARCH% set "VCPKG_VISUAL_STUDIO_PATH=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0" set VCPKG_PLATFORM_TOOLSET=v140 goto tools_configured ) -echo WARNING:********************************************* echo WARNING: cannot auto-detect Visual Studio version !!! -echo WARNING:********************************************* +REM Caller may decide what to do if Visual Studio environment +REM is not set up by checking TOOLS_VS_NOTFOUND set TOOLS_VS_NOTFOUND=1 exit /b 0