From 87c94464b18d2176c4abb874f85e077ee5ac20ab Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sat, 25 Oct 2025 22:06:34 +0200 Subject: [PATCH 01/13] fix(zlib): Remove legacy Mac fdopen workaround Remove obsolete compiler-specific code for Metrowerks CodeWarrior that was used back in 90s. The removed workarounds for fdopen() and inclusion are no longer needed as modern macOS (pre OS X) provides standard POSIX support. Signed-off-by: Panagiotis Georgiadis --- patches/zlib.patch | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/patches/zlib.patch b/patches/zlib.patch index 7d1657d..cecdb32 100644 --- a/patches/zlib.patch +++ b/patches/zlib.patch @@ -1,5 +1,3 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index b412dc7..7e847ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ @@ -8,29 +6,18 @@ index b412dc7..7e847ee 100644 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) project(zlib C) -@@ -189,25 +189,3 @@ endif() - if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) - install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") - endif() -- --#============================================================================ --# Example binaries --#============================================================================ -- --add_executable(example test/example.c) --target_link_libraries(example zlib) --add_test(example example) -- --add_executable(minigzip test/minigzip.c) --target_link_libraries(minigzip zlib) -- --if(HAVE_OFF64_T) -- add_executable(example64 test/example.c) -- target_link_libraries(example64 zlib) -- set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") -- add_test(example64 example64) -- -- add_executable(minigzip64 test/minigzip.c) -- target_link_libraries(minigzip64 zlib) -- set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") --endif() +--- a/zutil.h ++++ b/zutil.h +@@ -140,12 +140,3 @@ + #if defined(MACOS) || defined(TARGET_OS_MAC) + # define OS_CODE 7 +-# ifndef Z_SOLO +-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +-# include /* for fdopen */ +-# else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif +-# endif +-# endif + #endif From 381d12aad7f9bf5f56db0062e149cf18ecc449ef Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sat, 25 Oct 2025 23:05:25 +0200 Subject: [PATCH 02/13] Fix ARM64 macOS support with conditional config file updates Resolves "invalid host type" errors during libelf configuration by ensuring autotools recognizes aarch64-apple-darwin triple. The solution is platform-specific to avoid unnecessary changes on working systems and includes robust error handling. Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 12 +++++++++++ cmake/update_config_files.sh | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 cmake/update_config_files.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a1072b..55fb369 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL_HASH ${LIBELF_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/libelf.patch + COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND autoreconf -i COMMAND CC=${cc_compiler} RANLIB=${ranlib} ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -198,6 +199,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL http://pyyaml.org/download/libyaml/yaml-${LIBYAML_VERSION}.tar.gz URL_HASH ${LIBYAML_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh /config CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -212,6 +214,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL http://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2 URL_HASH ${GMP_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND CPPFLAGS=-fexceptions ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -227,6 +230,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.bz2 URL_HASH ${MPFR_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh /build-aux CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -241,6 +245,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz URL_HASH ${MPC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh /build-aux CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -257,6 +262,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi GIT_REPOSITORY https://github.com/Meinersbur/isl GIT_TAG isl-${ISL_VERSION} DOWNLOAD_DIR ${DOWNLOAD_DIR} + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND cd && ./autogen.sh COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -270,6 +276,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL https://github.com/libexpat/libexpat/releases/download/R_2_3_0/expat-${EXPAT_VERSION}.tar.bz2 URL_HASH ${EXPAT_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh /conftools CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -301,6 +308,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0001-vita.patch && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0002-fix-broken-reloc.patch && patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0003-fix-elf-vaddr.patch + && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -323,6 +331,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL_HASH ${GDB_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb.patch + && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -463,6 +472,7 @@ ExternalProject_add(gcc-base URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch + && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} # compile a native compiler so keep host == build @@ -561,6 +571,7 @@ if(CMAKE_TOOLCHAIN_FILE) URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch + && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${toolchain_tools} ${wrapper_command} /configure --build=${build_native} @@ -617,6 +628,7 @@ ExternalProject_add(gcc-final URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch + && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${toolchain_tools} ${compiler_target_tools} ${wrapper_command} /configure --build=${build_native} diff --git a/cmake/update_config_files.sh b/cmake/update_config_files.sh new file mode 100755 index 0000000..137f460 --- /dev/null +++ b/cmake/update_config_files.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Update config.sub and config.guess for ARM64 support + +SOURCE_DIR=$1 + +if [ -z "$SOURCE_DIR" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Only update on ARM64 macOS - other platforms work fine with existing config files +ARCH=$(uname -m) +OS=$(uname -s) + +if [ "$OS" != "Darwin" ] || [ "$ARCH" != "arm64" ]; then + echo "Skipping config files update (not ARM64 Mac)" + exit 0 +fi + +echo "Updating config.sub and config.guess in $SOURCE_DIR for ARM64 Mac support" + +# Try to download latest config.sub +if ! curl -L -o "$SOURCE_DIR/config.sub" \ + 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'; then + echo "Warning: Failed to download config.sub, build might fail on ARM64 Mac" +fi + +# Try to download latest config.guess +if ! curl -L -o "$SOURCE_DIR/config.guess" \ + 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'; then + echo "Warning: Failed to download config.guess, build might fail on ARM64 Mac" +fi + +# Make them executable if they exist +[ -f "$SOURCE_DIR/config.sub" ] && chmod +x "$SOURCE_DIR/config.sub" +[ -f "$SOURCE_DIR/config.guess" ] && chmod +x "$SOURCE_DIR/config.guess" + +echo "Config files update completed" +exit 0 + From 85ef30410e83e148fff6fa0dc530e28282591ba5 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sat, 25 Oct 2025 23:52:27 +0200 Subject: [PATCH 03/13] Fix GMP compilation on Apple Silicon by disabling assembly Conditionally disable GMP assembly optimizations on ARM64 macOS to resolve build failures due to incompatible x86 assembly code. GMP's platform-specific assembly doesn't support ARM64, so we fall back to the portable C implementation on Apple Silicon M while maintaining assembly optimizations on other platforms. Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55fb369..bb08118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -210,6 +210,13 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi "CFLAGS=-DYAML_DECLARE_STATIC" ) + # GMP assembly doesn't work on ARM64 macOS - need to disable it + if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64") + set(gmp_asm_flag --disable-assembly) + else() + set(gmp_asm_flag "") + endif() + ExternalProject_add(gmp${suffix} URL http://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2 URL_HASH ${GMP_HASH} @@ -222,6 +229,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi --libdir=${toolchain_deps_dir}/lib --enable-cxx --disable-shared + ${gmp_asm_flag} BUILD_COMMAND ${compiler_flags} ${wrapper_command} $(MAKE) ) From 03cea059e262f0bb987b6485d4aaa9c1c36c769e Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sun, 26 Oct 2025 00:09:45 +0200 Subject: [PATCH 04/13] Fix ARM64 macOS support for MPFR Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb08118..98ad706 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,7 +238,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.bz2 URL_HASH ${MPFR_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} - PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh /build-aux + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} @@ -253,7 +253,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz URL_HASH ${MPC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} - PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh /build-aux + PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} From 68d1fcacc8c68c09245bd6ff75f68ed69f134187 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sun, 26 Oct 2025 00:32:57 +0200 Subject: [PATCH 05/13] Fix permission error in new config.{sub,guess} Signed-off-by: Panagiotis Georgiadis --- cmake/update_config_files.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/update_config_files.sh b/cmake/update_config_files.sh index 137f460..5aa1491 100755 --- a/cmake/update_config_files.sh +++ b/cmake/update_config_files.sh @@ -19,6 +19,10 @@ fi echo "Updating config.sub and config.guess in $SOURCE_DIR for ARM64 Mac support" +# Remove old files if they exist and are read-only +[ -f "$SOURCE_DIR/config.sub" ] && chmod +w "$SOURCE_DIR/config.sub" 2>/dev/null +[ -f "$SOURCE_DIR/config.guess" ] && chmod +w "$SOURCE_DIR/config.guess" 2>/dev/null + # Try to download latest config.sub if ! curl -L -o "$SOURCE_DIR/config.sub" \ 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'; then From 50a3dc9b736a8ecaf037e8ad8e9ef0ceed22157b Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sun, 26 Oct 2025 03:08:39 +0100 Subject: [PATCH 06/13] fix binutils patch fdopen conflict Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 1 + .../binutils/0004-fix-zlib-fdopen-macos.patch | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 patches/binutils/0004-fix-zlib-fdopen-macos.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 98ad706..51659d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -316,6 +316,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0001-vita.patch && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0002-fix-broken-reloc.patch && patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0003-fix-elf-vaddr.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0004-fix-zlib-fdopen-macos.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} diff --git a/patches/binutils/0004-fix-zlib-fdopen-macos.patch b/patches/binutils/0004-fix-zlib-fdopen-macos.patch new file mode 100644 index 0000000..6730014 --- /dev/null +++ b/patches/binutils/0004-fix-zlib-fdopen-macos.patch @@ -0,0 +1,16 @@ +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -140,12 +140,3 @@ + #if defined(MACOS) || defined(TARGET_OS_MAC) + # define OS_CODE 7 +-# ifndef Z_SOLO +-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +-# include /* for fdopen */ +-# else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif +-# endif +-# endif + #endif + From 6a13fa72c4247c3e8fe70cce197071cf0bafd3c1 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sun, 26 Oct 2025 10:00:31 +0100 Subject: [PATCH 07/13] Fix GCC 10.3.0 build on ARM64 macOS - Fix zlib fdopen macro conflict with macOS headers - Wrap safe-ctype.h macros in #ifndef __cplusplus to avoid C++ std library conflicts - Remove -no-pie flags from configure scripts - Add aarch64-darwin to config.host for host-darwin.o compilation - Remove zlib .dylib files to force static linking Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 7 ++- cmake/fix_gcc_arm64_macos.sh | 86 ++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100755 cmake/fix_gcc_arm64_macos.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 51659d7..6c40264 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,9 +148,11 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi ExternalProject_Add_Step(zlib${suffix} delete_shared DEPENDEES install - COMMAND ${CMAKE_COMMAND} -E remove + COMMAND ${CMAKE_COMMAND} -E remove -f ${toolchain_deps_dir}/lib/libz.so ${toolchain_deps_dir}/lib/libz.so.1 + ${toolchain_deps_dir}/lib/libz.dylib + ${toolchain_deps_dir}/lib/libz.*.dylib COMMENT "Delete shared libraries, if present" ) endif() @@ -482,6 +484,7 @@ ExternalProject_add(gcc-base DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh + && sh ${PROJECT_SOURCE_DIR}/cmake/fix_gcc_arm64_macos.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} # compile a native compiler so keep host == build @@ -581,6 +584,7 @@ if(CMAKE_TOOLCHAIN_FILE) DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh + && sh ${PROJECT_SOURCE_DIR}/cmake/fix_gcc_arm64_macos.sh CONFIGURE_COMMAND ${compiler_flags} ${toolchain_tools} ${wrapper_command} /configure --build=${build_native} @@ -638,6 +642,7 @@ ExternalProject_add(gcc-final DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh + && sh ${PROJECT_SOURCE_DIR}/cmake/fix_gcc_arm64_macos.sh CONFIGURE_COMMAND ${compiler_flags} ${toolchain_tools} ${compiler_target_tools} ${wrapper_command} /configure --build=${build_native} diff --git a/cmake/fix_gcc_arm64_macos.sh b/cmake/fix_gcc_arm64_macos.sh new file mode 100755 index 0000000..b6ef52c --- /dev/null +++ b/cmake/fix_gcc_arm64_macos.sh @@ -0,0 +1,86 @@ +#!/bin/sh +# Fix GCC build issues on macOS (especially ARM64) + +SOURCE_DIR=$1 + +if [ -z "$SOURCE_DIR" ]; then + echo "Usage: $0 " + exit 1 +fi + +ARCH=$(uname -m) +OS=$(uname -s) + +if [ "$OS" != "Darwin" ]; then + echo "Skipping GCC macOS fixes (not macOS)" + exit 0 +fi + +echo "Applying GCC macOS fixes in $SOURCE_DIR" + +# Fix 1: Fix zlib fdopen macro conflict on macOS (affects all macOS) +echo "Fixing zlib fdopen macro for macOS..." +if [ -f "$SOURCE_DIR/zlib/zutil.h" ]; then + # Apply zlib fdopen fix as a patch + cat > /tmp/zlib_fdopen_fix.patch << 'EOF' +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -133,12 +133,3 @@ + #if defined(MACOS) || defined(TARGET_OS_MAC) + # define OS_CODE 7 +-# ifndef Z_SOLO +-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +-# include /* for fdopen */ +-# else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif +-# endif +-# endif + #endif +EOF + patch -d "$SOURCE_DIR" -p1 -t -N < /tmp/zlib_fdopen_fix.patch || echo "Warning: zlib fdopen patch may have already been applied" + rm -f /tmp/zlib_fdopen_fix.patch +fi + +# ARM64-specific fixes +if [ "$ARCH" = "arm64" ]; then + echo "Applying ARM64-specific fixes..." + + # Fix 2: Fix safe-ctype.h conflicts with C++ standard library headers + echo "Fixing safe-ctype.h conflicts with C++ headers..." + if [ -f "$SOURCE_DIR/include/safe-ctype.h" ]; then + # Wrap the macro redefinitions in #ifndef __cplusplus + # Add #ifndef __cplusplus before the #undef isalpha line + sed -i '' '/^#undef isalpha$/i\ +#ifndef __cplusplus +' "$SOURCE_DIR/include/safe-ctype.h" + + # Add #endif before the final #endif /* SAFE_CTYPE_H */ + sed -i '' '/^#endif \/\* SAFE_CTYPE_H \*\/$/i\ +#endif /* __cplusplus */ +' "$SOURCE_DIR/include/safe-ctype.h" + fi + + # Fix 3: Remove -no-pie flags that cause issues on macOS ARM64 + echo "Removing -no-pie flags from configure scripts..." + find "$SOURCE_DIR" -name "configure" -type f -exec sed -i '' 's/-no-pie//g' {} + + + # Fix 4: Ensure host-darwin.c is compiled for ARM64 + echo "Checking host-darwin configuration..." + if [ -f "$SOURCE_DIR/gcc/config.host" ]; then + # First, remove any broken aarch64-darwin line from previous attempts + sed -i '' '/^ aarch64-\*-darwin\* | arm64-\*-darwin\*)$/d' "$SOURCE_DIR/gcc/config.host" + + # Now add aarch64-darwin to the x86_64-darwin case if not already there + if ! grep "i\[34567\]86-\*-darwin\* | x86_64-\*-darwin\*.*aarch64" "$SOURCE_DIR/gcc/config.host" > /dev/null 2>&1; then + echo "Adding aarch64-darwin to x86_64-darwin case..." + # Add aarch64 to the existing x86_64-darwin pattern + sed -i '' 's/i\[34567\]86-\*-darwin\* | x86_64-\*-darwin\*)/i[34567]86-*-darwin* | x86_64-*-darwin* | aarch64-*-darwin* | arm64-*-darwin*)/' "$SOURCE_DIR/gcc/config.host" + fi + fi +fi + +echo "GCC ARM64 macOS fixes applied" +exit 0 + From c3b74e57d31d300ca9da46b75ae06167b9d575e6 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sun, 26 Oct 2025 10:21:03 +0100 Subject: [PATCH 08/13] Use patch; not script Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 6 +- cmake/fix_gcc_arm64_macos.sh | 86 -------------------------- patches/gcc/0002-fix-macos-arm64.patch | 46 ++++++++++++++ 3 files changed, 49 insertions(+), 89 deletions(-) delete mode 100755 cmake/fix_gcc_arm64_macos.sh create mode 100644 patches/gcc/0002-fix-macos-arm64.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c40264..a0bc025 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -483,8 +483,8 @@ ExternalProject_add(gcc-base URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0002-fix-macos-arm64.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh - && sh ${PROJECT_SOURCE_DIR}/cmake/fix_gcc_arm64_macos.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} # compile a native compiler so keep host == build @@ -583,8 +583,8 @@ if(CMAKE_TOOLCHAIN_FILE) URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0002-fix-macos-arm64.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh - && sh ${PROJECT_SOURCE_DIR}/cmake/fix_gcc_arm64_macos.sh CONFIGURE_COMMAND ${compiler_flags} ${toolchain_tools} ${wrapper_command} /configure --build=${build_native} @@ -641,8 +641,8 @@ ExternalProject_add(gcc-final URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0002-fix-macos-arm64.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh - && sh ${PROJECT_SOURCE_DIR}/cmake/fix_gcc_arm64_macos.sh CONFIGURE_COMMAND ${compiler_flags} ${toolchain_tools} ${compiler_target_tools} ${wrapper_command} /configure --build=${build_native} diff --git a/cmake/fix_gcc_arm64_macos.sh b/cmake/fix_gcc_arm64_macos.sh deleted file mode 100755 index b6ef52c..0000000 --- a/cmake/fix_gcc_arm64_macos.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/sh -# Fix GCC build issues on macOS (especially ARM64) - -SOURCE_DIR=$1 - -if [ -z "$SOURCE_DIR" ]; then - echo "Usage: $0 " - exit 1 -fi - -ARCH=$(uname -m) -OS=$(uname -s) - -if [ "$OS" != "Darwin" ]; then - echo "Skipping GCC macOS fixes (not macOS)" - exit 0 -fi - -echo "Applying GCC macOS fixes in $SOURCE_DIR" - -# Fix 1: Fix zlib fdopen macro conflict on macOS (affects all macOS) -echo "Fixing zlib fdopen macro for macOS..." -if [ -f "$SOURCE_DIR/zlib/zutil.h" ]; then - # Apply zlib fdopen fix as a patch - cat > /tmp/zlib_fdopen_fix.patch << 'EOF' ---- a/zlib/zutil.h -+++ b/zlib/zutil.h -@@ -133,12 +133,3 @@ - #if defined(MACOS) || defined(TARGET_OS_MAC) - # define OS_CODE 7 --# ifndef Z_SOLO --# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os --# include /* for fdopen */ --# else --# ifndef fdopen --# define fdopen(fd,mode) NULL /* No fdopen() */ --# endif --# endif --# endif - #endif -EOF - patch -d "$SOURCE_DIR" -p1 -t -N < /tmp/zlib_fdopen_fix.patch || echo "Warning: zlib fdopen patch may have already been applied" - rm -f /tmp/zlib_fdopen_fix.patch -fi - -# ARM64-specific fixes -if [ "$ARCH" = "arm64" ]; then - echo "Applying ARM64-specific fixes..." - - # Fix 2: Fix safe-ctype.h conflicts with C++ standard library headers - echo "Fixing safe-ctype.h conflicts with C++ headers..." - if [ -f "$SOURCE_DIR/include/safe-ctype.h" ]; then - # Wrap the macro redefinitions in #ifndef __cplusplus - # Add #ifndef __cplusplus before the #undef isalpha line - sed -i '' '/^#undef isalpha$/i\ -#ifndef __cplusplus -' "$SOURCE_DIR/include/safe-ctype.h" - - # Add #endif before the final #endif /* SAFE_CTYPE_H */ - sed -i '' '/^#endif \/\* SAFE_CTYPE_H \*\/$/i\ -#endif /* __cplusplus */ -' "$SOURCE_DIR/include/safe-ctype.h" - fi - - # Fix 3: Remove -no-pie flags that cause issues on macOS ARM64 - echo "Removing -no-pie flags from configure scripts..." - find "$SOURCE_DIR" -name "configure" -type f -exec sed -i '' 's/-no-pie//g' {} + - - # Fix 4: Ensure host-darwin.c is compiled for ARM64 - echo "Checking host-darwin configuration..." - if [ -f "$SOURCE_DIR/gcc/config.host" ]; then - # First, remove any broken aarch64-darwin line from previous attempts - sed -i '' '/^ aarch64-\*-darwin\* | arm64-\*-darwin\*)$/d' "$SOURCE_DIR/gcc/config.host" - - # Now add aarch64-darwin to the x86_64-darwin case if not already there - if ! grep "i\[34567\]86-\*-darwin\* | x86_64-\*-darwin\*.*aarch64" "$SOURCE_DIR/gcc/config.host" > /dev/null 2>&1; then - echo "Adding aarch64-darwin to x86_64-darwin case..." - # Add aarch64 to the existing x86_64-darwin pattern - sed -i '' 's/i\[34567\]86-\*-darwin\* | x86_64-\*-darwin\*)/i[34567]86-*-darwin* | x86_64-*-darwin* | aarch64-*-darwin* | arm64-*-darwin*)/' "$SOURCE_DIR/gcc/config.host" - fi - fi -fi - -echo "GCC ARM64 macOS fixes applied" -exit 0 - diff --git a/patches/gcc/0002-fix-macos-arm64.patch b/patches/gcc/0002-fix-macos-arm64.patch new file mode 100644 index 0000000..7989641 --- /dev/null +++ b/patches/gcc/0002-fix-macos-arm64.patch @@ -0,0 +1,46 @@ +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -132,15 +132,6 @@ + + #if defined(MACOS) || defined(TARGET_OS_MAC) + # define OS_CODE 7 +-# ifndef Z_SOLO +-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +-# include /* for fdopen */ +-# else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif +-# endif +-# endif + #endif + + #ifdef __acorn +--- a/include/safe-ctype.h ++++ b/include/safe-ctype.h +@@ -120,6 +120,7 @@ + So we include ctype.h here and then immediately redefine its macros. */ + + #include ++#ifndef __cplusplus + #undef isalpha + #define isalpha(c) do_not_use_isalpha_with_safe_ctype + #undef isalnum +@@ -147,4 +148,5 @@ + #undef tolower + #define tolower(c) do_not_use_tolower_with_safe_ctype + ++#endif /* __cplusplus */ + #endif /* SAFE_CTYPE_H */ +--- a/gcc/config.host ++++ b/gcc/config.host +@@ -251,7 +251,7 @@ + host_extra_gcc_objs="${host_extra_gcc_objs} driver-mingw32.o" + host_lto_plugin_soname=liblto_plugin-0.dll + ;; +- i[34567]86-*-darwin* | x86_64-*-darwin*) ++ i[34567]86-*-darwin* | x86_64-*-darwin* | aarch64-*-darwin* | arm64-*-darwin*) + out_host_hook_obj="${out_host_hook_obj} host-i386-darwin.o" + host_xmake_file="${host_xmake_file} i386/x-darwin" + ;; + From f48f0ab877aeaa0c72a2874128659a0ae9e85036 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sun, 26 Oct 2025 11:09:17 +0100 Subject: [PATCH 09/13] Reset libzip git repo before patching to avoid reapplication conflicts libzip is git-cloned, and patch modifies files causing conflicts on rebuild. Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0bc025..efc0165 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,7 +175,8 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi GIT_REPOSITORY https://github.com/vitasdk/libzip GIT_TAG ${LIBZIP_TAG} ${GIT_SHALLOW_SUPPORT} - PATCH_COMMAND patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/libzip.patch + PATCH_COMMAND git -C reset --hard HEAD && git -C clean -fd + COMMAND patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/libzip.patch CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${toolchain_deps_dir} ${toolchain_cmake_args} ${libzip_configure} -DZLIB_INCLUDE_DIR=${toolchain_deps_dir}/include From f09b66d1c59a972b10ee44f205e1402e188565f4 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Sun, 26 Oct 2025 13:39:59 +0100 Subject: [PATCH 10/13] Fix gdb Signed-off-by: Panagiotis Georgiadis --- CMakeLists.txt | 2 ++ patches/gdb-enum-fix.patch | 24 ++++++++++++++++++++++++ patches/gdb-zlib-fdopen-macos.patch | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 patches/gdb-enum-fix.patch create mode 100644 patches/gdb-zlib-fdopen-macos.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index efc0165..0f3c792 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,6 +343,8 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL_HASH ${GDB_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb-zlib-fdopen-macos.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb-enum-fix.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} diff --git a/patches/gdb-enum-fix.patch b/patches/gdb-enum-fix.patch new file mode 100644 index 0000000..37e484b --- /dev/null +++ b/patches/gdb-enum-fix.patch @@ -0,0 +1,24 @@ +--- a/gdb/gdbsupport/enum-flags.h ++++ b/gdb/gdbsupport/enum-flags.h +@@ -79,6 +79,10 @@ template<> struct integer_for_size<4, 1> { typedef int32_t type; }; + template<> struct integer_for_size<8, 1> { typedef int64_t type; }; + + template ++#ifdef __clang__ ++#pragma clang diagnostic push ++#pragma clang diagnostic ignored "-Wenum-constexpr-conversion" ++#endif + struct enum_underlying_type + { + typedef typename +@@ -86,6 +90,9 @@ struct enum_underlying_type + type; + }; + ++#ifdef __clang__ ++#pragma clang diagnostic pop ++#endif + template + class enum_flags + { + diff --git a/patches/gdb-zlib-fdopen-macos.patch b/patches/gdb-zlib-fdopen-macos.patch new file mode 100644 index 0000000..c99767b --- /dev/null +++ b/patches/gdb-zlib-fdopen-macos.patch @@ -0,0 +1,19 @@ +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -132,15 +132,6 @@ + + #if defined(MACOS) || defined(TARGET_OS_MAC) + # define OS_CODE 7 +-# ifndef Z_SOLO +-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +-# include /* for fdopen */ +-# else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif +-# endif +-# endif + #endif + + #ifdef __acorn + From 67d84c25450d16b2d7678a1520f93b52c5f16d7e Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Tue, 28 Oct 2025 11:57:14 +0100 Subject: [PATCH 11/13] Add mac-arm64 CI job Signed-off-by: Panagiotis Georgiadis --- .github/workflows/build.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2cfab31..a3b37f1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ name: Build on: push: pull_request: + workflow_dispatch: repository_dispatch: types: [run_build] @@ -75,6 +76,26 @@ jobs: with: name: vitasdk-macos path: build/*.tar.bz2 + build-macos-arm64: + runs-on: macos-14 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - name: Build + run: | + git config --global user.email "builds@travis-ci.com" + git config --global user.name "Travis CI" + brew install autoconf automake libtool texinfo pkg-config + mkdir build + cd build + cmake .. + make -j$(nproc) tarball + - name: Upload artifacts + if: ${{ success() }} + uses: actions/upload-artifact@v4 + with: + name: vitasdk-macos-arm64 + path: build/*.tar.bz2 build-windows: # TODO match as build-linux # we don't know reason yet, mingw build was failed when libelf compille. From cdb0e1953cde35e3af149d523052c2cc2a250190 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Tue, 28 Oct 2025 15:57:01 +0100 Subject: [PATCH 12/13] ci: Fix all the targets - Fix Linux aarch64 - Fix macOS x86_64 by patching GMP to disable assembly optimizations. - Fix macOS arm64 by setting 4 cores instead of all of them (GH hiccup) - Cosmetic changes for the CI Signed-off-by: Panagiotis Georgiadis --- .github/workflows/build.yml | 32 +++++++++++++++++++++----------- CMakeLists.txt | 26 ++++++++++++++------------ cmake/update_config_files.sh | 21 +++++++++++---------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a3b37f1..798a8f7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - name: Install dependencies run: | sudo apt-get update @@ -22,7 +24,7 @@ jobs: run: | git config --global user.email "builds@travis-ci.com" git config --global user.name "Travis CI" - mkdir build + mkdir -p build cd build cmake .. make -j$(nproc) tarball @@ -37,6 +39,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - name: Install dependencies run: | sudo apt-get update @@ -46,7 +50,7 @@ jobs: run: | git config --global user.email "builds@travis-ci.com" git config --global user.name "Travis CI" - mkdir build + mkdir -p build cd build cmake .. make -j$(nproc) tarball @@ -57,19 +61,21 @@ jobs: name: vitasdk-linux-arm64 path: build/*.tar.bz2 build-macos: - runs-on: macos-12 + runs-on: macos-15-intel steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - name: Build run: | git config --global user.email "builds@travis-ci.com" git config --global user.name "Travis CI" - brew install autoconf automake libtool - mkdir build + brew install autoconf automake libtool texinfo + mkdir -p build cd build cmake .. - make -j$(nproc) tarball + make -j4 tarball - name: Upload artifacts if: ${{ success() }} uses: actions/upload-artifact@v4 @@ -77,19 +83,21 @@ jobs: name: vitasdk-macos path: build/*.tar.bz2 build-macos-arm64: - runs-on: macos-14 + runs-on: macos-15 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - name: Build run: | git config --global user.email "builds@travis-ci.com" git config --global user.name "Travis CI" - brew install autoconf automake libtool texinfo pkg-config - mkdir build + brew install autoconf automake libtool texinfo + mkdir -p build cd build cmake .. - make -j$(nproc) tarball + make -j4 tarball - name: Upload artifacts if: ${{ success() }} uses: actions/upload-artifact@v4 @@ -104,6 +112,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 + with: + python-version: '3.x' - name: Install dependencies run: | sudo apt-get update @@ -115,7 +125,7 @@ jobs: git config --global user.name "Travis CI" unset CXX unset CC - mkdir build + mkdir -p build cd build cmake .. -DCMAKE_TOOLCHAIN_FILE=toolchain-x86_64-w64-mingw32.cmake make -j$(nproc) tarball diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f3c792..089486d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,7 +199,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi ) ExternalProject_add(libyaml${suffix} - URL http://pyyaml.org/download/libyaml/yaml-${LIBYAML_VERSION}.tar.gz + URL https://pyyaml.org/download/libyaml/yaml-${LIBYAML_VERSION}.tar.gz URL_HASH ${LIBYAML_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh /config @@ -213,19 +213,21 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi "CFLAGS=-DYAML_DECLARE_STATIC" ) - # GMP assembly doesn't work on ARM64 macOS - need to disable it - if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "arm64") + # GMP assembly causes issues on macOS - need to disable it and use PIC + if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set(gmp_asm_flag --disable-assembly) + set(gmp_env_command ${CMAKE_COMMAND} -E env "CFLAGS=-fPIC -fexceptions" "CXXFLAGS=-fPIC") else() set(gmp_asm_flag "") + set(gmp_env_command ${CMAKE_COMMAND} -E env "CPPFLAGS=-fexceptions") endif() ExternalProject_add(gmp${suffix} - URL http://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2 + URL https://ftpmirror.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.bz2 URL_HASH ${GMP_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh - CONFIGURE_COMMAND CPPFLAGS=-fexceptions ${compiler_flags} ${wrapper_command} /configure + CONFIGURE_COMMAND ${gmp_env_command} ${compiler_flags} ${wrapper_command} /configure --build=${build_native} --host=${toolchain_host} --prefix=${toolchain_deps_dir} @@ -238,7 +240,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi ExternalProject_add(mpfr${suffix} DEPENDS gmp${suffix} - URL http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.bz2 + URL https://ftpmirror.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.bz2 URL_HASH ${MPFR_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh @@ -253,7 +255,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi ExternalProject_add(mpc${suffix} DEPENDS gmp${suffix} mpfr${suffix} - URL https://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz + URL https://ftpmirror.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz URL_HASH ${MPC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh @@ -312,7 +314,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi ) ExternalProject_Add(binutils${suffix} - URL https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz + URL https://ftpmirror.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz URL_HASH ${BINUTILS_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND @@ -339,7 +341,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi ) ExternalProject_Add(gdb${suffix} - URL https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.xz + URL https://ftpmirror.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.xz URL_HASH ${GDB_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb.patch @@ -482,7 +484,7 @@ endif() # Build a basic gcc compiler, needed to compile newlib ExternalProject_add(gcc-base DEPENDS gmp_${build_suffix} mpfr_${build_suffix} mpc_${build_suffix} isl_${build_suffix} libelf_${build_suffix} - URL http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz + URL https://ftpmirror.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch @@ -582,7 +584,7 @@ ExternalProject_Add(newlib if(CMAKE_TOOLCHAIN_FILE) ExternalProject_add(gcc-complete DEPENDS newlib gmp_${build_suffix} mpfr_${build_suffix} mpc_${build_suffix} isl_${build_suffix} libelf_${build_suffix} - URL http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz + URL https://ftpmirror.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch @@ -640,7 +642,7 @@ ExternalProject_Add(pthread-embedded ExternalProject_add(gcc-final DEPENDS gmp_${target_suffix} mpfr_${target_suffix} mpc_${target_suffix} isl_${target_suffix} libelf_${target_suffix} DEPENDS newlib ${GCC_DEPENDS} pthread-embedded - URL http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz + URL https://ftpmirror.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz URL_HASH ${GCC_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gcc/0001-gcc-10.patch diff --git a/cmake/update_config_files.sh b/cmake/update_config_files.sh index 5aa1491..5c5ac3b 100755 --- a/cmake/update_config_files.sh +++ b/cmake/update_config_files.sh @@ -8,31 +8,32 @@ if [ -z "$SOURCE_DIR" ]; then exit 1 fi -# Only update on ARM64 macOS - other platforms work fine with existing config files +# Update on ARM64 platforms (macOS and Linux) - old config files don't recognize aarch64 ARCH=$(uname -m) OS=$(uname -s) -if [ "$OS" != "Darwin" ] || [ "$ARCH" != "arm64" ]; then - echo "Skipping config files update (not ARM64 Mac)" +# Check if we're on ARM64 (macOS uses "arm64", Linux uses "aarch64") +if [ "$ARCH" != "arm64" ] && [ "$ARCH" != "aarch64" ]; then + echo "Skipping config files update (not ARM64 platform: $ARCH)" exit 0 fi -echo "Updating config.sub and config.guess in $SOURCE_DIR for ARM64 Mac support" +echo "Updating config.sub and config.guess in $SOURCE_DIR for ARM64 support ($OS $ARCH)" # Remove old files if they exist and are read-only [ -f "$SOURCE_DIR/config.sub" ] && chmod +w "$SOURCE_DIR/config.sub" 2>/dev/null [ -f "$SOURCE_DIR/config.guess" ] && chmod +w "$SOURCE_DIR/config.guess" 2>/dev/null # Try to download latest config.sub -if ! curl -L -o "$SOURCE_DIR/config.sub" \ - 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'; then - echo "Warning: Failed to download config.sub, build might fail on ARM64 Mac" +if ! curl -f -L -o "$SOURCE_DIR/config.sub" \ + 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub'; then + echo "Warning: Failed to download config.sub, build might fail on ARM64" fi # Try to download latest config.guess -if ! curl -L -o "$SOURCE_DIR/config.guess" \ - 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'; then - echo "Warning: Failed to download config.guess, build might fail on ARM64 Mac" +if ! curl -f -L -o "$SOURCE_DIR/config.guess" \ + 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess'; then + echo "Warning: Failed to download config.guess, build might fail on ARM64" fi # Make them executable if they exist From c0e335e58b1508e17ac6befb6bf5bca96f2bd675 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgiadis Date: Fri, 31 Oct 2025 02:33:10 +0100 Subject: [PATCH 13/13] Consolidation of duplicate code in patches Signed-off-by: Panagiotis Georgiadis --- .github/workflows/build.yml | 10 ++-- CMakeLists.txt | 8 +-- cmake/update_config_files.sh | 52 +++++++++++++++---- .../binutils/0004-fix-zlib-fdopen-macos.patch | 16 ------ patches/common/zlib-fdopen-macos.patch | 29 +++++++++++ patches/gcc/0002-fix-macos-arm64.patch | 12 +++++ patches/gdb-enum-fix.patch | 7 +++ patches/gdb-zlib-fdopen-macos.patch | 19 ------- patches/zlib.patch | 4 ++ 9 files changed, 104 insertions(+), 53 deletions(-) delete mode 100644 patches/binutils/0004-fix-zlib-fdopen-macos.patch create mode 100644 patches/common/zlib-fdopen-macos.patch delete mode 100644 patches/gdb-zlib-fdopen-macos.patch diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 798a8f7..414ca34 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,11 +67,13 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.x' + - name: Install dependencies + run: | + brew install autoconf automake libtool texinfo - name: Build run: | git config --global user.email "builds@travis-ci.com" git config --global user.name "Travis CI" - brew install autoconf automake libtool texinfo mkdir -p build cd build cmake .. @@ -80,7 +82,7 @@ jobs: if: ${{ success() }} uses: actions/upload-artifact@v4 with: - name: vitasdk-macos + name: vitasdk-macos-x86_64 path: build/*.tar.bz2 build-macos-arm64: runs-on: macos-15 @@ -89,11 +91,13 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.x' + - name: Install dependencies + run: | + brew install autoconf automake libtool texinfo - name: Build run: | git config --global user.email "builds@travis-ci.com" git config --global user.name "Travis CI" - brew install autoconf automake libtool texinfo mkdir -p build cd build cmake .. diff --git a/CMakeLists.txt b/CMakeLists.txt index 089486d..2360d59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,10 +216,10 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi # GMP assembly causes issues on macOS - need to disable it and use PIC if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") set(gmp_asm_flag --disable-assembly) - set(gmp_env_command ${CMAKE_COMMAND} -E env "CFLAGS=-fPIC -fexceptions" "CXXFLAGS=-fPIC") + set(gmp_env_command ${CMAKE_COMMAND} -E env "CFLAGS=-fPIC -fexceptions" "CXXFLAGS=-fPIC -fexceptions") else() set(gmp_asm_flag "") - set(gmp_env_command ${CMAKE_COMMAND} -E env "CPPFLAGS=-fexceptions") + set(gmp_env_command ${CMAKE_COMMAND} -E env "CFLAGS=-fexceptions" "CXXFLAGS=-fexceptions") endif() ExternalProject_add(gmp${suffix} @@ -321,7 +321,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0001-vita.patch && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0002-fix-broken-reloc.patch && patch -d -p3 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0003-fix-elf-vaddr.patch - && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/binutils/0004-fix-zlib-fdopen-macos.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/common/zlib-fdopen-macos.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure --build=${build_native} @@ -345,7 +345,7 @@ function(toolchain_deps toolchain_deps_dir toolchain_install_dir toolchain_suffi URL_HASH ${GDB_HASH} DOWNLOAD_DIR ${DOWNLOAD_DIR} PATCH_COMMAND patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb.patch - && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb-zlib-fdopen-macos.patch + && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/common/zlib-fdopen-macos.patch && patch -d -p1 -t -N < ${PROJECT_SOURCE_DIR}/patches/gdb-enum-fix.patch && sh ${PROJECT_SOURCE_DIR}/cmake/update_config_files.sh CONFIGURE_COMMAND ${compiler_flags} ${wrapper_command} /configure diff --git a/cmake/update_config_files.sh b/cmake/update_config_files.sh index 5c5ac3b..7f646bd 100755 --- a/cmake/update_config_files.sh +++ b/cmake/update_config_files.sh @@ -1,10 +1,17 @@ #!/bin/sh # Update config.sub and config.guess for ARM64 support +set -e SOURCE_DIR=$1 if [ -z "$SOURCE_DIR" ]; then - echo "Usage: $0 " + echo "Error: No source directory provided" >&2 + echo "Usage: $0 " >&2 + exit 1 +fi + +if [ ! -d "$SOURCE_DIR" ]; then + echo "Error: Source directory does not exist: $SOURCE_DIR" >&2 exit 1 fi @@ -20,25 +27,48 @@ fi echo "Updating config.sub and config.guess in $SOURCE_DIR for ARM64 support ($OS $ARCH)" +# Check if curl is available +if ! command -v curl >/dev/null 2>&1; then + echo "Error: curl command not found. Cannot download config files." >&2 + echo " Please install curl or manually update config.sub and config.guess" >&2 + exit 1 +fi + # Remove old files if they exist and are read-only [ -f "$SOURCE_DIR/config.sub" ] && chmod +w "$SOURCE_DIR/config.sub" 2>/dev/null [ -f "$SOURCE_DIR/config.guess" ] && chmod +w "$SOURCE_DIR/config.guess" 2>/dev/null -# Try to download latest config.sub -if ! curl -f -L -o "$SOURCE_DIR/config.sub" \ - 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub'; then - echo "Warning: Failed to download config.sub, build might fail on ARM64" +# Download latest config files from GNU config repository +CONFIG_BASE_URL='https://git.savannah.gnu.org/cgit/config.git/plain' + +# Try to download latest config.sub with timeout and retries +if ! curl -f -s -S -L --connect-timeout 30 --max-time 60 --retry 3 \ + -o "$SOURCE_DIR/config.sub" "$CONFIG_BASE_URL/config.sub"; then + echo "Warning: Failed to download config.sub from $CONFIG_BASE_URL/config.sub" >&2 + echo " Build might fail on ARM64 if config.sub doesn't support aarch64" >&2 +else + echo "Successfully downloaded config.sub" fi -# Try to download latest config.guess -if ! curl -f -L -o "$SOURCE_DIR/config.guess" \ - 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess'; then - echo "Warning: Failed to download config.guess, build might fail on ARM64" +# Try to download latest config.guess with timeout and retries +if ! curl -f -s -S -L --connect-timeout 30 --max-time 60 --retry 3 \ + -o "$SOURCE_DIR/config.guess" "$CONFIG_BASE_URL/config.guess"; then + echo "Warning: Failed to download config.guess from $CONFIG_BASE_URL/config.guess" >&2 + echo " Build might fail on ARM64 if config.guess doesn't recognize this platform" >&2 +else + echo "Successfully downloaded config.guess" fi # Make them executable if they exist -[ -f "$SOURCE_DIR/config.sub" ] && chmod +x "$SOURCE_DIR/config.sub" -[ -f "$SOURCE_DIR/config.guess" ] && chmod +x "$SOURCE_DIR/config.guess" +if [ -f "$SOURCE_DIR/config.sub" ]; then + chmod +x "$SOURCE_DIR/config.sub" + echo "Made config.sub executable" +fi + +if [ -f "$SOURCE_DIR/config.guess" ]; then + chmod +x "$SOURCE_DIR/config.guess" + echo "Made config.guess executable" +fi echo "Config files update completed" exit 0 diff --git a/patches/binutils/0004-fix-zlib-fdopen-macos.patch b/patches/binutils/0004-fix-zlib-fdopen-macos.patch deleted file mode 100644 index 6730014..0000000 --- a/patches/binutils/0004-fix-zlib-fdopen-macos.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- a/zlib/zutil.h -+++ b/zlib/zutil.h -@@ -140,12 +140,3 @@ - #if defined(MACOS) || defined(TARGET_OS_MAC) - # define OS_CODE 7 --# ifndef Z_SOLO --# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os --# include /* for fdopen */ --# else --# ifndef fdopen --# define fdopen(fd,mode) NULL /* No fdopen() */ --# endif --# endif --# endif - #endif - diff --git a/patches/common/zlib-fdopen-macos.patch b/patches/common/zlib-fdopen-macos.patch new file mode 100644 index 0000000..6dfc0f6 --- /dev/null +++ b/patches/common/zlib-fdopen-macos.patch @@ -0,0 +1,29 @@ +Remove obsolete Metrowerks CodeWarrior fdopen workaround from zlib + +This patch removes legacy code for the Metrowerks CodeWarrior compiler from the 1990s. +The code was attempting to work around missing or incompatible fdopen() implementations +on pre-macOS systems. Modern macOS (since OS X) provides standard POSIX fdopen() support, +making this workaround unnecessary and actually problematic as it can conflict with +system headers. + +This fix is needed for binutils, GDB, and GCC which all bundle their own copy of zlib. + +--- a/zlib/zutil.h ++++ b/zlib/zutil.h +@@ -132,15 +132,6 @@ + + #if defined(MACOS) || defined(TARGET_OS_MAC) + # define OS_CODE 7 +-# ifndef Z_SOLO +-# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os +-# include /* for fdopen */ +-# else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif +-# endif +-# endif + #endif + + #ifdef __acorn + diff --git a/patches/gcc/0002-fix-macos-arm64.patch b/patches/gcc/0002-fix-macos-arm64.patch index 7989641..4ef2dda 100644 --- a/patches/gcc/0002-fix-macos-arm64.patch +++ b/patches/gcc/0002-fix-macos-arm64.patch @@ -1,3 +1,15 @@ +GCC 10.3.0 fixes for macOS (especially ARM64/Apple Silicon) + +This patch addresses several issues preventing GCC 10.3.0 from building on macOS: + +1. Remove obsolete zlib fdopen workaround (see common/zlib-fdopen-macos.patch) +2. Wrap safe-ctype.h macro redefinitions in #ifndef __cplusplus to prevent + conflicts with C++ standard library headers +3. Add aarch64-darwin and arm64-darwin to config.host so host-darwin.o is + compiled for ARM64 macOS builds + +These fixes are necessary for both x86_64 and ARM64 macOS builds. + --- a/zlib/zutil.h +++ b/zlib/zutil.h @@ -132,15 +132,6 @@ diff --git a/patches/gdb-enum-fix.patch b/patches/gdb-enum-fix.patch index 37e484b..a438a7b 100644 --- a/patches/gdb-enum-fix.patch +++ b/patches/gdb-enum-fix.patch @@ -1,3 +1,10 @@ +Fix Clang enum-constexpr-conversion warning in GDB enum-flags.h + +This patch suppresses the -Wenum-constexpr-conversion warning that occurs when +building GDB with Clang on macOS. The warning is triggered by the enum_underlying_type +template which uses sizeof() on enum types in a way that Clang considers problematic, +even though the code is valid and works correctly. + --- a/gdb/gdbsupport/enum-flags.h +++ b/gdb/gdbsupport/enum-flags.h @@ -79,6 +79,10 @@ template<> struct integer_for_size<4, 1> { typedef int32_t type; }; diff --git a/patches/gdb-zlib-fdopen-macos.patch b/patches/gdb-zlib-fdopen-macos.patch deleted file mode 100644 index c99767b..0000000 --- a/patches/gdb-zlib-fdopen-macos.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- a/zlib/zutil.h -+++ b/zlib/zutil.h -@@ -132,15 +132,6 @@ - - #if defined(MACOS) || defined(TARGET_OS_MAC) - # define OS_CODE 7 --# ifndef Z_SOLO --# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os --# include /* for fdopen */ --# else --# ifndef fdopen --# define fdopen(fd,mode) NULL /* No fdopen() */ --# endif --# endif --# endif - #endif - - #ifdef __acorn - diff --git a/patches/zlib.patch b/patches/zlib.patch index cecdb32..17ac266 100644 --- a/patches/zlib.patch +++ b/patches/zlib.patch @@ -1,3 +1,7 @@ +Patch for standalone zlib build +- Updates CMake minimum version requirement for modern CMake compatibility +- Removes obsolete Metrowerks CodeWarrior fdopen workaround (same as patches/common/zlib-fdopen-macos.patch) + --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@