File: crossplatformbuild.patch

package info (click to toggle)
onnxruntime 1.21.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 333,732 kB
  • sloc: cpp: 3,153,079; python: 179,219; ansic: 109,131; asm: 37,791; cs: 34,424; perl: 13,070; java: 11,047; javascript: 6,330; pascal: 4,126; sh: 3,277; xml: 598; objc: 281; makefile: 59
file content (184 lines) | stat: -rw-r--r-- 6,167 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
diff --git a/mlmodel/src/MILBlob/Blob/FileWriter.cpp b/mlmodel/src/MILBlob/Blob/FileWriter.cpp
index adc7bfcf..7b2bf9cc 100644
--- a/mlmodel/src/MILBlob/Blob/FileWriter.cpp
+++ b/mlmodel/src/MILBlob/Blob/FileWriter.cpp
@@ -8,8 +8,12 @@
 
 #include <cstdio>
 #include <stdexcept>
+
+// ORT_EDIT: Exclude mmap on Windows. Not used in this file anyway.
+#if !defined(_WIN32)
 #include <sys/mman.h>
 #include <sys/stat.h>
+#endif
 
 using namespace MILBlob;
 using namespace MILBlob::Blob;
diff --git a/mlmodel/src/MILBlob/Blob/FileWriter.hpp b/mlmodel/src/MILBlob/Blob/FileWriter.hpp
index 2bc99403..49239513 100644
--- a/mlmodel/src/MILBlob/Blob/FileWriter.hpp
+++ b/mlmodel/src/MILBlob/Blob/FileWriter.hpp
@@ -6,7 +6,8 @@
 #pragma once
 
 #include "MILBlob/Util/Span.hpp"
-
+// ORT_EDIT: add missing header
+#include <cstdint>
 #include <fstream>
 #include <string>
 #include <type_traits>
diff --git a/mlmodel/src/MILBlob/Fp16.cpp b/mlmodel/src/MILBlob/Fp16.cpp
index ae1e71a1..77a7161f 100644
--- a/mlmodel/src/MILBlob/Fp16.cpp
+++ b/mlmodel/src/MILBlob/Fp16.cpp
@@ -5,6 +5,8 @@
 
 #include "MILBlob/Fp16.hpp"
 
+// ORT_EDIT: Exclude clang specific pragmas from other builds
+#if defined(__clang__)
 // fp16 lib code has some conversion warnings we don't want to globally ignore
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wincompatible-pointer-types"
@@ -12,6 +14,9 @@
 #pragma clang diagnostic ignored "-Wconversion"
 #include "fp16/fp16.h"
 #pragma clang diagnostic pop
+#else
+#include "fp16/fp16.h"
+#endif
 
 using namespace MILBlob;
 
diff --git a/modelpackage/src/ModelPackage.cpp b/modelpackage/src/ModelPackage.cpp
index 8fee56b9..5508e316 100644
--- a/modelpackage/src/ModelPackage.cpp
+++ b/modelpackage/src/ModelPackage.cpp
@@ -26,7 +26,14 @@ namespace std {
 #else
 #error "missing required header <filesystem>"
 #endif
+
+// ORT_EDIT: Use UuidCreate on Windows.
+#if defined(_WIN32)
+#pragma comment(lib, "rpcrt4.lib")  // UuidCreate
+#include <windows.h>
+#else
 #include <uuid/uuid.h>
+#endif
 #include <vector>
 
 #if defined(__cplusplus)
@@ -187,7 +194,10 @@ public:
     ModelPackageItemInfo createFile(const std::string& name, const std::string& author, const std::string& description);
 };
 
+// ORT_EDIT: pragma only available on APPLE platforms
+#if defined(__APPLE__)
 #pragma mark ModelPackageImpl
+#endif
 
 ModelPackageImpl::ModelPackageImpl(const std::filesystem::path& path, bool createIfNecessary, bool readOnly)
 : m_packagePath(path),
