From cf6a1c1715643fb65fea4ecc44d4523b61f4ba6c Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Fri, 8 May 2020 15:59:16 -0700 Subject: [PATCH] Fix Windows Inbox build failing on 1) building raw api tests and 2) referencing _winml namespace in onnxruntime.dll (#3872) * add build inbox flag * remove raw tests and wstring for utf filenames * enable raw tests * use ToWideString * create new utf8 helper * update string helper to utf8 Co-authored-by: Sheil Kumar --- cmake/winml.cmake | 3 +++ cmake/winml_unittests.cmake | 22 +++++++++++++++++++--- include/onnxruntime/core/common/common.h | 1 + onnxruntime/core/common/str_helper.cc | 4 ++-- winml/adapter/winml_adapter_model.cpp | 7 +++++-- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 015184382a..9d7dfdd591 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -24,6 +24,8 @@ set(winml_lib_api_ort_dir ${REPO_ROOT}/winml/lib/api.ort) set(winml_lib_common_dir ${REPO_ROOT}/winml/lib/common) set(winml_lib_telemetry_dir ${REPO_ROOT}/winml/lib/telemetry) +set(winml_is_inbox false) + if (onnxruntime_WINML_NAMESPACE_OVERRIDE) set(output_name "${onnxruntime_WINML_NAMESPACE_OVERRIDE}.AI.MachineLearning") set(idl_native_output_name "${onnxruntime_WINML_NAMESPACE_OVERRIDE}.AI.MachineLearning.Native") @@ -31,6 +33,7 @@ if (onnxruntime_WINML_NAMESPACE_OVERRIDE) if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows") set(winml_midl_defines "/DBUILD_INBOX=1") + set(winml_is_inbox true) endif() set(winml_root_ns "${onnxruntime_WINML_NAMESPACE_OVERRIDE}") diff --git a/cmake/winml_unittests.cmake b/cmake/winml_unittests.cmake index 29f5bdf9ab..cbf4e13c23 100644 --- a/cmake/winml_unittests.cmake +++ b/cmake/winml_unittests.cmake @@ -80,11 +80,27 @@ function(get_winml_test_api_src output_winml_test_api_src ) file(GLOB winml_test_api_src CONFIGURE_DEPENDS - "${winml_test_src_path}/api/*.h" - "${winml_test_src_path}/api/*.cpp" + "${winml_test_src_path}/api/APITest.h" + "${winml_test_src_path}/api/LearningModelAPITest.h" + "${winml_test_src_path}/api/LearningModelBindingAPITest.h" + "${winml_test_src_path}/api/LearningModelSessionAPITest.h" + "${winml_test_src_path}/api/LearningModelAPITest.cpp" + "${winml_test_src_path}/api/LearningModelBindingAPITest.cpp" + "${winml_test_src_path}/api/LearningModelSessionAPITest.cpp") + + if (NOT winml_is_inbox) + file(GLOB winml_redist_only_api_src CONFIGURE_DEPENDS + "${winml_test_src_path}/api/RawApiHelpers.h" + "${winml_test_src_path}/api/RawApiTests.h" + "${winml_test_src_path}/api/RawApiTestsGpu.h" + "${winml_test_src_path}/api/RawApiHelpers.cpp" + "${winml_test_src_path}/api/RawApiTests.cpp" + "${winml_test_src_path}/api/RawApiTestsGpu.cpp" "${winml_test_src_path}/api/raw/*.h" "${winml_test_src_path}/api/raw/*.cpp") - set(${output_winml_test_api_src} ${winml_test_api_src} PARENT_SCOPE) + endif() + + set(${output_winml_test_api_src} ${winml_test_api_src} ${winml_redist_only_api_src} PARENT_SCOPE) endfunction() function(get_winml_test_concurrency_src diff --git a/include/onnxruntime/core/common/common.h b/include/onnxruntime/core/common/common.h index becc3d39d5..f6ff7d3fdf 100644 --- a/include/onnxruntime/core/common/common.h +++ b/include/onnxruntime/core/common/common.h @@ -241,4 +241,5 @@ inline std::wstring ToWideString(const std::wstring& s) { return s; } #else inline std::string ToWideString(const std::string& s) { return s; } #endif + } // namespace onnxruntime diff --git a/onnxruntime/core/common/str_helper.cc b/onnxruntime/core/common/str_helper.cc index 7eb627c1d8..5da383292e 100644 --- a/onnxruntime/core/common/str_helper.cc +++ b/onnxruntime/core/common/str_helper.cc @@ -20,10 +20,10 @@ std::string ToMBString(const std::wstring& s) { std::wstring ToWideString(const std::string& s) { if (s.size() >= static_cast(std::numeric_limits::max())) throw std::runtime_error("length overflow"); const int src_len = static_cast(s.size() + 1); - const int len = MultiByteToWideChar(CP_ACP, 0, s.data(), src_len, nullptr, 0); + const int len = MultiByteToWideChar(CP_UTF8, 0, s.data(), src_len, nullptr, 0); assert(len > 0); std::wstring ret(static_cast(len) - 1, '\0'); - const int r = MultiByteToWideChar(CP_ACP, 0, s.data(), src_len, (wchar_t*)ret.data(), len); + const int r = MultiByteToWideChar(CP_UTF8, 0, s.data(), src_len, (wchar_t*)ret.data(), len); assert(len == r); return ret; } diff --git a/winml/adapter/winml_adapter_model.cpp b/winml/adapter/winml_adapter_model.cpp index 9b5466c40a..a88f0cf574 100644 --- a/winml/adapter/winml_adapter_model.cpp +++ b/winml/adapter/winml_adapter_model.cpp @@ -11,13 +11,13 @@ #include "core/session/ort_apis.h" #include "winml_adapter_apis.h" #include "core/framework/error_code_helper.h" +#include "core/common/common.h" #include #include #include #include "google/protobuf/io/zero_copy_stream_impl.h" #include "core/framework/onnxruntime_typeinfo.h" -#include "StringHelpers.h" namespace winmla = Windows::AI::MachineLearning::Adapter; @@ -120,7 +120,10 @@ OrtModel::OrtModel(std::unique_ptr model_proto) : model_proto_ // factory methods for creating an ort model from a path static OrtStatus* CreateModelProto(const char* path, std::unique_ptr& out) { int file_descriptor; - auto wide_path = _winml::Strings::HStringFromUTF8(path); + + auto path_str = std::string(path); + auto wide_path = onnxruntime::ToWideString(path_str); + _set_errno(0); // clear errno _wsopen_s( &file_descriptor,