From 5d06e383da500902e5c3a217ab365f4f02009656 Mon Sep 17 00:00:00 2001 From: Vladyslav Bahlai Date: Fri, 12 Jun 2026 21:47:40 +0300 Subject: [PATCH] Update die_library to latest and fix macOS arm64 build Bump .dielib_commit to da15bca (DIE engine 3.22) and add the build fixes needed for the new sources to compile on macOS arm64: - Put the bundled aqt Qt first on CMAKE_PREFIX_PATH so a system-wide Qt (e.g. Homebrew) cannot leak into transitive Qt6 config lookups. - Strip x86-only SIMD flags (-msse/-msse2/-mavx/-mavx2) and the USE_SSE2 define from the new xsimd targets on non-x86 builds; the runtime dispatcher never enables those paths on ARM. - Define fdopen=fdopen on the zlib and die targets on macOS: the vendored pre-1.2.12 zlib treats TARGET_OS_MAC (predefined by recent Apple clang) as Mac OS Classic and #defines fdopen to NULL, which breaks the SDK stdio headers. - Add -Wno-register for XArchive Algos sources that still use the C++17-removed register keyword. - Patch xdeflatedecoder.cpp via FetchContent PATCH_COMMAND to #undef its zlib-style `local` macro before including Qt headers, which on macOS reach CoreFoundation's CFMessagePort.h where `local` is a parameter name. Co-Authored-By: Claude Fable 5 --- .dielib_commit | 2 +- cmake/FindDieLibrary.cmake | 43 +++++++++++++++++++++++++++++++++++++ cmake/PatchDieLibrary.cmake | 20 +++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 cmake/PatchDieLibrary.cmake diff --git a/.dielib_commit b/.dielib_commit index 9f0f455..9ffe4c4 100644 --- a/.dielib_commit +++ b/.dielib_commit @@ -1 +1 @@ -09df9ccafe48a0531987ad1e605402ed79d4c3f6 \ No newline at end of file +da15bca4474d30107ba4e6b20a268b05bbc13f81 diff --git a/cmake/FindDieLibrary.cmake b/cmake/FindDieLibrary.cmake index 47ba0b2..c06b76f 100644 --- a/cmake/FindDieLibrary.cmake +++ b/cmake/FindDieLibrary.cmake @@ -63,6 +63,10 @@ list(INSERT CMAKE_MODULE_PATH 0 ${Qt6_DIR} ) +# Ensure the bundled Qt wins over any system-wide Qt (e.g. Homebrew) when Qt +# config files resolve their own dependencies (Qt6CoreTools, etc.) +list(INSERT CMAKE_PREFIX_PATH 0 "${ROOT_DIR}/build/${QT_BUILD_VERSION}/${QT_BUILD_COMPILER}") + find_package(Qt6 REQUIRED COMPONENTS Core Qml Concurrent) file(STRINGS "${ROOT_DIR}/.dielib_commit" DIE_LIBRARY_GIT_TAG) @@ -71,11 +75,50 @@ FetchContent_Declare( DieLibrary GIT_REPOSITORY "https://github.com/horsicq/die_library" GIT_TAG "${DIE_LIBRARY_GIT_TAG}" + PATCH_COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_LIST_DIR}/PatchDieLibrary.cmake" ) set(DIE_BUILD_AS_STATIC ON CACHE INTERNAL "") FetchContent_MakeAvailable( DieLibrary ) +# The xsimd component of Formats unconditionally adds x86 SIMD flags +# (-msse/-mavx2) and the USE_SSE2 define under GCC/Clang, which breaks +# non-x86 targets. The runtime dispatcher in xsimd.c never enables SSE2/AVX2 +# on non-x86 CPUs, so dropping them is safe (functions fall back to -1 / +# "not available"). +# The zlib vendored by XArchive predates zlib 1.2.12: its zutil.h treats +# TARGET_OS_MAC (predefined by recent Apple clang) as Mac OS Classic and +# #defines fdopen to NULL, breaking the macOS SDK's stdio. Pre-defining +# fdopen as a self-referencing macro skips that branch (guarded by #ifndef). +if(APPLE) + foreach(XARCHIVE_CONSUMER zlib die) + if(TARGET ${XARCHIVE_CONSUMER}) + target_compile_definitions(${XARCHIVE_CONSUMER} PRIVATE "fdopen=fdopen") + endif() + endforeach() + if(TARGET die) + # XArchive's Algos sources still use the C++17-removed `register` keyword + target_compile_options(die PRIVATE -Wno-register) + endif() +endif() + +if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|AMD64|i.86)") + foreach(XSIMD_TARGET xsimd_sse2 xsimd_avx2) + if(TARGET ${XSIMD_TARGET}) + get_target_property(XSIMD_OPTS ${XSIMD_TARGET} COMPILE_OPTIONS) + if(XSIMD_OPTS) + list(REMOVE_ITEM XSIMD_OPTS -msse -msse2 -mavx -mavx2) + set_target_properties(${XSIMD_TARGET} PROPERTIES COMPILE_OPTIONS "${XSIMD_OPTS}") + endif() + get_target_property(XSIMD_DEFS ${XSIMD_TARGET} COMPILE_DEFINITIONS) + if(XSIMD_DEFS) + list(REMOVE_ITEM XSIMD_DEFS USE_SSE2) + set_target_properties(${XSIMD_TARGET} PROPERTIES COMPILE_DEFINITIONS "${XSIMD_DEFS}") + endif() + endif() + endforeach() +endif() + message(STATUS "Using DieLibrary in '${dielibrary_SOURCE_DIR}'") list(APPEND CMAKE_MODULE_PATH "${dielibrary_SOURCE_DIR}/dep/build_tools/cmake") diff --git a/cmake/PatchDieLibrary.cmake b/cmake/PatchDieLibrary.cmake new file mode 100644 index 0000000..96c6af5 --- /dev/null +++ b/cmake/PatchDieLibrary.cmake @@ -0,0 +1,20 @@ +# Post-fetch fixups for die_library sources, run as FetchContent PATCH_COMMAND +# from the die_library source directory. Must stay idempotent: the command can +# run again on re-population. + +# XArchive's xdeflatedecoder.cpp defines the zlib-style `local` macro +# (`#define local static`) and later includes Qt headers that, on macOS, pull +# in CoreFoundation's CFMessagePort.h which uses `local` as a parameter name. +# Undefine the macro before those includes; nothing below them uses it. +set(XDEFLATE "dep/XArchive/Algos/xdeflatedecoder.cpp") +if(EXISTS "${XDEFLATE}") + file(READ "${XDEFLATE}" CONTENT) + if(NOT CONTENT MATCHES "#undef local") + string(REPLACE + "#include \"xdeflatedecoder.h\"" + "#undef local\n#include \"xdeflatedecoder.h\"" + CONTENT "${CONTENT}") + file(WRITE "${XDEFLATE}" "${CONTENT}") + message(STATUS "Patched ${XDEFLATE}: #undef local before includes") + endif() +endif()