Skip to content

Commit

Permalink
Try linking the windows wheels against the static C runtime. See #346
Browse files Browse the repository at this point in the history
Also include updated versions of the two open PRs that attempt to add new platforms. They are untested and unsupported,
but fixes #224 and fixes #257
  • Loading branch information
jamadden committed Aug 30, 2023
1 parent c2416a1 commit f1005b9
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 33 deletions.
19 changes: 18 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@
3.0.0a2 (unreleased)
====================

- Nothing changed yet.
- Windows wheels are linked statically to the C runtime in an effort
to prevent import errors on systems without the correct C runtime
installed. It's not clear if this will make the situation better or
worse, so please share your experiences in `issue 346
<https://github.com/python-greenlet/greenlet/issues/346>`_.

Note that this only applies to the binary wheels found on PyPI.
Building greenlet from source defaults to the shared library. Set
the environment variable ``GREENLET_STATIC_RUNTIME=1`` at build time
to change that.

- Now, greenlet *may* compile and work on Windows ARM64 using
llvm-mingw, but this is untested and unsupported. See `PR
<https://github.com/python-greenlet/greenlet/pull/224>`_ by Adrian
Vladu.
- Now, greenlet *may* compile and work on LoongArch64 Linux systems,
but this is untested and unsupported. See `PR 257
<https://github.com/python-greenlet/greenlet/pull/257/files>`_ by merore.


3.0.0a1 (2023-06-21)
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ environment:
PYTHONDEVMODE: 1
PYTHONFAULTHANDLER: 1
PYTHONUNBUFFERED: 1
# Try to avoid pulling in the C runtime, as some users won't have the
# right package.
GREENLET_STATIC_RUNTIME: "1"
# Don't get warnings about Python 2 support being deprecated. We
# know.
PIP_NO_PYTHON_VERSION_WARNING: 1
Expand Down
3 changes: 3 additions & 0 deletions src/greenlet/greenlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "structmember.h" // PyMemberDef

