-
Notifications
You must be signed in to change notification settings - Fork 139
/
setup.py
196 lines (178 loc) · 5.07 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
import inspect
import os
import sys
from setuptools import Extension, setup
PACKAGE_NAME = "pyrfc"
MODULE_NAME = "_cyrfc"
build_cython = sys.platform.startswith("linux") or bool(
os.environ.get("PYRFC_BUILD_CYTHON")
)
# build from source on Linux
CMDCLASS = {}
if build_cython:
try:
from Cython.Build import cythonize
from Cython.Distutils import build_ext
except ImportError:
sys.exit("Cython not installed")
CMDCLASS = {"build_ext": build_ext}
# check if SAP NWRFC SDK configured
SAPNWRFC_HOME = os.environ.get("SAPNWRFC_HOME")
if not SAPNWRFC_HOME:
sys.exit(
"Environment variable SAPNWRFC_HOME not set.\n"
"This variable shall point to the root directory of the SAP NWRFC Library."
)
# Build options for supported wheels
if sys.platform.startswith("linux"):
LIBS = ["sapnwrfc", "sapucum"]
MACROS = [
("NDEBUG", None),
("_LARGEFILE_SOURCE", None),
("_CONSOLE", None),
("_FILE_OFFSET_BITS", 64),
("SAPonUNIX", None),
("SAPwithUNICODE", None),
("SAPwithTHREADS", None),
("SAPonLIN", None),
]
COMPILE_ARGS = [
"-Wall",
"-O2",
"-fexceptions",
"-funsigned-char",
"-fno-strict-aliasing",
"-Wall",
"-Wno-uninitialized",
"-Wno-deprecated-declarations",
"-Wno-unused-function",
"-Wcast-align",
"-fPIC",
"-pthread",
"-minline-all-stringops",
f"-I{SAPNWRFC_HOME}/include",
]
LINK_ARGS = [f"-L{SAPNWRFC_HOME}/lib"]
elif sys.platform.startswith("win"):
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically
# Python sources
PYTHONSOURCE = os.getenv(
"PYTHONSOURCE", inspect.getfile(inspect).split("/inspect.py")[0]
)
if not PYTHONSOURCE:
sys.exit("Environment variable PYTHONSOURCE not set.")
LIBS = ["sapnwrfc", "libsapucum"]
MACROS = [
("SAPonNT", None),
("_CRT_NON_CONFORMING_SWPRINTFS", None),
("_CRT_SECURE_NO_DEPRECATES", None),
("_CRT_NONSTDC_NO_DEPRECATE", None),
("_AFXDLL", None),
("WIN32", None),
("_WIN32_WINNT", "0x0502"),
("WIN64", None),
("_AMD64_", None),
("NDEBUG", None),
("SAPwithUNICODE", None),
("UNICODE", None),
("_UNICODE", None),
("SAPwithTHREADS", None),
("_ATL_ALLOW_CHAR_UNSIGNED", None),
("_LARGEFILE_SOURCE", None),
("_CONSOLE", None),
("SAP_PLATFORM_MAKENAME", "ntintel"),
]
COMPILE_ARGS = [
f"-I{SAPNWRFC_HOME}\\include",
f"-I{PYTHONSOURCE}\\Include",
f"-I{PYTHONSOURCE}\\Include\\PC",
"/EHs",
"/GL",
"/Gy",
"/J",
"/MD",
"/nologo",
"/O2",
"/Oy-",
"/we4552",
"/we4700",
"/we4789",
"/W3",
"/Z7",
]
LINK_ARGS = [
f"-LIBPATH:{SAPNWRFC_HOME}\\lib",
f"-LIBPATH:{PYTHONSOURCE}\\PCbuild",
"/NXCOMPAT",
"/STACK:0x2000000",
"/SWAPRUN:NET",
"/DEBUG",
"/OPT:REF",
"/DEBUGTYPE:CV,FIXUP",
"/MACHINE:amd64",
"/nologo",
"/LTCG",
]
elif sys.platform.startswith("darwin"):
MACOS_VERSION_MIN = "11"
LIBS = ["sapnwrfc", "sapucum"]
MACROS = [
("NDEBUG", None),
("_LARGEFILE_SOURCE", None),
("_CONSOLE", None),
("_FILE_OFFSET_BITS", 64),
("SAPonUNIX", None),
("SAPwithUNICODE", None),
("SAPwithTHREADS", None),
("SAPonDARW", None),
]
COMPILE_ARGS = [
"-Wall",
"-O2",
"-fexceptions",
"-funsigned-char",
"-fno-strict-aliasing",
"-Wno-uninitialized",
"-Wcast-align",
"-fPIC",
"-pthread",
"-minline-all-stringops",
"-isystem",
"-std=c++11",
f"-mmacosx-version-min={MACOS_VERSION_MIN}",
f"-I{SAPNWRFC_HOME}/include",
"-Wno-cast-align",
"-Wno-deprecated-declarations",
"-Wno-unused-function",
"-Wno-nullability-completeness",
"-Wno-expansion-to-defined",
"-Wno-unreachable-code",
"-Wno-unreachable-code-fallthrough",
]
LINK_ARGS = [
f"-L{SAPNWRFC_HOME}/lib",
"-stdlib=libc++",
f"-mmacosx-version-min={MACOS_VERSION_MIN}",
f"-Wl,-rpath,{SAPNWRFC_HOME}/lib",
]
else:
sys.exit(f"Platform not supported: {sys.platform}.")
PYRFC_EXT = Extension(
language="c++",
name=f"{PACKAGE_NAME}.{MODULE_NAME}",
sources=[f"src/{PACKAGE_NAME}/{MODULE_NAME}.pyx"],
define_macros=MACROS,
extra_compile_args=COMPILE_ARGS,
extra_link_args=LINK_ARGS,
libraries=LIBS,
)
PYRFC_EXT.cython_directives = {"language_level": "3", "embedsignature": True} # type: ignore
setup(
name=PACKAGE_NAME,
cmdclass=CMDCLASS,
ext_modules=cythonize(PYRFC_EXT, annotate=True) if build_cython else [PYRFC_EXT],
test_suite="tests",
)