From 9d3ddcdd08a6b53a138169127d33a4083692ed50 Mon Sep 17 00:00:00 2001 From: Peter Chang Date: Fri, 2 Feb 2024 16:15:01 -0500 Subject: [PATCH] Add cmake option for azure libs, fix compile issues --- CMakeLists.txt | 1 + examples/rl_sim_cpp/CMakeLists.txt | 6 +++--- examples/rl_sim_cpp/azure_credentials.cc | 2 +- examples/rl_sim_cpp/azure_credentials.h | 5 ++--- examples/rl_sim_cpp/rl_sim.cc | 2 +- examples/rl_sim_cpp/rl_sim.h | 2 ++ rlclientlib/CMakeLists.txt | 3 +++ rlclientlib/utility/api_header_token.h | 4 +--- 8 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ee51d28b..850049b5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,7 @@ option(RL_USE_UBSAN "Compile with UndefinedBehaviorSanitizer" OFF) option(rlclientlib_BUILD_ONNXRUNTIME_EXTENSION "Build OnnxRuntime Inference Extension" OFF) option(rlclientlib_BUILD_DOTNET "Build .NET bindings" OFF) option(rlclientlib_DOTNET_USE_MSPROJECT "[Experimental] Use import_external_msproject to build .NET csproj files." OFF) +option(RL_LINK_AZURE_LIBS "Whether to build components requiring the use of Azure libraries. Requires C++14 or greater" OFF) if(RL_USE_ASAN) add_compile_definitions(RL_USE_ASAN VW_USE_ASAN) diff --git a/examples/rl_sim_cpp/CMakeLists.txt b/examples/rl_sim_cpp/CMakeLists.txt index 1fc42c0cc..ea028279c 100644 --- a/examples/rl_sim_cpp/CMakeLists.txt +++ b/examples/rl_sim_cpp/CMakeLists.txt @@ -1,6 +1,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/../../cmake/Modules/") -if(RL_CXX_STANDARD GREATER_EQUAL 14 AND vw_USE_AZURE_FACTORIES) +if(RL_LINK_AZURE_LIBS) include(AzureVcpkg) az_vcpkg_integrate() endif() @@ -11,7 +11,7 @@ set(RL_SIM_SOURCES robot_joint.cc rl_sim.cc ) -if(RL_CXX_STANDARD GREATER_EQUAL 14 AND vw_USE_AZURE_FACTORIES) +if(RL_LINK_AZURE_LIBS) list(APPEND RL_SIM_SOURCES azure_credentials.cc ) @@ -23,7 +23,7 @@ add_executable(rl_sim_cpp.out target_link_libraries(rl_sim_cpp.out PRIVATE Boost::program_options rlclientlib) -if(RL_CXX_STANDARD GREATER_EQUAL 14 AND vw_USE_AZURE_FACTORIES) +if(RL_LINK_AZURE_LIBS) find_package(azure-identity-cpp CONFIG REQUIRED) target_link_libraries(rl_sim_cpp.out PRIVATE Azure::azure-identity) endif() diff --git a/examples/rl_sim_cpp/azure_credentials.cc b/examples/rl_sim_cpp/azure_credentials.cc index db796b555..f26b17ebf 100644 --- a/examples/rl_sim_cpp/azure_credentials.cc +++ b/examples/rl_sim_cpp/azure_credentials.cc @@ -1,3 +1,4 @@ +#ifdef LINK_AZURE_LIBS #include "azure_credentials.h" #include "err_constants.h" #include "future_compat.h" @@ -10,7 +11,6 @@ #include #include -#ifdef HAS_STD14 using namespace reinforcement_learning; diff --git a/examples/rl_sim_cpp/azure_credentials.h b/examples/rl_sim_cpp/azure_credentials.h index 0a56fefa8..889bd8704 100644 --- a/examples/rl_sim_cpp/azure_credentials.h +++ b/examples/rl_sim_cpp/azure_credentials.h @@ -1,12 +1,11 @@ #pragma once -#include "future_compat.h" - -#ifdef HAS_STD14 +#ifdef LINK_AZURE_LIBS #include #include "api_status.h" #include "configuration.h" +#include "future_compat.h" #include #include diff --git a/examples/rl_sim_cpp/rl_sim.cc b/examples/rl_sim_cpp/rl_sim.cc index 8e8cfed98..c98b408e7 100644 --- a/examples/rl_sim_cpp/rl_sim.cc +++ b/examples/rl_sim_cpp/rl_sim.cc @@ -493,7 +493,7 @@ int rl_sim::init_rl() // probably incompatible with the throughput option? else if (_options["azure_oauth_factories"].as()) { -#ifdef HAS_STD14 +#ifdef LINK_AZURE_LIBS // Note: This requires C++14 or better using namespace std::placeholders; reinforcement_learning::oauth_callback_t callback = diff --git a/examples/rl_sim_cpp/rl_sim.h b/examples/rl_sim_cpp/rl_sim.h index a232ea643..bfdcc6799 100644 --- a/examples/rl_sim_cpp/rl_sim.h +++ b/examples/rl_sim_cpp/rl_sim.h @@ -178,5 +178,7 @@ class rl_sim int64_t _delay = 2000; bool _quiet = false; bool _random_ids = true; +#ifdef LINK_AZURE_LIBS AzureCredentials _creds; +#endif }; diff --git a/rlclientlib/CMakeLists.txt b/rlclientlib/CMakeLists.txt index 1a134256b..d1302421e 100644 --- a/rlclientlib/CMakeLists.txt +++ b/rlclientlib/CMakeLists.txt @@ -213,6 +213,9 @@ if(vw_USE_AZURE_FACTORIES) target_compile_definitions(rlclientlib PRIVATE USE_AZURE_FACTORIES) endif() +if(RL_LINK_AZURE_LIBS) + target_compile_definitions(rlclientlib PRIVATE LINK_AZURE_LIBS) +endif() if(RL_USE_ZSTD) target_compile_definitions(rlclientlib PRIVATE USE_ZSTD) diff --git a/rlclientlib/utility/api_header_token.h b/rlclientlib/utility/api_header_token.h index 206a257f2..9dcc0e395 100644 --- a/rlclientlib/utility/api_header_token.h +++ b/rlclientlib/utility/api_header_token.h @@ -85,11 +85,10 @@ class api_header_token_callback api_status::try_update(status, result, error_code::not_initialized_s); return result; } - using namespace std::chrono_literals; using namespace std::chrono; system_clock::time_point now = system_clock::now(); // TODO: make this configurable? - system_clock::time_point refresh_time = _token_expiry - 10s; + system_clock::time_point refresh_time = _token_expiry - std::chrono::seconds(10); if (now >= refresh_time) { RETURN_IF_FAIL(refresh_auth_token(status, trace)); @@ -109,7 +108,6 @@ class api_header_token_callback private: int refresh_auth_token(api_status* status, i_trace* trace) { - using namespace std::chrono_literals; using namespace std::chrono; system_clock::time_point tp; RETURN_IF_FAIL(_token_callback(_scopes, _bearer_token, _token_expiry));