Skip to content

Commit ab17c95

Browse files
committed
Patch crunch for win-arm64
1 parent 4de70f0 commit ab17c95

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

build/BuildWindowsTask.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,38 @@ public sealed class BuildWindowsTask : FrostingTask<BuildContext>
99

1010
public override void Run(BuildContext context)
1111
{
12+
// Apply ARM64 compatibility patches to crunch source
13+
ApplyArm64Patches(context);
14+
1215
BuildForArchitecture(context, "x64", "windows-x64");
13-
BuildForArchitecture(context, "ARM64", "windows-arm64", "-DCMAKE_CXX_FLAGS=\"/D_mm_pause=YieldProcessor\"");
16+
BuildForArchitecture(context, "ARM64", "windows-arm64");
17+
}
18+
19+
private void ApplyArm64Patches(BuildContext context)
20+
{
21+
// Fix crn_core.h: Ensure WIN32 is defined when _WIN32 is defined (MSVC defines _WIN32, not WIN32)
22+
context.ReplaceTextInFiles(
23+
"crunch/crnlib/crn_core.h",
24+
"// File: crn_core.h\r\n// See Copyright Notice and license at the end of inc/crnlib.h\r\n#pragma once",
25+
"// File: crn_core.h\r\n// See Copyright Notice and license at the end of inc/crnlib.h\r\n#pragma once\r\n\r\n// Ensure WIN32 is defined when _WIN32 is defined (MSVC defines _WIN32, not WIN32)\r\n#if defined(_WIN32) && !defined(WIN32)\r\n#define WIN32 1\r\n#endif");
26+
27+
// Fix crn_core.h: Add ARM64 platform detection before x64 check
28+
context.ReplaceTextInFiles(
29+
"crunch/crnlib/crn_core.h",
30+
"#define CRNLIB_PLATFORM_PC 1\r\n\r\n#if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)\r\n#define CRNLIB_PLATFORM_PC_X64 1",
31+
"#define CRNLIB_PLATFORM_PC 1\r\n\r\n#if defined(_M_ARM64)\r\n// Windows ARM64\r\n#define CRNLIB_PLATFORM_PC_ARM64 1\r\n#define CRNLIB_64BIT_POINTERS 1\r\n#define CRNLIB_CPU_HAS_64BIT_REGISTERS 1\r\n#define CRNLIB_LITTLE_ENDIAN_CPU 1\r\n#elif defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)\r\n#define CRNLIB_PLATFORM_PC_X64 1");
32+
33+
// Fix crn_core.h: Disable MSVC x86 intrinsics on ARM64
34+
context.ReplaceTextInFiles(
35+
"crunch/crnlib/crn_core.h",
36+
"#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)\r\n#define CRNLIB_USE_MSVC_INTRINSICS 1\r\n#endif",
37+
"#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)\r\n#if !defined(_M_ARM64)\r\n#define CRNLIB_USE_MSVC_INTRINSICS 1\r\n#endif\r\n#endif");
38+
39+
// Fix crn_atomics.h: Add ARM64 yield processor support
40+
context.ReplaceTextInFiles(
41+
"crunch/crnlib/crn_atomics.h",
42+
"#if defined(__GNUC__) && CRNLIB_PLATFORM_PC\r\nextern __inline__ __attribute__((__always_inline__, __gnu_inline__)) void crnlib_yield_processor() {\r\n __asm__ __volatile__(\"pause\");\r\n}\r\n#else\r\nCRNLIB_FORCE_INLINE void crnlib_yield_processor() {\r\n#if CRNLIB_USE_MSVC_INTRINSICS\r\n#if CRNLIB_PLATFORM_PC_X64\r\n _mm_pause();\r\n#else\r\n YieldProcessor();\r\n#endif\r\n#else\r\n// No implementation\r\n#endif\r\n}",
43+
"#if defined(__GNUC__) && CRNLIB_PLATFORM_PC\r\nextern __inline__ __attribute__((__always_inline__, __gnu_inline__)) void crnlib_yield_processor() {\r\n#if defined(__aarch64__)\r\n __asm__ __volatile__(\"yield\");\r\n#else\r\n __asm__ __volatile__(\"pause\");\r\n#endif\r\n}\r\n#else\r\nCRNLIB_FORCE_INLINE void crnlib_yield_processor() {\r\n#if defined(_M_ARM64)\r\n __yield();\r\n#elif CRNLIB_USE_MSVC_INTRINSICS\r\n#if CRNLIB_PLATFORM_PC_X64\r\n _mm_pause();\r\n#else\r\n YieldProcessor();\r\n#endif\r\n#else\r\n// No implementation\r\n#endif\r\n}");
1444
}
1545

1646
private void BuildForArchitecture(BuildContext context, string cmakeArch, string rid, string cmakeOptions = "")

0 commit comments

Comments
 (0)