Skip to content

Commit 12d13d8

Browse files
committed
modifpy windows build
1 parent 7340565 commit 12d13d8

5 files changed

Lines changed: 40 additions & 21 deletions

File tree

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
__pycache__/
33
*.py[cod]
44
*$py.class
5-
.exp
6-
.lib
7-
.dll
5+
*.exp
6+
*.lib
7+
*.dll
8+
*.pdb
89

910
# Compiled Dynamic libraries
1011
*.so

SConstruct

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ SCons construction environment can be customized in sconscript.local script.
2222
import os
2323
from os.path import join as pjoin
2424
import re
25-
import platform
2625
import sys
2726

2827

@@ -107,6 +106,9 @@ if env['PLATFORM'] == "win32":
107106
lib_path = pjoin(env['prefix'], 'Library', 'lib')
108107
shared_path = pjoin(env['prefix'], 'Library', 'share')
109108

109+
env.AppendUnique(CPPPATH=[ pjoin(env['prefix'], 'include') ]) # for python headers
110+
env.AppendUnique(LIBPATH=[ pjoin(env['prefix'], 'libs') ]) # for python libs
111+
110112
env['ENV']['TMP'] = os.environ.get('TMP', env['ENV'].get('TMP', ''))
111113
else:
112114
include_path = pjoin(env['prefix'], 'include')
@@ -137,7 +139,7 @@ env.Help(MY_SCONS_HELP % vars.GenerateHelpText(env))
137139

138140
# Determine python-config script name.
139141
pyversion = os.environ.get('PY_VER') or f"{sys.version_info.major}.{sys.version_info.minor}"
140-
if platform.system().lower() != 'windows':
142+
if env['PLATFORM'] != 'win32':
141143
pythonconfig = pjoin(env['prefix'], 'bin', f'python{pyversion}-config')
142144
xpython = pjoin(env['prefix'], 'bin', 'python')
143145
else:
@@ -155,16 +157,13 @@ if env['PLATFORM'] == 'win32':
155157
env.AppendUnique(CCFLAGS=['/EHsc', '/MD'])
156158

157159
if env['build'] == 'debug':
158-
env.Append(CCFLAGS=['/Zi', '/Od'])
160+
env.Append(CCFLAGS=['/Zi', '/Od', '/FS'])
159161
env.Append(LINKFLAGS=['/DEBUG'])
160162

161163
elif env['build'] == 'fast':
162164
env.Append(CCFLAGS=['/Ox', '/GL'])
163165
env.Append(LINKFLAGS=['/LTCG', '/OPT:REF', '/OPT:ICF'])
164166

165-
if env['profile']:
166-
env.Append(CCFLAGS='/Gh')
167-
168167
else:
169168
# get python flags from python-config script
170169
# not using sysconfig here because of parsing issues
@@ -202,11 +201,7 @@ else:
202201
env.Append(CCFLAGS=['-O3'] + fast_opts)
203202
env.Append(LINKFLAGS=fast_link)
204203

205-
if env['profile']:
206-
env.AppendUnique(CCFLAGS='-pg')
207-
env.AppendUnique(LINKFLAGS='-pg')
208-
209-
builddir = env.Dir('build/%s-%s' % (env['build'], platform.machine()))
204+
builddir = env.Dir('build/%s-%s' % (env['build'], env['PLATFORM']))
210205

211206
Export('env', 'pyversion')
212207

requirements/build.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setuptools

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ def create_extensions():
5555
include_dirs = get_env_config().get("include_dirs") + [np.get_include()]
5656
library_dirs = get_env_config().get("library_dirs")
5757

58-
libraries = ["ObjCryst"] + check_boost_libraries(Path(library_dirs[0]))
58+
if os.name == "nt":
59+
objcryst_lib = "libObjCryst"
60+
else:
61+
objcryst_lib = "ObjCryst"
62+
63+
libraries = [objcryst_lib] + check_boost_libraries(Path(library_dirs[0]))
5964
extra_objects = []
6065
extra_compile_args = []
6166
extra_link_args = []

src/extensions/SConscript

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import os
3-
from setuptools import Distribution, Extension
3+
from SCons.Script import Clean
44

55
Import('env')
66

@@ -11,28 +11,45 @@ env.AppendUnique(CPPPATH=[np.get_include()])
1111
if not (GetOption('clean') or env.GetOption('help')):
1212
SConscript('SConscript.configure')
1313

14+
if env['PLATFORM'] == 'win32':
15+
if env['profile']:
16+
print("Warning: Windows profiling is not enabled; skipping /Gh")
17+
else:
18+
if env['profile']:
19+
env.AppendUnique(CCFLAGS='-pg')
20+
env.AppendUnique(LINKFLAGS='-pg')
21+
1422
# python extension module
15-
module = env.SharedLibrary(
23+
module_nodes = env.SharedLibrary(
1624
'_pyobjcryst',
1725
Glob('*.cpp'),
1826
SHLIBPREFIX='',
19-
SHLIBSUFFIX='.so')
27+
SHLIBSUFFIX = '.pyd' if env['PLATFORM']=='win32' else '.so')
2028

21-
installed = env.Install(Dir('#/src/pyobjcryst'), module)
29+
ext_module = module_nodes[0]
30+
installed = env.Install(Dir('#/src/pyobjcryst'), ext_module)
2231

2332
# run `scons develop` to install the extension in development mode
2433
dev = Alias('dev', installed)
2534
AlwaysBuild(dev)
2635

2736

2837
# run `scons test` to run the tests
38+
env['ENV']['PYTHONPATH'] = Dir('#').abspath + os.sep + 'src'
2939
test = env.Alias(
3040
'test',
3141
['dev'],
32-
f'PYTHONPATH={Dir("#").abspath + "/src"} python -m pyobjcryst.tests.run')
42+
Action('python -m pyobjcryst.tests.run')
43+
)
3344
AlwaysBuild(test)
3445

3546
# default targets:
36-
Default(module)
47+
Default(module_nodes)
48+
49+
# clean up the build artifacts
50+
Clean(None, ['.sconsign.dblite', 'config.log'])
51+
Clean(None, Dir('.sconf_temp'))
52+
Clean(None, Dir('build'))
53+
Clean(None, installed)
3754

3855
# vim: ft=python

0 commit comments

Comments
 (0)