@@ -372,6 +382,20 @@ std::filesystem::path ModelPackageImpl::getItemPath(const std::string& name, con
 }
 
 std::string ModelPackageImpl::generateIdentifier() const {
+// ORT_EDIT: Use built-in UUID generation on Windows
+#if defined(_WIN32)
+    UUID uuid;
+    UuidCreate(&uuid);
+
+    RPC_CSTR uuidStr;
+    UuidToStringA(&uuid, &uuidStr);
+
+    std::string uuidStrCpp(reinterpret_cast<char*>(uuidStr));
+
+    RpcStringFreeA(&uuidStr);
+
+    return uuidStrCpp;
+#else
     uuid_t uuid;
     
     // uuid_unparse generates a 36-character null-terminated string (37 bytes).
@@ -383,6 +407,7 @@ std::string ModelPackageImpl::generateIdentifier() const {
     uuid_unparse(uuid, buf);
         
     return std::string(buf);
+#endif
 }
 
 ModelPackageItemInfo ModelPackageImpl::createFile(const std::string& name, const std::string& author, const std::string& description) {
@@ -468,7 +493,14 @@ std::shared_ptr<ModelPackageItemInfo> ModelPackageImpl::findItem(const std::stri
     auto author = itemInfoEntry->getString(kModelPackageItemInfoAuthorKey);
     auto description = itemInfoEntry->getString(kModelPackageItemInfoDescriptionKey);
     
+// ORT_EDIT: need to use path.string() on Windows
+#if defined(_WIN32)
+    return std::make_shared<ModelPackageItemInfo>(std::make_shared<ModelPackageItemInfoImpl>(identifier, path.string(), name, author, description));
+
+#else
     return std::make_shared<ModelPackageItemInfo>(std::make_shared<ModelPackageItemInfoImpl>(identifier, path, name, author, description));
+#endif
+
 }
 
 std::shared_ptr<ModelPackageItemInfo> ModelPackageImpl::findItem(const std::string& name, const std::string& author) const
@@ -514,7 +546,9 @@ void ModelPackageImpl::removeItem(const std::string& identifier)
     }
     
     auto path = m_packageDataDirPath / itemInfoEntry->getString(kModelPackageItemInfoPathKey);
-    if (0 != std::remove(path.c_str())) {
+    // ORT_EDIT: std::remove doesn't work on Windows. Use std::filesystem::remove instead.
+    // if (0 != std::remove(path.c_str())) {
+    if (!std::filesystem::remove(path)) {
         throw std::runtime_error("Failed to remove file at path: " + path.string());
     }
     
@@ -525,13 +559,16 @@ bool ModelPackageImpl::isValid(const std::filesystem::path& path)
 {
     try {
         ModelPackageImpl(path, false, true);
-    } catch (std::runtime_error& e) {
+    } catch (std::runtime_error& /*e*/) {  // ORT_EDIT: comment out unused variable
         return false;
     }
     return true;
 }
 
+// ORT_EDIT: pragma only available on APPLE platforms
+#if defined(__APPLE__)
 #pragma mark ModelPackage
+#endif
 
 ModelPackage::ModelPackage(const std::string& packagePath, bool createIfNecessary, bool readOnly)
 : m_modelPackageImpl(std::make_shared<ModelPackageImpl>(packagePath, createIfNecessary, readOnly))
@@ -544,7 +581,12 @@ ModelPackage::~ModelPackage()
 
 std::string ModelPackage::path() const
 {
+// ORT_EDIT: Windows doesn't automatically convert to std::string as the native format could be char or wchar.
+#if defined(_WIN32)
+    return m_modelPackageImpl->path().string();
+#else
     return m_modelPackageImpl->path();
+#endif
 }
 
 std::string ModelPackage::setRootModel(const std::string& path, const std::string& name, const std::string& author, const std::string& description)
diff --git a/modelpackage/src/utils/JsonMap.hpp b/modelpackage/src/utils/JsonMap.hpp
index 0d7dc3f4..b700cfd5 100644
--- a/modelpackage/src/utils/JsonMap.hpp
+++ b/modelpackage/src/utils/JsonMap.hpp
@@ -10,7 +10,8 @@
 #include <iostream>
 #include <vector>
 #include <string>
-
+// ORT_EDIT: add missing header
+#include <memory>
 class JsonMapImpl;
 
 class JsonMap {