Skip to content

Commit

Permalink
Merge branch 'arm64ec'
Browse files Browse the repository at this point in the history
Closes #88
  • Loading branch information
cfillion committed Oct 29, 2024
2 parents 46c179a + 5cfa341 commit 04accc2
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 89 deletions.
19 changes: 13 additions & 6 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ build_script:
- cmake --build build

test_script:
- '[ "$ARCH" = "arm64" ] || cmake --build build --target test'
- sh: '[[ "$ARCH" = arm64 ]] || cmake --build build --target test'
- cmd: 'if NOT "%ARCH%" == "arm64ec" cmake --build build --target test'

for:
- matrix: { only: [ appveyor_build_worker_image: &linux Ubuntu1804 ] }
Expand Down Expand Up @@ -113,11 +114,14 @@ for:

- matrix: { only: [ appveyor_build_worker_image: &windows Visual Studio 2022 ] }
cache:
- build\vcpkg_installed -> vcpkg.json
- build\vcpkg_installed -> vcpkg.json, cmake\vcpkg-triplets\arm64ec-windows-static.cmake
install:
- if "%ARCH%" == "x64" call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
- if "%ARCH%" == "x86" call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat"
- if "%ARCH%" == "x64" call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
- if "%ARCH%" == "x86" call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars32.bat"
- if "%ARCH%" == "arm64ec" call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsamd64_arm64.bat"
- if "%ARCH%" == "arm64ec" set CFLAGS=-arm64EC & set CXXFLAGS=-arm64EC
build_script:
- set VCPKG_OVERLAY_TRIPLETS=cmake\vcpkg-triplets
- cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
-DVCPKG_TARGET_TRIPLET=%ARCH%-windows-static
-DCMAKE_TOOLCHAIN_FILE=C:\Tools\vcpkg\scripts\buildsystems\vcpkg.cmake
Expand All @@ -128,12 +132,15 @@ for:

environment:
matrix:
- job_name: Windows 64-bit
- job_name: Windows x86 64-bit
appveyor_build_worker_image: *windows
ARCH: x64
- job_name: Windows 32-bit
- job_name: Windows x86 32-bit
appveyor_build_worker_image: *windows
ARCH: x86
- job_name: Windows ARM 64-bit EC
appveyor_build_worker_image: *windows
ARCH: arm64ec
- job_name: macOS x86 64-bit
appveyor_build_worker_image: macos-mojave
ARCH: x86_64
Expand Down
3 changes: 3 additions & 0 deletions cmake/vcpkg-triplets/arm64ec-windows-static.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(VCPKG_TARGET_ARCHITECTURE arm64ec)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
29 changes: 21 additions & 8 deletions src/index_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

#include <sstream>

static void LoadMetadataV1(XmlNode , Metadata *);
static void LoadCategoryV1(XmlNode , Index *);
static void LoadPackageV1(XmlNode , Category *);
static void LoadVersionV1(XmlNode , Package *);
static void LoadSourceV1(XmlNode , Version *);
static void LoadMetadataV1(XmlNode, Metadata *);
static void LoadCategoryV1(XmlNode, Index *);
static void LoadPackageV1(XmlNode, Category *);
static void LoadVersionV1(XmlNode, Package *);
static void LoadSourceV1(XmlNode, Version *, bool hasArm64Ec);

