Skip to content

Commit cb2d86d

Browse files
asheshvfrozencemetery
authored andcommitted
Support 32-bit Windows if using 32-bit Python
Signed-off-by: Ashesh Vashi <[email protected]> [[email protected]: commit message, squash, minor style tweaks] [[email protected]: add 32-bit Windows CI]
1 parent dfbf05a commit cb2d86d

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
"win-py-3.7",
6767
"win-py-3.6",
6868
],
69+
"arch": [
70+
"x64",
71+
"x86",
72+
],
6973
"include": [
7074
{
7175
"name": "win-py-3.9",
@@ -94,7 +98,10 @@
9498
{
9599
"name": "Install the right python",
96100
"uses": "actions/setup-python@v2",
97-
"with": { "python-version": "${{ matrix.pyenv }}" },
101+
"with": {
102+
"python-version": "${{ matrix.pyenv }}",
103+
"architecture": "${{ matrix.arch }}",
104+
},
98105
},
99106
{
100107
"name": "Build and test gssapi",

.github/workflows/release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
"win-wheel-3.7",
8686
"win-wheel-3.6",
8787
],
88+
"arch": [
89+
"x64",
90+
"x86"
91+
],
8892
"include": [
8993
{
9094
"name": "win-wheel-3.9",
@@ -113,7 +117,10 @@
113117
{
114118
"name": "Install the right python",
115119
"uses": "actions/setup-python@v2",
116-
"with": { "python-version": "${{ matrix.pyenv }}" },
120+
"with": {
121+
"python-version": "${{ matrix.pyenv }}",
122+
"architecture": "${{ matrix.arch }}"
123+
},
117124
},
118125
{
119126
"name": "Create and upload Windows wheel",

gssapi/_win_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import shutil
11+
import sys
1112
import ctypes
1213

1314
#: Path to normal KfW installed bin folder
@@ -22,7 +23,10 @@
2223
def kfw_available():
2324
"""Return if the main GSSAPI DLL for KfW can be loaded"""
2425
try: # to load the main GSSAPI DLL
25-
ctypes.WinDLL('gssapi64.dll')
26+
if sys.maxsize > 2**32:
27+
ctypes.WinDLL('gssapi64.dll')
28+
else:
29+
ctypes.WinDLL('gssapi32.dll')
2630
except OSError: # DLL is not in PATH
2731
return False
2832
else: # DLL is in PATH, everything should work

setup.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def get_output(*args, **kwargs):
3939
# get the compile and link args
4040
kc = "krb5-config"
4141
posix = os.name != 'nt'
42+
43+
# Per https://docs.python.org/3/library/platform.html#platform.architecture
44+
# this is the preferred way of determining "64-bitness".
45+
is64bit = sys.maxsize > 2**32
46+
4247
link_args, compile_args = [
4348
shlex.split(os.environ[e], posix=posix) if e in os.environ else None
4449
for e in ['GSSAPI_LINKER_ARGS', 'GSSAPI_COMPILER_ARGS']
@@ -97,7 +102,7 @@ def get_output(*args, **kwargs):
97102
link_args = ['-framework', 'GSS']
98103
elif winkrb_path:
99104
_libs = os.path.join(
100-
winkrb_path, 'lib', 'amd64' if sys.maxsize > 2 ** 32 else 'i386'
105+
winkrb_path, 'lib', 'amd64' if is64bit else 'i386'
101106
)
102107
link_args = (
103108
['-L%s' % _libs]
@@ -114,8 +119,9 @@ def get_output(*args, **kwargs):
114119
elif winkrb_path:
115120
compile_args = [
116121
'-I%s' % os.path.join(winkrb_path, 'include'),
117-
'-DMS_WIN64'
118122
]
123+
if is64bit:
124+
compile_args.append('-DMS_WIN64')
119125
elif os.environ.get('MINGW_PREFIX'):
120126
compile_args = ['-fPIC']
121127
else:
@@ -174,10 +180,7 @@ def get_output(*args, **kwargs):
174180
main_lib = os.environ.get('MINGW_PREFIX')+'/bin/libgss-3.dll'
175181
elif sys.platform == 'msys':
176182
# Plain msys, not running in MINGW_PREFIX. Try to get the lib from one
177-
_main_lib = (
178-
'/mingw%d/bin/libgss-3.dll'
179-
% (64 if sys.maxsize > 2 ** 32 else 32)
180-
)
183+
_main_lib = f'/mingw{64 if is64bit else 32}/bin/libgss-3.dll'
181184
if os.path.exists(_main_lib):
182185
main_lib = _main_lib
183186
os.environ['PATH'] += os.pathsep + os.path.dirname(main_lib)

0 commit comments

Comments
 (0)