From 4f1c2e8a5392e1daf1823c70538fd908b827e19c Mon Sep 17 00:00:00 2001 From: Ashesh Vashi Date: Tue, 25 May 2021 16:21:40 +0530 Subject: [PATCH 1/2] Support 32-bit Windows if using 32-bit Python Signed-off-by: Ashesh Vashi [rharwood@redhat.com: commit message, squash, minor style tweaks] --- gssapi/_win_config.py | 6 +++++- setup.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gssapi/_win_config.py b/gssapi/_win_config.py index ccbdb259..9b765b20 100644 --- a/gssapi/_win_config.py +++ b/gssapi/_win_config.py @@ -8,6 +8,7 @@ import os import shutil +import sys import ctypes #: Path to normal KfW installed bin folder @@ -22,7 +23,10 @@ def kfw_available(): """Return if the main GSSAPI DLL for KfW can be loaded""" try: # to load the main GSSAPI DLL - ctypes.WinDLL('gssapi64.dll') + if sys.maxsize > 2**32: + ctypes.WinDLL('gssapi64.dll') + else: + ctypes.WinDLL('gssapi32.dll') except OSError: # DLL is not in PATH return False else: # DLL is in PATH, everything should work diff --git a/setup.py b/setup.py index 37bef146..de30f2ee 100755 --- a/setup.py +++ b/setup.py @@ -39,6 +39,11 @@ def get_output(*args, **kwargs): # get the compile and link args kc = "krb5-config" posix = os.name != 'nt' + +# Per https://docs.python.org/3/library/platform.html#platform.architecture +# this is the preferred way of determining "64-bitness". +is64bit = sys.maxsize > 2**32 + link_args, compile_args = [ shlex.split(os.environ[e], posix=posix) if e in os.environ else None for e in ['GSSAPI_LINKER_ARGS', 'GSSAPI_COMPILER_ARGS'] @@ -97,7 +102,7 @@ def get_output(*args, **kwargs): link_args = ['-framework', 'GSS'] elif winkrb_path: _libs = os.path.join( - winkrb_path, 'lib', 'amd64' if sys.maxsize > 2 ** 32 else 'i386' + winkrb_path, 'lib', 'amd64' if is64bit else 'i386' ) link_args = ( ['-L%s' % _libs] @@ -114,8 +119,9 @@ def get_output(*args, **kwargs): elif winkrb_path: compile_args = [ '-I%s' % os.path.join(winkrb_path, 'include'), - '-DMS_WIN64' ] + if is64bit: + compile_args.append('-DMS_WIN64') elif os.environ.get('MINGW_PREFIX'): compile_args = ['-fPIC'] else: @@ -174,10 +180,7 @@ def get_output(*args, **kwargs): main_lib = os.environ.get('MINGW_PREFIX')+'/bin/libgss-3.dll' elif sys.platform == 'msys': # Plain msys, not running in MINGW_PREFIX. Try to get the lib from one - _main_lib = ( - '/mingw%d/bin/libgss-3.dll' - % (64 if sys.maxsize > 2 ** 32 else 32) - ) + _main_lib = f'/mingw{64 if is64bit else 32}/bin/libgss-3.dll' if os.path.exists(_main_lib): main_lib = _main_lib os.environ['PATH'] += os.pathsep + os.path.dirname(main_lib) From 737330b296ae40973c6d6ba7db68c8347c3cde67 Mon Sep 17 00:00:00 2001 From: Roger Aiudi Date: Tue, 25 May 2021 13:42:53 -0400 Subject: [PATCH 2/2] CI: Build and release on 32bit Windows Python Signed-off-by: Roger Aiudi --- .github/workflows/build.yml | 9 ++++++++- .github/workflows/release.yml | 9 ++++++++- ci/lib-setup.sh | 10 +++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69ad7c2a..2549fde3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,6 +66,10 @@ "win-py-3.7", "win-py-3.6", ], + "arch": [ + "x64", + "x86" + ], "include": [ { "name": "win-py-3.9", @@ -94,7 +98,10 @@ { "name": "Install the right python", "uses": "actions/setup-python@v2", - "with": { "python-version": "${{ matrix.pyenv }}" }, + "with": { + "python-version": "${{ matrix.pyenv }}", + "architecture": "${{ matrix.arch }}" + }, }, { "name": "Build and test gssapi", diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 600a6657..da9015eb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -85,6 +85,10 @@ "win-wheel-3.7", "win-wheel-3.6", ], + "arch": [ + "x64", + "x86" + ], "include": [ { "name": "win-wheel-3.9", @@ -113,7 +117,10 @@ { "name": "Install the right python", "uses": "actions/setup-python@v2", - "with": { "python-version": "${{ matrix.pyenv }}" }, + "with": { + "python-version": "${{ matrix.pyenv }}", + "architecture": "${{ matrix.arch }}" + }, }, { "name": "Create and upload Windows wheel", diff --git a/ci/lib-setup.sh b/ci/lib-setup.sh index c90b530f..2fa93292 100755 --- a/ci/lib-setup.sh +++ b/ci/lib-setup.sh @@ -64,11 +64,19 @@ setup::macos::install() { setup::windows::install() { CHINST="choco install --no-progress --yes --ignore-detected-reboot --allow-downgrade" + # Install the 32bit version if Python is 32bit + if python -c "assert __import__('sys').maxsize <= 2**32"; then + CHINST="$CHINST --x86" + PF="Program Files (x86)" + else + PF="Program Files" + fi + # Install MIT Kerberos. choco will fail despite the installation working. $CHINST mitkerberos --install-arguments "'ADDLOCAL=ALL'" || true # Update path to include it - export PATH="/c/Program Files/MIT/Kerberos/bin:$PATH" + export PATH="/c/$PF/MIT/Kerberos/bin:$PATH" python -m pip install --upgrade pip }