#include "greenlet_internal.hpp"
// Code after this point can assume access to things declared in stdint.h,
// including the fixed-width types. This goes for the platform-specific switch functions
// as well.
#include "greenlet_refs.hpp"
#include "greenlet_slp_switch.hpp"
#include "greenlet_thread_state.hpp"
Expand Down
6 changes: 5 additions & 1 deletion src/greenlet/platform/switch_aarch64_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ slp_switch(void)
{
int err;
void *fp;
long *stackref, stsizediff;
/* Windowz uses a 32-bit long on a 64-bit platform, unlike the rest of
the world, and in theory we can be compiled with GCC/llvm on 64-bit
windows. So we need a fixed-width type.
*/
int64_t *stackref, stsizediff;
__asm__ volatile ("" : : : REGS_TO_SAVE);
__asm__ volatile ("str x29, %0" : "=m"(fp) : : );
__asm__ ("mov %0, sp" : "=r" (stackref));
Expand Down
31 changes: 31 additions & 0 deletions src/greenlet/platform/switch_loongarch64_linux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#define STACK_REFPLUS 1

#ifdef SLP_EVAL
#define STACK_MAGIC 0

#define REGS_TO_SAVE "s0", "s1", "s2", "s3", "s4", "s5", \
"s6", "s7", "s8", "fp", \
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31"

static int
slp_switch(void)
{
int ret;
long *stackref, stsizediff;
__asm__ volatile ("" : : : REGS_TO_SAVE);
__asm__ volatile ("move %0, $sp" : "=r" (stackref) : );
{
SLP_SAVE_STATE(stackref, stsizediff);
__asm__ volatile (
"add.d $sp, $sp, %0\n\t"
: /* no outputs */
: "r" (stsizediff)
);
SLP_RESTORE_STATE();
}
__asm__ volatile ("" : : : REGS_TO_SAVE);
__asm__ volatile ("move %0, $zero" : "=r" (ret) : );
return ret;
}

#endif
68 changes: 37 additions & 31 deletions src/greenlet/slp_platformselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,68 @@
#ifdef __cplusplus
extern "C" {
#endif

#if defined(MS_WIN32) && !defined(MS_WIN64) && defined(_M_IX86) && defined(_MSC_VER)
#include "platform/switch_x86_msvc.h" /* MS Visual Studio on X86 */
# include "platform/switch_x86_msvc.h" /* MS Visual Studio on X86 */
#elif defined(MS_WIN64) && defined(_M_X64) && defined(_MSC_VER) || defined(__MINGW64__)
#include "platform/switch_x64_msvc.h" /* MS Visual Studio on X64 */
# include "platform/switch_x64_msvc.h" /* MS Visual Studio on X64 */
#elif defined(MS_WIN64) && defined(_M_ARM64)
#include "platform/switch_arm64_msvc.h" /* MS Visual Studio on ARM64 */
# include "platform/switch_arm64_msvc.h" /* MS Visual Studio on ARM64 */
#elif defined(__GNUC__) && defined(__amd64__) && defined(__ILP32__)
#include "platform/switch_x32_unix.h" /* gcc on amd64 with x32 ABI */
# include "platform/switch_x32_unix.h" /* gcc on amd64 with x32 ABI */
#elif defined(__GNUC__) && defined(__amd64__)
#include "platform/switch_amd64_unix.h" /* gcc on amd64 */
# include "platform/switch_amd64_unix.h" /* gcc on amd64 */
#elif defined(__GNUC__) && defined(__i386__)
#include "platform/switch_x86_unix.h" /* gcc on X86 */
# include "platform/switch_x86_unix.h" /* gcc on X86 */
#elif defined(__GNUC__) && defined(__powerpc64__) && (defined(__linux__) || defined(__FreeBSD__))
#include "platform/switch_ppc64_linux.h" /* gcc on PowerPC 64-bit */
# include "platform/switch_ppc64_linux.h" /* gcc on PowerPC 64-bit */
#elif defined(__GNUC__) && defined(__PPC__) && (defined(__linux__) || defined(__FreeBSD__))
#include "platform/switch_ppc_linux.h" /* gcc on PowerPC */
# include "platform/switch_ppc_linux.h" /* gcc on PowerPC */
#elif defined(__GNUC__) && defined(__ppc__) && defined(__APPLE__)
#include "platform/switch_ppc_macosx.h" /* Apple MacOS X on PowerPC */
# include "platform/switch_ppc_macosx.h" /* Apple MacOS X on PowerPC */
#elif defined(__GNUC__) && defined(__powerpc64__) && defined(_AIX)
#include "platform/switch_ppc64_aix.h" /* gcc on AIX/PowerPC 64-bit */
# include "platform/switch_ppc64_aix.h" /* gcc on AIX/PowerPC 64-bit */
#elif defined(__GNUC__) && defined(_ARCH_PPC) && defined(_AIX)
#include "platform/switch_ppc_aix.h" /* gcc on AIX/PowerPC */
# include "platform/switch_ppc_aix.h" /* gcc on AIX/PowerPC */
#elif defined(__GNUC__) && defined(sparc)
#include "platform/switch_sparc_sun_gcc.h" /* SunOS sparc with gcc */
# include "platform/switch_sparc_sun_gcc.h" /* SunOS sparc with gcc */
#elif defined(__SUNPRO_C) && defined(sparc) && defined(sun)
#include "platform/switch_sparc_sun_gcc.h" /* SunStudio on amd64 */
# iiclude "platform/switch_sparc_sun_gcc.h" /* SunStudio on amd64 */
#elif defined(__SUNPRO_C) && defined(__amd64__) && defined(sun)
#include "platform/switch_amd64_unix.h" /* SunStudio on amd64 */
# include "platform/switch_amd64_unix.h" /* SunStudio on amd64 */
#elif defined(__SUNPRO_C) && defined(__i386__) && defined(sun)
#include "platform/switch_x86_unix.h" /* SunStudio on x86 */
# include "platform/switch_x86_unix.h" /* SunStudio on x86 */
#elif defined(__GNUC__) && defined(__s390__) && defined(__linux__)
#include "platform/switch_s390_unix.h" /* Linux/S390 */
# include "platform/switch_s390_unix.h" /* Linux/S390 */
#elif defined(__GNUC__) && defined(__s390x__) && defined(__linux__)
#include "platform/switch_s390_unix.h" /* Linux/S390 zSeries (64-bit) */
# include "platform/switch_s390_unix.h" /* Linux/S390 zSeries (64-bit) */
#elif defined(__GNUC__) && defined(__arm__)
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
#if TARGET_OS_IPHONE
#include "platform/switch_arm32_ios.h" /* iPhone OS on arm32 */
#else
#include "platform/switch_arm32_gcc.h" /* gcc using arm32 */
#endif
# ifdef __APPLE__
# include <TargetConditionals.h>
# endif
# if TARGET_OS_IPHONE
# include "platform/switch_arm32_ios.h" /* iPhone OS on arm32 */
# else
# include "platform/switch_arm32_gcc.h" /* gcc using arm32 */
# endif
#elif defined(__GNUC__) && defined(__mips__) && defined(__linux__)
#include "platform/switch_mips_unix.h" /* Linux/MIPS */
# include "platform/switch_mips_unix.h" /* Linux/MIPS */
#elif defined(__GNUC__) && defined(__aarch64__)
#include "platform/switch_aarch64_gcc.h" /* Aarch64 ABI */
# include "platform/switch_aarch64_gcc.h" /* Aarch64 ABI */
#elif defined(__GNUC__) && defined(__mc68000__)
#include "platform/switch_m68k_gcc.h" /* gcc on m68k */
# include "platform/switch_m68k_gcc.h" /* gcc on m68k */
#elif defined(__GNUC__) && defined(__csky__)
#include "platform/switch_csky_gcc.h" /* gcc on csky */
#elif defined(__GNUC__) && defined(__riscv)
#include "platform/switch_riscv_unix.h" /* gcc on RISC-V */
# elif defined(__GNUC__) && defined(__riscv)
# include "platform/switch_riscv_unix.h" /* gcc on RISC-V */
#elif defined(__GNUC__) && defined(__alpha__)
#include "platform/switch_alpha_unix.h" /* gcc on DEC Alpha */
# include "platform/switch_alpha_unix.h" /* gcc on DEC Alpha */
#elif defined(MS_WIN32) && defined(__llvm__) && defined(__aarch64__)
# include "platform/switch_aarch64_gcc.h" /* LLVM Aarch64 ABI for Windows */
#elif defined(__GNUC__) && defined(__loongarch64) && defined(__linux__)
# include "platform/switch_loongarch64_linux.h" /* LoongArch64 */
#endif

#ifdef __cplusplus
};
#endif

0 comments on commit f1005b9

Please sign in to comment.