Skip to content

Commit 5cfa341

Browse files
committed
install x64 binaries when packages don't provide arm64ec ones
1 parent 8325b97 commit 5cfa341

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

src/index_v1.cpp

+21-8
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222

2323
#include <sstream>
2424

25-
static void LoadMetadataV1(XmlNode , Metadata *);
26-
static void LoadCategoryV1(XmlNode , Index *);
27-
static void LoadPackageV1(XmlNode , Category *);
28-
static void LoadVersionV1(XmlNode , Package *);
29-
static void LoadSourceV1(XmlNode , Version *);
25+
static void LoadMetadataV1(XmlNode, Metadata *);
26+
static void LoadCategoryV1(XmlNode, Index *);
27+
static void LoadPackageV1(XmlNode, Category *);
28+
static void LoadVersionV1(XmlNode, Package *);
29+
static void LoadSourceV1(XmlNode, Version *, bool hasArm64Ec);
3030

3131
void Index::loadV1(XmlNode root, Index *ri)
3232
{
@@ -117,8 +117,21 @@ void LoadVersionV1(XmlNode verNode, Package *pkg)
117117

118118
XmlNode node = verNode.firstChild("source");
119119

120+
bool hasArm64Ec = false;
121+
#if defined(_WIN32) && defined(_M_ARM64EC)
120122
while(node) {
121-
LoadSourceV1(node, ver);
123+
const char *platform = *node.attribute("platform");
124+
if(platform && Platform(platform) == Platform::Windows_arm64ec) {
125+
hasArm64Ec = true;
126+
break;
127+
}
128+
node = node.nextSibling("source");
129+
}
130+
node = verNode.firstChild("source");
131+
#endif
132+
133+
while(node) {
134+
LoadSourceV1(node, ver, hasArm64Ec);
122135
node = node.nextSibling("source");
123136
}
124137

@@ -133,7 +146,7 @@ void LoadVersionV1(XmlNode verNode, Package *pkg)
133146
ptr.release();
134147
}
135148

136-
void LoadSourceV1(XmlNode node, Version *ver)
149+
void LoadSourceV1(XmlNode node, Version *ver, const bool hasArm64Ec)
137150
{
138151
const XmlString &platform = node.attribute("platform"),
139152
&type = node.attribute("type"),
@@ -146,7 +159,7 @@ void LoadSourceV1(XmlNode node, Version *ver)
146159
std::unique_ptr<Source> ptr(src);
147160

148161
src->setChecksum(checksum.value_or(""));
149-
src->setPlatform(platform.value_or("all"));
162+
src->setPlatform(Platform(platform.value_or("all"), hasArm64Ec));
150163
src->setTypeOverride(Package::getType(type.value_or("")));
151164

152165
int sections = 0;

src/platform.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const Platform::Enum Platform::Current = Platform::
6262
static_assert(Platform::Current != Platform::Unknown,
6363
"The current operating system or architecture is not supported.");
6464

65-
auto Platform::parse(const char *platform) -> Enum
65+
auto Platform::parse(const char *platform, const bool hasArm64Ec) -> Enum
6666
{
6767
constexpr std::pair<const char *, Enum> map[] {
6868
{ "all", Generic },
@@ -85,8 +85,11 @@ auto Platform::parse(const char *platform) -> Enum
8585
};
8686

8787
for(auto &[key, value] : map) {
88-
if(!strcmp(platform, key))
88+
if(!strcmp(platform, key)) {
89+
if(!hasArm64Ec && value == Windows_x64)
90+
return Windows_x64_arm64ec;
8991
return value;
92+
}
9093
}
9194

9295
return Unknown;

src/platform.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Platform {
3838
Windows_x64 = 1<<8,
3939
Windows_arm64ec = 1<<9,
4040
Windows_Any = Windows_x86 | Windows_x64 | Windows_arm64ec,
41+
Windows_x64_arm64ec = Windows_x64 | Windows_arm64ec,
4142

4243
Generic = Darwin_Any | Linux_Any | Windows_Any,
4344
};
@@ -46,7 +47,7 @@ class Platform {
4647

4748
Platform() : m_value(Generic) {}
4849
Platform(Enum val) : m_value(val) {}
49-
Platform(const char *str) : m_value(parse(str)) {}
50+
Platform(const char *str, bool hasArm64Ec = true) : m_value(parse(str, hasArm64Ec)) {}
5051

5152
Enum value() const { return m_value; }
5253
bool test() const;
@@ -55,7 +56,7 @@ class Platform {
5556
Platform &operator=(Enum n) { m_value = n; return *this; }
5657

5758
private:
58-
static Enum parse(const char *);
59+
static Enum parse(const char *, bool hasArm64Ec);
5960

6061
Enum m_value;
6162
};

test/platform.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ TEST_CASE("platform from string", M) {
2323
REQUIRE(Platform("windows") == Platform::Windows_Any);
2424
REQUIRE(Platform("win32") == Platform::Windows_x86);
2525
REQUIRE(Platform("win64") == Platform::Windows_x64);
26+
REQUIRE(Platform("win64", false) == Platform::Windows_x64_arm64ec);
2627
REQUIRE(Platform("windows-arm64ec") == Platform::Windows_arm64ec);
2728
}
2829

0 commit comments

Comments
 (0)