Skip to content

Commit 80b722a

Browse files
committed
try suggested patch from PR review
1 parent 75c2c1e commit 80b722a

File tree

12 files changed

+142
-46
lines changed

12 files changed

+142
-46
lines changed

.github/workflows/rebuildDependencies.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,10 @@ jobs:
4545
os: windows-latest
4646
conan_profiles: '["msvc-x64"]'
4747
conan_options: -o "&:target_pre_windows10=True"
48-
- platform: windows-x64-win7
49-
os: windows-latest
50-
conan_profiles: '["msvc-x64-win7"]'
51-
conan_options: -o "&:target_pre_windows10=True" -o "&:with_onnxruntime=False"
5248
- platform: windows-x86
5349
os: windows-latest
5450
conan_profiles: '["msvc-x86"]'
5551
conan_options: -o "&:target_pre_windows10=True"
56-
- platform: windows-x86-win7
57-
os: windows-latest
58-
conan_profiles: '["msvc-x86-win7"]'
59-
conan_options: -o "&:target_pre_windows10=True" -o "&:with_onnxruntime=False"
6052
- platform: windows-arm64
6153
os: windows-11-arm
6254
conan_profiles: '["msvc-arm64"]'

conan_patches/onnxruntime/conandata.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ patches:
77
- patch_file: "patches/msvc-x86.diff"
88
patch_description: |
99
Fixes detection of x86 windows targets during cross-compilation.
10+
- patch_file: "patches/win7.diff"
11+
patch_description: |
12+
Fixes compile errors on for windows 7 targets:
13+
error C3861: 'CreateFile2': identifier not found
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
--- a/onnxruntime/test/shared_lib/test_model_loading.cc
2+
+++ b/onnxruntime/test/shared_lib/test_model_loading.cc
3+
@@ -227,7 +227,7 @@ using ScopedFileDescriptor = ScopedResource<FileDescriptorTraits>;
4+
5+
void FileMmap(const ORTCHAR_T* file_path, void*& mapped_base) {
6+
#ifdef _WIN32
7+
- wil::unique_hfile file_handle{CreateFile2(file_path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL)};
8+
+ wil::unique_hfile file_handle{CreateFileW(file_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)};
9+
ASSERT_TRUE(file_handle.get() != INVALID_HANDLE_VALUE);
10+
11+
wil::unique_hfile file_mapping_handle{
12+
--- a/onnxruntime/core/platform/windows/env.cc
13+
+++ b/onnxruntime/core/platform/windows/env.cc
14+
@@ -314,7 +314,7 @@ PIDType WindowsEnv::GetSelfPid() const {
15+
16+
Status WindowsEnv::GetFileLength(_In_z_ const ORTCHAR_T* file_path, size_t& length) const {
17+
wil::unique_hfile file_handle{
18+
- CreateFile2(file_path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, OPEN_EXISTING, NULL)};
19+
+ CreateFileW(file_path, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)};
20+
if (file_handle.get() == INVALID_HANDLE_VALUE) {
21+
const auto error_code = GetLastError();
22+
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "open file ", ToUTF8String(Basename(file_path)), " fail, errcode = ", error_code, " - ", std::system_category().message(error_code));
23+
@@ -361,7 +361,7 @@ Status WindowsEnv::ReadFileIntoBuffer(_In_z_ const ORTCHAR_T* const file_path, c
24+
ORT_RETURN_IF_NOT(offset >= 0, "offset < 0");
25+
ORT_RETURN_IF_NOT(length <= buffer.size(), "length > buffer.size()");
26+
wil::unique_hfile file_handle{
27+
- CreateFile2(file_path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL)};
28+
+ CreateFileW(file_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)};
29+
if (file_handle.get() == INVALID_HANDLE_VALUE) {
30+
const auto error_code = GetLastError();
31+
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "open file ", ToUTF8String(Basename(file_path)), " fail, errcode = ", error_code, " - ", std::system_category().message(error_code));
32+
@@ -414,7 +414,7 @@ Status WindowsEnv::MapFileIntoMemory(_In_z_ const ORTCHAR_T* file_path,
33+
}
34+
35+
wil::unique_hfile file_handle{
36+
- CreateFile2(file_path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, NULL)};
37+
+ CreateFileW(file_path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)};
38+
if (file_handle.get() == INVALID_HANDLE_VALUE) {
39+
const auto error_code = GetLastError();
40+
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL,
41+
@@ -600,16 +600,14 @@ common::Status WindowsEnv::GetCanonicalPath(
42+
PathString& canonical_path) const {
43+
// adapted from MSVC STL std::filesystem::canonical() implementation
44+
// https://github.com/microsoft/STL/blob/ed3cbf36416a385828e7a5987ca52cb42882d84b/stl/inc/filesystem#L2986
45+
- CREATEFILE2_EXTENDED_PARAMETERS param;
46+
- memset(&param, 0, sizeof(param));
47+
- param.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
48+
- param.dwFileFlags = FILE_FLAG_BACKUP_SEMANTICS;
49+
- wil::unique_hfile file_handle{CreateFile2(
50+
- path.c_str(),
51+
- FILE_READ_ATTRIBUTES,
52+
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
53+
- OPEN_EXISTING,
54+
- &param)};
55+
+ wil::unique_hfile file_handle{CreateFileW(
56+
+ path.c_str(), // LPCWSTR lpFileName
57+
+ FILE_READ_ATTRIBUTES, // DWORD dwDesiredAccess
58+
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // DWORD dwShareMode
59+
+ nullptr, // LPSECURITY_ATTRIBUTES lpSecurityAttributes
60+
+ OPEN_EXISTING, // DWORD dwCreationDisposition
61+
+ FILE_FLAG_BACKUP_SEMANTICS, // DWORD dwFlagsAndAttributes
62+
+ nullptr)}; // HANDLE hTemplateFile
63+
64+
if (file_handle.get() == INVALID_HANDLE_VALUE) {
65+
const auto error_code = GetLastError();
66+
--- a/onnxruntime/core/platform/windows/env_time.cc
67+
+++ b/onnxruntime/core/platform/windows/env_time.cc
68+
@@ -18,6 +18,7 @@ limitations under the License.
69+
70+
#include <time.h>
71+
#include <windows.h>
72+
+#include <sysinfoapi.h>
73+
#include <chrono>
74+
#include <numeric>
75+
#include <algorithm>
76+
@@ -28,14 +29,10 @@ namespace {
77+
78+
class WindowsEnvTime : public EnvTime {
79+
public:
80+
- WindowsEnvTime() : GetSystemTimePreciseAsFileTime_(GetSystemTimePreciseAsFileTime) {}
81+
+ WindowsEnvTime() = default;
82+
83+
uint64_t NowMicros() override {
84+
- if (GetSystemTimePreciseAsFileTime_ != NULL) {
85+
- // GetSystemTimePreciseAsFileTime function is only available in latest
86+
- // versions of Windows, so we need to check for its existence here.
87+
- // All std::chrono clocks on Windows proved to return
88+
- // values that may repeat, which is not good enough for some uses.
89+
+ // System time in 100-ns ticks since 1601-01-01
90+
constexpr int64_t kUnixEpochStartTicks = 116444736000000000i64;
91+
constexpr int64_t kFtToMicroSec = 10;
92+
93+
@@ -43,7 +40,8 @@ class WindowsEnvTime : public EnvTime {
94+
// just any microseconds because it is often used as an argument
95+
// to TimedWait() on condition variable
96+
FILETIME system_time;
97+
- GetSystemTimePreciseAsFileTime_(&system_time);
98+
+ // Get current system time as FILETIME (available on all supported Windows versions)
99+
+ GetSystemTimeAsFileTime(&system_time);
100+
101+
LARGE_INTEGER li;
102+
li.LowPart = system_time.dwLowDateTime;
103+
@@ -54,16 +52,11 @@ class WindowsEnvTime : public EnvTime {
104+
li.QuadPart /= kFtToMicroSec;
105+
return li.QuadPart;
106+
}
107+
- using namespace std::chrono;
108+
- return duration_cast<microseconds>(system_clock::now().time_since_epoch())
109+
- .count();
110+
- }
111+
-
112+
- void SleepForMicroseconds(int64_t micros) { Sleep(static_cast<DWORD>(micros) / 1000); }
113+
114+
- private:
115+
- typedef VOID(WINAPI* FnGetSystemTimePreciseAsFileTime)(LPFILETIME);
116+
- FnGetSystemTimePreciseAsFileTime GetSystemTimePreciseAsFileTime_;
117+
+ void SleepForMicroseconds(int64_t micros) {
118+
+ DWORD ms = static_cast<DWORD>((micros + 999) / 1000);
119+
+ Sleep(ms);
120+
+ }
121+
};
122+
123+
} // namespace

conan_patches/onnxruntime/recipe.diff

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
index 0757ecd..587294b 100644
1+
diff --git a/recipes/onnxruntime/all/conanfile.py b/recipes/onnxruntime/all/conanfile.py
2+
index 0757ecdc0..bb8cca8bf 100644
23
--- a/recipes/onnxruntime/all/conanfile.py
34
+++ b/recipes/onnxruntime/all/conanfile.py
45
@@ -34,6 +34,11 @@ class OnnxRuntimeConan(ConanFile):
@@ -13,3 +14,12 @@ index 0757ecd..587294b 100644
1314
}
1415
short_paths = True
1516

17+
@@ -47,7 +52,7 @@ class OnnxRuntimeConan(ConanFile):
18+
def _compilers_minimum_version(self):
19+
return {
20+
"Visual Studio": "17",
21+
- "msvc": "193",
22+
+ "msvc": "192",
23+
"gcc": "9",
24+
"clang": "5",
25+
"apple-clang": "10",

conan_profiles/base/msvc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include(common)
66
compiler=msvc
77
compiler.cppstd={{ vars.cppstd }}
88
compiler.runtime=dynamic
9+
compiler.version=194
910
os=Windows
1011

1112
[options]

conan_profiles/base/msvc-win7 renamed to conan_profiles/base/msvc-intel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ include(msvc)
33
[settings]
44
# https://blog.knatten.org/2022/08/26/microsoft-c-versions-explained/
55
# https://learn.microsoft.com/en-us/cpp/overview/compiler-versions
6-
# https://github.com/actions/runner-images/blob/win25/20251102.77/images/windows/Windows2025-Readme.md#microsoft-visual-c
76
# v142 / 14.29 / 19.29
87
compiler.version=192
98
compiler.update=9

conan_profiles/base/msvc-win8

Lines changed: 0 additions & 25 deletions
This file was deleted.

conan_profiles/msvc-arm64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include(base/msvc-win8)
1+
include(base/msvc)
22

33
[settings]
44
arch=armv8

conan_profiles/msvc-x64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include(base/msvc-win8)
1+
include(base/msvc-intel)
22

33
[settings]
44
arch=x86_64

conan_profiles/msvc-x64-win7

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)