Skip to content

Commit 6804927

Browse files
committed
win7 compat
1 parent 0bcc861 commit 6804927

File tree

10 files changed

+96
-44
lines changed

10 files changed

+96
-44
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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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, FILE_READ_ATTRIBUTES, 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, FILE_READ_ATTRIBUTES, 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, FILE_READ_ATTRIBUTES, 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+
@@ -22,6 +22,12 @@ limitations under the License.
69+
#include <numeric>
70+
#include <algorithm>
71+
72+
+#ifndef GetSystemTimePreciseAsFileTime
73+
+static void WINAPI GetSystemTimePreciseAsFileTime(LPFILETIME lpSystemTimeAsFileTime) {
74+
+ GetSystemTimeAsFileTime(lpSystemTimeAsFileTime);
75+
+}
76+
+#endif
77+
+
78+
namespace onnxruntime {
79+
80+
namespace {

conan_profiles/base/msvc-intel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ compiler.update=4
1111
[conf]
1212
# VS 2022
1313
tools.microsoft.msbuild:vs_version=17
14+
15+
# https://walbourn.github.io/a-brief-history-of-windows-sdks/
16+
# https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt
17+
# https://learn.microsoft.com/en-us/windows/win32/WinProg/using-the-windows-headers
18+
{% set _WIN32_WINNT_WIN7 = '0x0601' %}
19+
{% set NTDDI_WIN7 = '0x06010000' %}
20+
{% set win7_defines = [
21+
'_WIN32_WINNT={}'.format(_WIN32_WINNT_WIN7),
22+
'WINVER={}'.format(_WIN32_WINNT_WIN7),
23+
'NTDDI_VERSION={}'.format(NTDDI_WIN7),
24+
] %}
25+
tools.build:defines={{ win7_defines }}

conan_profiles/base/msvc-win7

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

conan_profiles/base/msvc-win8

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

conan_profiles/msvc-x64

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
include(base/msvc-intel)
2-
include(base/msvc-win8)
32

43
[settings]
54
arch=x86_64

conan_profiles/msvc-x64-win7

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

conan_profiles/msvc-x86

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
include(base/msvc-intel)
2-
include(base/msvc-win8)
32

43
[settings]
54
arch=x86

conan_profiles/msvc-x86-win7

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

0 commit comments

Comments
 (0)