From f43c2dd5c758b251c1245c6c62b9c0a06d5e00a2 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Fri, 19 Dec 2025 06:18:53 +0800 Subject: [PATCH] Support powerpc-darwin diff --git a/compiler/installer.ini b/compiler/installer.ini index 7db6182dc..507299eb6 100644 --- a/compiler/installer.ini +++ b/compiler/installer.ini @@ -7,7 +7,7 @@ Version: "$version" Platforms: """ windows: i386;amd64 linux: i386;hppa;ia64;alpha;amd64;powerpc64;arm;sparc;sparc64;s390x;m68k;mips;mipsel;mips64;mips64el;powerpc;powerpc64el;arm64;riscv32;riscv64;loongarch64 - macosx: i386;amd64;powerpc64;arm64 + macosx: i386;amd64;powerpc;powerpc64;arm64 solaris: i386;amd64;sparc;sparc64 freebsd: i386;amd64;powerpc64;arm;arm64;riscv64;sparc64;mips;mipsel;mips64;mips64el;powerpc;powerpc64el netbsd: i386;amd64;arm64 diff --git a/config/nim.cfg b/config/nim.cfg index 038c3c9be..d596d6df7 100644 --- a/config/nim.cfg +++ b/config/nim.cfg @@ -193,7 +193,7 @@ tlsEmulation:on @end -@if macosx or freebsd or openbsd: +@if freebsd or openbsd: cc = clang gcc.options.always %= "-w ${gcc.maxerrorsimpl}" gcc.cpp.options.always %= "-w ${gcc.maxerrorsimpl} -fpermissive" diff --git a/lib/cycle.h b/lib/cycle.h index 4d714ba3f..ef9df3cb5 100644 --- a/lib/cycle.h +++ b/lib/cycle.h @@ -133,7 +133,7 @@ static __inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */ /* * PowerPC ``cycle'' counter using the time base register. */ -#if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER) +#if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__POWERPC__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER) typedef unsigned long long ticks; static __inline__ ticks getticks(void) diff --git a/tools/niminst/buildsh.nimf b/tools/niminst/buildsh.nimf index 2ef1874cb..49f3cc256 100644 --- a/tools/niminst/buildsh.nimf +++ b/tools/niminst/buildsh.nimf @@ -126,11 +126,14 @@ case $uos in ;; *darwin* ) myos="macosx" - CC="clang" + CC="gcc" LINK_FLAGS="$LINK_FLAGS -ldl -lm" if [ "$HOSTTYPE" = "x86_64" ] ; then ucpu="amd64" fi + if [ "$HOSTTYPE" = "powerpc" ] ; then + ucpu="powerpc" + fi ;; *aix* ) myos="aix" @@ -204,6 +207,15 @@ case $ucpu in powerpc64le) mycpu="powerpc64el" esac + elif [ "$myos" = "macosx" ] ; then + mycpu="$("$CC" -dumpmachine | sed 's/-.*//')" + if [ "$mycpu" = "powerpc64" ] ; then + COMP_FLAGS="$COMP_FLAGS -arch ppc64" + LINK_FLAGS="$LINK_FLAGS -arch ppc64" + else + COMP_FLAGS="$COMP_FLAGS -arch ppc" + LINK_FLAGS="$LINK_FLAGS -arch ppc" + fi else mycpu="powerpc" fi diff --git a/tools/niminst/makefile.nimf b/tools/niminst/makefile.nimf index 002bc0592..54c52ecb8 100644 --- a/tools/niminst/makefile.nimf +++ b/tools/niminst/makefile.nimf @@ -49,11 +49,14 @@ ifeq ($(uos),netbsd) endif ifeq ($(uos),darwin) myos = macosx - CC = clang + CC = gcc LDFLAGS += -ldl -lm ifeq ($(HOSTTYPE),x86_64) ucpu = amd64 endif + ifeq ($(HOSTTYPE),powerpc) + ucpu = powerpc + endif endif ifeq ($(uos),aix) myos = aix @@ -140,6 +143,16 @@ ifeq ($(ucpu),powerpc) mycpu = powerpc64el endif endif + ifeq ($(myos),macosx) + mycpu = $(shell /bin/sh -c '"$(CC)" -dumpmachine | sed "s/-.*//"') + ifeq ($(mycpu),powerpc64) + CFLAGS += -arch ppc64 + LDFLAGS += -arch ppc64 + else + CFLAGS += -arch ppc + LDFLAGS += -arch ppc + endif + endif endif ifeq ($(ucpu),ppc) mycpu = powerpc --- a/lib/posix/posix.nim 2025-10-31 10:02:44.000000000 +0800 +++ b/lib/posix/posix.nim 2025-12-21 00:48:59.000000000 +0800 @@ -104,7 +104,7 @@ include posix_linux_amd64 elif defined(openbsd) and defined(amd64): include posix_openbsd_amd64 -elif (defined(macos) or defined(macosx) or defined(bsd)) and defined(cpu64): +elif (defined(macos) or defined(macosx) or defined(osx) or defined(bsd)): include posix_macos_amd64 elif defined(nintendoswitch): include posix_nintendoswitch --- a/lib/nimbase.h 2025-10-31 10:02:44.000000000 +0800 +++ b/lib/nimbase.h 2025-12-22 09:36:54.000000000 +0800 @@ -316,6 +316,9 @@ #endif /* bool types (C++ has it): */ +#ifdef __ppc__ +typedef unsigned char NIM_BOOL; // In Darwin ppc ABI bool is 4-bytes. +#else #ifdef __cplusplus #define NIM_BOOL bool #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) @@ -324,6 +327,7 @@ #else typedef unsigned char NIM_BOOL; // best effort #endif +#endif NIM_STATIC_ASSERT(sizeof(NIM_BOOL) == 1, ""); // check whether really needed NIM_STATIC_ASSERT(CHAR_BIT == 8, "");