void Index::loadV1(XmlNode root, Index *ri)
{
Expand Down Expand Up @@ -117,8 +117,21 @@ void LoadVersionV1(XmlNode verNode, Package *pkg)

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

bool hasArm64Ec = false;
#if defined(_WIN32) && defined(_M_ARM64EC)
while(node) {
LoadSourceV1(node, ver);
const char *platform = *node.attribute("platform");
if(platform && Platform(platform) == Platform::Windows_arm64ec) {
hasArm64Ec = true;
break;
}
node = node.nextSibling("source");
}
node = verNode.firstChild("source");
#endif

while(node) {
LoadSourceV1(node, ver, hasArm64Ec);
node = node.nextSibling("source");
}

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

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

src->setChecksum(checksum.value_or(""));
src->setPlatform(platform.value_or("all"));
src->setPlatform(Platform(platform.value_or("all"), hasArm64Ec));
src->setTypeOverride(Package::getType(type.value_or("")));

int sections = 0;
Expand Down
18 changes: 12 additions & 6 deletions src/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const Platform::Enum Platform::Current = Platform::
# endif

#elif _WIN32
# ifdef _WIN64
# ifdef _M_ARM64EC
Windows_arm64ec
# elif _M_X64
Windows_x64
# else
Windows_x86
Expand All @@ -60,7 +62,7 @@ const Platform::Enum Platform::Current = Platform::
static_assert(Platform::Current != Platform::Unknown,
"The current operating system or architecture is not supported.");

auto Platform::parse(const char *platform) -> Enum
auto Platform::parse(const char *platform, const bool hasArm64Ec) -> Enum
{
constexpr std::pair<const char *, Enum> map[] {
{ "all", Generic },
Expand All @@ -76,14 +78,18 @@ auto Platform::parse(const char *platform) -> Enum
{ "linux-armv7l", Linux_armv7l },
{ "linux-aarch64", Linux_aarch64 },

{ "windows", Windows_Any },
{ "win32", Windows_x86 },
{ "win64", Windows_x64 },
{ "windows", Windows_Any },
{ "win32", Windows_x86 },
{ "win64", Windows_x64 },
{ "windows-arm64ec", Windows_arm64ec },
};

for(auto &[key, value] : map) {
if(!strcmp(platform, key))
if(!strcmp(platform, key)) {
if(!hasArm64Ec && value == Windows_x64)
return Windows_x64_arm64ec;
return value;
}
}

return Unknown;
Expand Down
14 changes: 8 additions & 6 deletions src/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ class Platform {
Linux_aarch64 = 1<<6,
Linux_Any = Linux_i686 | Linux_x86_64 | Linux_armv7l | Linux_aarch64,

Windows_x86 = 1<<7,
Windows_x64 = 1<<8,
Windows_Any = Windows_x86 | Windows_x64,
Windows_x86 = 1<<7,
Windows_x64 = 1<<8,
Windows_arm64ec = 1<<9,
Windows_Any = Windows_x86 | Windows_x64 | Windows_arm64ec,
Windows_x64_arm64ec = Windows_x64 | Windows_arm64ec,

Generic = Darwin_Any | Linux_Any | Windows_Any,
Generic = Darwin_Any | Linux_Any | Windows_Any,
};

static const Enum Current;

Platform() : m_value(Generic) {}
Platform(Enum val) : m_value(val) {}
Platform(const char *str) : m_value(parse(str)) {}
Platform(const char *str, bool hasArm64Ec = true) : m_value(parse(str, hasArm64Ec)) {}

Enum value() const { return m_value; }
bool test() const;
Expand All @@ -54,7 +56,7 @@ class Platform {
Platform &operator=(Enum n) { m_value = n; return *this; }

private:
static Enum parse(const char *);
static Enum parse(const char *, bool hasArm64Ec);

Enum m_value;
};
Expand Down
136 changes: 73 additions & 63 deletions test/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ TEST_CASE("platform from string", M) {
REQUIRE(Platform("all") == Platform::Generic);

SECTION("windows") {
REQUIRE(Platform("windows") == Platform::Windows_Any);
REQUIRE(Platform("win32") == Platform::Windows_x86);
REQUIRE(Platform("win64") == Platform::Windows_x64);
REQUIRE(Platform("windows") == Platform::Windows_Any);
REQUIRE(Platform("win32") == Platform::Windows_x86);
REQUIRE(Platform("win64") == Platform::Windows_x64);
REQUIRE(Platform("win64", false) == Platform::Windows_x64_arm64ec);
REQUIRE(Platform("windows-arm64ec") == Platform::Windows_arm64ec);
}

SECTION("macOS") {
Expand All @@ -47,84 +49,92 @@ TEST_CASE("test platform", M) {
{Platform::Generic, true },

#ifdef __APPLE__
{Platform::Linux_Any, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_i686, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},
{Platform::Windows_Any, false},
{Platform::Windows_x64, false},
{Platform::Windows_x86, false},

{Platform::Darwin_Any, true },
{Platform::Linux_Any, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_i686, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},
{Platform::Windows_Any, false},
{Platform::Windows_x64, false},
{Platform::Windows_x86, false},
{Platform::Windows_arm64ec, false},

{Platform::Darwin_Any, true },
# ifdef __x86_64__
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, true },
{Platform::Darwin_arm64, false},
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, true },
{Platform::Darwin_arm64, false},
# elif __i386__
{Platform::Darwin_i386, true },
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, false},
{Platform::Darwin_i386, true },
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, false},
# elif __arm64__
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, true },
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, true },
# else
# error Untested architecture
# endif

#elif __linux__
{Platform::Darwin_Any, false},
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, false},
{Platform::Windows_Any, false},
{Platform::Windows_x86, false},
{Platform::Windows_x64, false},

{Platform::Linux_Any, true },
{Platform::Darwin_Any, false},
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, false},
{Platform::Windows_Any, false},
{Platform::Windows_x86, false},
{Platform::Windows_x64, false},
{Platform::Windows_arm64ec, false},

{Platform::Linux_Any, true },
# ifdef __x86_64__
{Platform::Linux_i686, false},
{Platform::Linux_x86_64, true },
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},
{Platform::Linux_i686, false},
{Platform::Linux_x86_64, true },
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},
# elif __i686__
{Platform::Linux_i686, true },
{Platform::Linux_x86_64, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},
{Platform::Linux_i686, true },
{Platform::Linux_x86_64, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},
# elif __ARM_ARCH_7A__
{Platform::Linux_i686, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_armv7l, true },
{Platform::Linux_aarch64, false},
{Platform::Linux_i686, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_armv7l, true },
{Platform::Linux_aarch64, false},
# elif __aarch64__
{Platform::Linux_i686, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, true },
{Platform::Linux_i686, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, true },
# else
# error Untested architecture
# endif

#elif _WIN32
{Platform::Darwin_Any, false},
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, false},
{Platform::Linux_Any, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_i686, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},

{Platform::Windows_Any, true },
# ifdef _WIN64
{Platform::Windows_x86, false},
{Platform::Windows_x64, true },
{Platform::Darwin_Any, false},
{Platform::Darwin_i386, false},
{Platform::Darwin_x86_64, false},
{Platform::Darwin_arm64, false},
{Platform::Linux_Any, false},
{Platform::Linux_x86_64, false},
{Platform::Linux_i686, false},
{Platform::Linux_armv7l, false},
{Platform::Linux_aarch64, false},

{Platform::Windows_Any, true },
# ifdef _M_ARM64EC
{Platform::Windows_x86, false},
{Platform::Windows_x64, false},
{Platform::Windows_arm64ec, true },
# elif _M_X64
{Platform::Windows_x86, false},
{Platform::Windows_x64, true },
{Platform::Windows_arm64ec, false},
# else
{Platform::Windows_x86, true },
{Platform::Windows_x64, false},
{Platform::Windows_x86, true },
{Platform::Windows_x64, false},
{Platform::Windows_arm64ec, false},
# endif

#else
Expand Down

0 comments on commit 04accc2

Please sign in to comment.