Skip to content

Commit

Permalink
Add cmake option for azure libs, fix compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
peterychang committed Feb 2, 2024
1 parent 9bc06eb commit 9d3ddcd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions examples/rl_sim_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
)
Expand All @@ -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()
2 changes: 1 addition & 1 deletion examples/rl_sim_cpp/azure_credentials.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef LINK_AZURE_LIBS
#include "azure_credentials.h"
#include "err_constants.h"
#include "future_compat.h"
Expand All @@ -10,7 +11,6 @@

#include <exception>
#include <iostream>
#ifdef HAS_STD14

using namespace reinforcement_learning;

Expand Down
5 changes: 2 additions & 3 deletions examples/rl_sim_cpp/azure_credentials.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once

#include "future_compat.h"

#ifdef HAS_STD14
#ifdef LINK_AZURE_LIBS
#include <memory>

#include "api_status.h"
#include "configuration.h"
#include "future_compat.h"

#include <azure/identity/default_azure_credential.hpp>
#include <azure/identity/azure_cli_credential.hpp>
Expand Down
2 changes: 1 addition & 1 deletion examples/rl_sim_cpp/rl_sim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ int rl_sim::init_rl()
// probably incompatible with the throughput option?
else if (_options["azure_oauth_factories"].as<bool>())
{
#ifdef HAS_STD14
#ifdef LINK_AZURE_LIBS
// Note: This requires C++14 or better
using namespace std::placeholders;
reinforcement_learning::oauth_callback_t callback =
Expand Down
2 changes: 2 additions & 0 deletions examples/rl_sim_cpp/rl_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
3 changes: 3 additions & 0 deletions rlclientlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions rlclientlib/utility/api_header_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 9d3ddcd

Please sign in to comment.