-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathbinding.gyp
More file actions
285 lines (285 loc) · 12.8 KB
/
Copy pathbinding.gyp
File metadata and controls
285 lines (285 loc) · 12.8 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
{
"conditions": [
[
'OS=="mac"',
{
"variables": {
"arch%": "<!(uname -m)",
"cflags_cpp": "gnu++20",
}
},
'OS=="linux"',
{
"variables": {
"cflags_cpp": "-std=c++20 -fexceptions",
"arch%": "<!(uname -m)",
}
},
'OS=="win"',
{
"variables": {
"cflags_cpp": "/std:c++20",
"arch%": "<!(node -e \"console.log(process.arch)\")",
},
},
]
],
"variables": {
"openssl_fips": "0",
# look for include files for these versions - taking top first priority
"msodbsver%": ["msodbcsql18", "msodbcsql17"],
"ext%": ".cpp",
"homebrew%": "/opt/homebrew/lib/libodbc.a",
"unixlocalodbc%": "-l/usr/local/odbc",
"linuxodbc%": "-lodbc",
"winodbc%": "odbc32",
# pick up libodbc from somwhere - note the ms driver is loaded
# dynamicaly via odbc, no
# link dependency is added
"linkdir%": "/usr/local/lib /usr/local/ssl/lib64/ /opt/homebrew/lib /home/linuxbrew/.linuxbrew/lib/ /usr/lib /usr/lib64 .",
},
"targets": [
{
# seems this is only way to add the cpp version flag
# on ms compiler - now needed for electron
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1,
"AdditionalOptions": [
"/std:c++20",
"/D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS"
],
}
},
"target_name": "sqlserver",
"make_global_settings": [
["make_flags", "-j2"]
],
"defines": [
# "NAPI_DISABLE_CPP_EXCEPTIONS",
# Uncomment the next line to use Node-API instead of NAN
# "CONNECTION_USE_NODE_API",
"BOUNDDATUM_USE_NODE_API",
],
"variables": {
# Set the target variable only if it is not passed in by prebuild
"target%": '<!(node -e "console.log(process.versions.node)")',
# Resolution order for napi_build_version, highest first:
# 1. -Dnapi_build_version=<N> on the gyp command line, which
# is how prebuild drives `-r napi` (prebuild/gypbuild.js:14).
# This is what our published prebuilds compile against, so
# the advertised binary.napi_versions floor is the real one.
# 2. build/config.gypi, inherited from the running Node's own
# config (e.g. "10" on Node 22). This is what a plain
# `node-gyp rebuild` -- the fallback half of our install
# script -- picks up, so source builds track the host.
# 3. The default below, a backstop so <(napi_build_version)
# always resolves and gyp never hard-errors on it.
# Keep in step with binary.napi_versions in package.json.
"napi_build_version%": 8,
# which folders are available for include eg.
# /opt/microsoft/msodbcsql18/include/ /opt/microsoft/msodbcsql17/include/
"msodbc_include_folders%": [
'<!@(node -p "'
"'<(msodbsver)'"
".split(' ')"
".map(x => ["
"'/opt/microsoft/' + x +'/include/'"
" ,"
"'/usr/local/opt/' + x + '/include/'"
" ,"
"'/usr/local/opt/' + x + '/include/' + x + '/'"
" ,"
"'/opt/homebrew/include/' + x + '/'"
" ,"
"'/home/linuxbrew/.linuxbrew/include/'"
"])"
".flatMap(y => y)"
".filter(z => require('fs').existsSync(z))"
".join(' ')"
'")'
],
# set fo
# the link folders available -L/usr/local/lib -L/usr/lib -L.
"link_path%": [
'<!@(node -p "'
"'<(linkdir)'"
".split(' ')"
".filter(x => require('fs')"
".existsSync(x))"
".map(x => '-L'+ x)"
".join(' ')"
'")'
], # set for macos based on silicon
# enumerate the cpp src files rather than name them.
"fileset%": [
'<!@(node -p "'
"['cpp/binding.cpp']"
".concat("
"require('fs').readdirSync('./cpp/src/common').map(f => 'cpp/src/common/'+f),"
"require('fs').readdirSync('./cpp/src/core').map(f => 'cpp/src/core/'+f),"
"require('fs').readdirSync('./cpp/src/js').map(f => 'cpp/src/js/'+f),"
"require('fs').readdirSync('./cpp/src/js/workers').map(f => 'cpp/src/js/workers/'+f),"
"require('fs').readdirSync('./cpp/src/js/columns').map(f => 'cpp/src/js/columns/'+f),"
"require('fs').readdirSync('./cpp/src/odbc').map(f => 'cpp/src/odbc/'+f),"
"require('fs').readdirSync('./cpp/src/utils').map(f => 'cpp/src/utils/'+f)"
")"
".filter(x => x.endsWith('<(ext)'))"
".join(' ')"
'")'
],
},
"sources": ["<!@(node -p \"'<(fileset)'" ".split(' ')" ".join(' ')\")"],
"include_dirs": [
"<!(node -p \"require('node-addon-api').include_dir\")",
"cpp",
"cpp/include",
"cpp/include/common",
"cpp/include/core",
"cpp/include/js",
"cpp/include/js/workers",
"cpp/include/js/columns",
"cpp/include/odbc",
"cpp/include/utils",
],
# NOTE: this is the *effective* defines block for the target. There
# is a second "defines" key earlier in this same dict; GYP parses
# the file as a Python dict literal, so the later key wins and the
# earlier one is silently discarded. Verified against
# build/sqlserver.target.mk: NODE_GYP_V4 is present,
# BOUNDDATUM_USE_NODE_API is not. Add defines here, not there.
"defines": [
"NODE_GYP_V4",
# Pin the N-API level so the ABI floor we advertise as
# binary.napi_versions is the one we actually compile against,
# rather than whatever the build headers happen to expose.
"NAPI_VERSION=<(napi_build_version)",
],
"actions": [
{
"action_name": "print_variables",
"action": [
"node", "-p",
"'compiler: ' + (process.platform === 'win32' ? 'MSVC' : (process.env.CXX || 'g++')) + ' | cflags_cpp <(cflags_cpp) | arch: <(arch) | link_path: <(link_path) | msodbc_include_folders <(msodbc_include_folders) | fileset <(fileset)'",
],
"inputs": [],
"outputs": ["<!@(node -p \"'<(fileset)'.split(' ')[0]\")"],
#'outputs': ['src/ConnectionHandles.cpp']
}
],
#
# currently for electron v20+ manually set the package.json
# for node_modules/prebuild dependencies (else code will not
# compile) - need to raise PR for prebuild
# cat .\package.json | grep gyp
# "node-gyp": "^9.1.0",
# "nw-gyp": "^3.6.3",
#
# also patch nan with https://github.com/VerteDinde/nan/tree/deprecate_accessor_signature
# whilst the PR is pending - this is only needed for electron v20 and
# above
#
"conditions": [
[
'target < "13.0"',
{
"defines": [
"PRE_V13",
],
},
],
[
'OS=="win"',
{
"link_settings": {
"libraries": ["<(winodbc)"],
},
"defines": [
"UNICODE=1",
"WINDOWS_BUILD",
"_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS",
# "BOUNDDATUM_USE_NODE_API",
# Uncomment the next line to use Node-API instead of NAN
# "CONNECTION_USE_NODE_API",
],
# Node distributions compiled with clang-cl + (thin) LTO
# (e.g. node 26 on Windows) leak -flto=thin / -flto=full
# and /opt:lldltojobs into addon builds via the node
# headers' common.gypi. MSVC's link.exe rejects
# /opt:lldltojobs (LNK1117: syntax error), failing the
# build. Strip the inherited LTO options from the MSVC
# tools - mirrors the "-fno-lto" handling for linux below.
"msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions!": ["-flto=thin", "-flto=full"],
"AdditionalOptions/": [["exclude", "flto"]],
},
"VCLibrarianTool": {
"AdditionalOptions!": ["-flto=thin", "-flto=full"],
"AdditionalOptions/": [["exclude", "flto|lldltojobs"]],
},
"VCLinkerTool": {
"AdditionalOptions!": [
"-flto=thin",
"-flto=full",
"/opt:lldltojobs=2",
],
"AdditionalOptions/": [["exclude", "flto|lldltojobs"]],
},
},
},
],
[
'OS=="linux"',
{
"link_settings": {
"libraries": [
"<!@(node -p \"'<(link_path)'.split(' ').join(' ')\")",
"<(linuxodbc)",
],
},
"defines": ["LINUX_BUILD", "UNICODE","NAPI_CPP_EXCEPTIONS"],
"cflags_cc": ["<(cflags_cpp)"],
"cflags": ["-U_FORTIFY_SOURCE", "-fno-lto"],
"conditions": [
['<!(which gcc-10 2>/dev/null && echo 1 || echo 0)'=='1', {
"make_global_settings": [
["CC", "gcc-10"],
["CXX", "g++-10"]
]
}]
],
"include_dirs": [
"<!@(node -p \"'<(msodbc_include_folders)'.split(' ').join(' ')\")",
"/usr/include/",
],
},
],
[
'OS=="mac"',
{
"link_settings": {
"libraries": [
"<(link_path)",
"<(linuxodbc)",
#'-lodbc'
],
},
"defines": ["LINUX_BUILD", "UNICODE", "NAPI_CPP_EXCEPTIONS"],
"xcode_settings": {
"CLANG_CXX_LANGUAGE_STANDARD": "<(cflags_cpp)",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_ENABLE_CPP_RTTI": "YES",
"OTHER_CPLUSPLUSFLAGS": ["-fexceptions"]
},
"include_dirs": [
"<!@(node -p \"'<(msodbc_include_folders)'.split(' ').join(' ')\")",
"/opt/homebrew/include",
"/usr/local/include/",
],
},
],
],
}
],
}