Skip to content

Commit 24f6d1e

Browse files
committed
Windows compat, at least for unparsing and actually loading the package.
1 parent cbf42ce commit 24f6d1e

1 file changed

Lines changed: 42 additions & 18 deletions

File tree

transpyle/cpp/compiler_interface.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ class GppInterface(CompilerInterface):
3333
'MPI': pathlib.Path('mpic++')
3434
}
3535

36+
compile_flags = tuple()
37+
38+
# Config does not always contain these items (eg. on Windows)
39+
40+
if 'BASECFLAGS' in PYTHON_CONFIG:
41+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags,PYTHON_CONFIG['BASECFLAGS'])))
42+
43+
if 'BASECPPFLAGS' in PYTHON_CONFIG:
44+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags,PYTHON_CONFIG['BASECPPFLAGS'])))
45+
3646
_flags = {
3747
'': ('-O3', '-fPIC', '-Wall', '-Wextra', '-Wpedantic', '-fdiagnostics-color=always'),
38-
'compile': tuple(split_and_strip('{} {}'.format(
39-
PYTHON_CONFIG['BASECFLAGS'], PYTHON_CONFIG['BASECPPFLAGS']))),
48+
'compile': compile_flags,
4049
'link': (),
4150
'OpenMP': ('-fopenmp',)
4251
}
@@ -46,18 +55,20 @@ class GppInterface(CompilerInterface):
4655
pathlib.Path(PYTHON_CONFIG['INCLUDEPY']),
4756
*[pathlib.Path(_, 'core', 'include') for _ in np.__path__]]
4857

49-
library_paths = [
50-
pathlib.Path(PYTHON_CONFIG['LIBDIR'])]
58+
library_paths = []
59+
if 'LIBDIR' in PYTHON_CONFIG:
60+
library_paths.append(pathlib.Path(PYTHON_CONFIG['LIBDIR']))
5161

52-
if PYTHON_CONFIG['LDLIBRARY']:
62+
if 'LDLIBRARY' in PYTHON_CONFIG:
5363
ldlibrary = pathlib.Path(PYTHON_CONFIG['LDLIBRARY'].lstrip('lib')).with_suffix('')
5464
else:
55-
ldlibrary = pathlib.Path('not_implemented_yet.dll')
65+
ldlibrary = None
5666

57-
# libraries = split_and_strip('-l{} {} {} {}'.format(
58-
# ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
59-
libraries = split_and_strip('-l{} {} {}'.format(
60-
ldlibrary, PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
67+
if 'LIBS' in PYTHON_CONFIG and 'SYSLIBS' in PYTHON_CONFIG and 'LINKFORSHARED' in PYTHON_CONFIG:
68+
libraries = split_and_strip('-l{} {} {} {}'.format(
69+
ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
70+
else:
71+
libraries = []
6172

6273
_options = {
6374
'compile': ['-I{}'.format(_) for _ in include_paths],
@@ -73,10 +84,19 @@ class ClangppInterface(CompilerInterface):
7384

7485
_executables = {'': pathlib.Path('clang++')}
7586

87+
compile_flags = tuple()
88+
89+
# Config does not always contain these items (eg. on Windows)
90+
91+
if 'BASECFLAGS' in PYTHON_CONFIG:
92+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags, PYTHON_CONFIG['BASECFLAGS'])))
93+
94+
if 'BASECPPFLAGS' in PYTHON_CONFIG:
95+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags, PYTHON_CONFIG['BASECPPFLAGS'])))
96+
7697
_flags = {
7798
'': ('-O3', '-fPIC', '-Wall', '-Wextra', '-Wpedantic', '-fcolor-diagnostics'),
78-
'compile': tuple(split_and_strip('{} {}'.format(
79-
PYTHON_CONFIG['BASECFLAGS'], PYTHON_CONFIG['BASECPPFLAGS']))),
99+
'compile': compile_flags,
80100
'OpenMP': ('-fopenmp',)
81101
}
82102
# -Ofast
@@ -85,16 +105,20 @@ class ClangppInterface(CompilerInterface):
85105
pathlib.Path(PYTHON_CONFIG['INCLUDEPY']),
86106
*[pathlib.Path(_, 'core', 'include') for _ in np.__path__]]
87107

88-
library_paths = [
89-
pathlib.Path(PYTHON_CONFIG['LIBDIR'])]
108+
library_paths = []
109+
if 'LIBDIR' in PYTHON_CONFIG:
110+
library_paths.append(pathlib.Path(PYTHON_CONFIG['LIBDIR']))
90111

91-
if PYTHON_CONFIG['LDLIBRARY']:
112+
if 'LDLIBRARY' in PYTHON_CONFIG:
92113
ldlibrary = pathlib.Path(PYTHON_CONFIG['LDLIBRARY'].lstrip('lib')).with_suffix('')
93114
else:
94-
ldlibrary = pathlib.Path('not_implemented_yet.dll')
115+
ldlibrary = None
95116

96-
libraries = split_and_strip('-l{} {} {} {}'.format(
97-
ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
117+
if 'LIBS' in PYTHON_CONFIG and 'SYSLIBS' in PYTHON_CONFIG and 'LINKFORSHARED' in PYTHON_CONFIG:
118+
libraries = split_and_strip('-l{} {} {} {}'.format(
119+
ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
120+
else:
121+
libraries = []
98122

99123
_options = {
100124
'compile': ['-I{}'.format(_) for _ in include_paths],

0 commit comments

Comments
 (0)