Skip to content

Commit

Permalink
Support 32-bit Windows if using 32-bit Python
Browse files Browse the repository at this point in the history
Signed-off-by: Ashesh Vashi <ashesh.vashi@enterprisedb.com>
[rharwood@redhat.com: commit message, squash, minor style tweaks]
[aiudirog@gmail.com: add 32-bit Windows CI]
  • Loading branch information
asheshv authored and frozencemetery committed May 25, 2021
1 parent dfbf05a commit cb2d86d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
"win-py-3.7",
"win-py-3.6",
],
"arch": [
"x64",
"x86",
],
"include": [
{
"name": "win-py-3.9",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
"win-wheel-3.7",
"win-wheel-3.6",
],
"arch": [
"x64",
"x86"
],
"include": [
{
"name": "win-wheel-3.9",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion gssapi/_win_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
import shutil
import sys
import ctypes

#: Path to normal KfW installed bin folder
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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]
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cb2d86d

Please sign in to comment.