koffi 2.3.5 → 2.3.6-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +4 -4
- package/src/cnoke/cnoke.js +40 -834
- package/src/cnoke/package.json +1 -0
- package/src/cnoke/src/builder.js +448 -0
- package/src/cnoke/src/index.js +20 -0
- package/src/cnoke/src/tools.js +401 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_arm64/koffi.exp +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_arm64/koffi.lib +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_arm64/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_ia32/koffi.exp +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_ia32/koffi.lib +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_ia32/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_x64/koffi.exp +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_x64/koffi.lib +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.2/koffi_win32_x64/koffi.pdb +0 -0
- package/src/koffi/src/ffi.cc +2 -2
- package/src/koffi/src/index.d.ts +3 -3
- package/src/koffi/src/index.js +23 -4
- package/src/koffi/build/2.3.5/koffi_darwin_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_darwin_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_freebsd_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_freebsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_freebsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_arm32hf.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_linux_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_openbsd_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_openbsd_x64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_win32_arm64.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_win32_ia32.tar.gz +0 -0
- package/src/koffi/build/2.3.5/koffi_win32_x64.tar.gz +0 -0
package/src/cnoke/package.json
CHANGED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
// This program is free software: you can redistribute it and/or modify
|
|
2
|
+
// it under the terms of the GNU Lesser General Public License as published by
|
|
3
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
4
|
+
// (at your option) any later version.
|
|
5
|
+
//
|
|
6
|
+
// This program is distributed in the hope that it will be useful,
|
|
7
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
9
|
+
// GNU Lesser General Public License for more details.
|
|
10
|
+
//
|
|
11
|
+
// You should have received a copy of the GNU Lesser General Public License
|
|
12
|
+
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const os = require('os');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const { spawnSync } = require('child_process');
|
|
20
|
+
const tools = require('./tools.js');
|
|
21
|
+
|
|
22
|
+
function Builder(config = {}) {
|
|
23
|
+
let self = this;
|
|
24
|
+
|
|
25
|
+
let app_dir = config.app_dir;
|
|
26
|
+
let project_dir = config.project_dir;
|
|
27
|
+
let package_dir = null;
|
|
28
|
+
|
|
29
|
+
if (app_dir == null)
|
|
30
|
+
app_dir = path.join(__dirname.replace(/\\/g, '/'), '..');
|
|
31
|
+
if (project_dir == null)
|
|
32
|
+
project_dir = process.cwd();
|
|
33
|
+
app_dir = app_dir.replace(/\\/g, '/');
|
|
34
|
+
project_dir = project_dir.replace(/\\/g, '/');
|
|
35
|
+
package_dir = find_parent_directory(project_dir, 'package.json');
|
|
36
|
+
|
|
37
|
+
let runtime_version = config.runtime_version;
|
|
38
|
+
let arch = config.arch;
|
|
39
|
+
let toolset = config.toolset || null;
|
|
40
|
+
let prefer_clang = config.prefer_clang || false;
|
|
41
|
+
let mode = config.mode;
|
|
42
|
+
let targets = config.targets || [];
|
|
43
|
+
let verbose = config.verbose || false;
|
|
44
|
+
let prebuild = config.prebuild || false;
|
|
45
|
+
|
|
46
|
+
if (runtime_version == null)
|
|
47
|
+
runtime_version = process.version;
|
|
48
|
+
if (runtime_version.startsWith('v'))
|
|
49
|
+
runtime_version = runtime_version.substr(1);
|
|
50
|
+
if (arch == null)
|
|
51
|
+
arch = tools.determine_arch();
|
|
52
|
+
if (mode == null)
|
|
53
|
+
throw new Error('Missing required mode setting');
|
|
54
|
+
|
|
55
|
+
let cache_dir = get_cache_directory();
|
|
56
|
+
let build_dir = config.build_dir;
|
|
57
|
+
let work_dir = null;
|
|
58
|
+
|
|
59
|
+
if (build_dir == null) {
|
|
60
|
+
let pkg = read_package_json();
|
|
61
|
+
|
|
62
|
+
if (pkg.cnoke.output != null) {
|
|
63
|
+
build_dir = expand_path(pkg.cnoke.output);
|
|
64
|
+
|
|
65
|
+
if (!tools.path_is_absolute(build_dir))
|
|
66
|
+
build_dir = path.join(project_dir, build_dir);
|
|
67
|
+
} else {
|
|
68
|
+
build_dir = project_dir + '/build';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
work_dir = build_dir + `/v${runtime_version}_${arch}`;
|
|
72
|
+
|
|
73
|
+
let cmake_bin = null;
|
|
74
|
+
|
|
75
|
+
this.configure = async function(retry = true) {
|
|
76
|
+
let args = [project_dir];
|
|
77
|
+
|
|
78
|
+
check_cmake();
|
|
79
|
+
check_compatibility();
|
|
80
|
+
|
|
81
|
+
console.log(`>> Node: ${runtime_version}`);
|
|
82
|
+
console.log(`>> Target: ${process.platform}_${arch}`);
|
|
83
|
+
|
|
84
|
+
// Prepare build directory
|
|
85
|
+
fs.mkdirSync(cache_dir, { recursive: true, mode: 0o755 });
|
|
86
|
+
fs.mkdirSync(build_dir, { recursive: true, mode: 0o755 });
|
|
87
|
+
fs.mkdirSync(work_dir, { recursive: true, mode: 0o755 });
|
|
88
|
+
|
|
89
|
+
retry &= fs.existsSync(work_dir + '/CMakeCache.txt');
|
|
90
|
+
|
|
91
|
+
// Download Node headers
|
|
92
|
+
{
|
|
93
|
+
let basename = `node-v${runtime_version}-headers.tar.gz`;
|
|
94
|
+
let urls = [
|
|
95
|
+
`https://nodejs.org/dist/v${runtime_version}/${basename}`,
|
|
96
|
+
`https://unofficial-builds.nodejs.org/download/release/v${runtime_version}/${basename}`
|
|
97
|
+
];
|
|
98
|
+
let destname = `${cache_dir}/${basename}`;
|
|
99
|
+
|
|
100
|
+
if (!fs.existsSync(destname))
|
|
101
|
+
await tools.download_http(urls, destname);
|
|
102
|
+
await tools.extract_targz(destname, work_dir + '/headers', 1);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Download Node import library (Windows)
|
|
106
|
+
if (process.platform === 'win32') {
|
|
107
|
+
let dirname;
|
|
108
|
+
switch (arch) {
|
|
109
|
+
case 'ia32': { dirname = 'win-x86'; } break;
|
|
110
|
+
case 'x64': { dirname = 'win-x64'; } break;
|
|
111
|
+
case 'arm64': { dirname = 'win-arm64'; } break;
|
|
112
|
+
|
|
113
|
+
default: {
|
|
114
|
+
throw new Error(`Unsupported architecture '${arch}' for Node on Windows`);
|
|
115
|
+
} break;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let destname = `${cache_dir}/node_v${runtime_version}_${arch}.lib`;
|
|
119
|
+
|
|
120
|
+
if (!fs.existsSync(destname)) {
|
|
121
|
+
let urls = [
|
|
122
|
+
`https://nodejs.org/dist/v${runtime_version}/${dirname}/node.lib`,
|
|
123
|
+
`https://unofficial-builds.nodejs.org/download/release/v${runtime_version}/${dirname}/node.lib`
|
|
124
|
+
];
|
|
125
|
+
await tools.download_http(urls, destname);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fs.copyFileSync(destname, work_dir + '/node.lib');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
args.push(`-DCMAKE_MODULE_PATH=${app_dir}/assets`);
|
|
132
|
+
|
|
133
|
+
args.push(`-DNODE_JS_INCLUDE_DIRS=${work_dir}/headers/include/node`);
|
|
134
|
+
|
|
135
|
+
// Set platform flags
|
|
136
|
+
switch (process.platform) {
|
|
137
|
+
case 'win32': {
|
|
138
|
+
fs.copyFileSync(`${app_dir}/assets/win_delay_hook.c`, work_dir + '/win_delay_hook.c');
|
|
139
|
+
|
|
140
|
+
args.push(`-DNODE_JS_SOURCES=${work_dir}/win_delay_hook.c`);
|
|
141
|
+
args.push(`-DNODE_JS_LIBRARIES=${work_dir}/node.lib`);
|
|
142
|
+
|
|
143
|
+
switch (arch) {
|
|
144
|
+
case 'ia32': {
|
|
145
|
+
args.push('-DNODE_JS_LINK_FLAGS=/DELAYLOAD:node.exe;/SAFESEH:NO');
|
|
146
|
+
args.push('-A', 'Win32');
|
|
147
|
+
} break;
|
|
148
|
+
case 'arm64': {
|
|
149
|
+
args.push('-DNODE_JS_LINK_FLAGS=/DELAYLOAD:node.exe;/SAFESEH:NO');
|
|
150
|
+
args.push('-A', 'ARM64');
|
|
151
|
+
} break;
|
|
152
|
+
case 'x64': {
|
|
153
|
+
args.push('-DNODE_JS_LINK_FLAGS=/DELAYLOAD:node.exe');
|
|
154
|
+
args.push('-A', 'x64');
|
|
155
|
+
} break;
|
|
156
|
+
}
|
|
157
|
+
} break;
|
|
158
|
+
|
|
159
|
+
case 'darwin': {
|
|
160
|
+
args.push('-DNODE_JS_LINK_FLAGS=-undefined;dynamic_lookup');
|
|
161
|
+
|
|
162
|
+
switch (arch) {
|
|
163
|
+
case 'arm64': { args.push('-DCMAKE_OSX_ARCHITECTURES=arm64'); } break;
|
|
164
|
+
case 'x64': { args.push('-DCMAKE_OSX_ARCHITECTURES=x86_64'); } break;
|
|
165
|
+
}
|
|
166
|
+
} break;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (process.platform != 'win32') {
|
|
170
|
+
// Prefer Ninja if available
|
|
171
|
+
if (spawnSync('ninja', ['--version']).status === 0)
|
|
172
|
+
args.push('-G', 'Ninja');
|
|
173
|
+
|
|
174
|
+
// Use CCache if available
|
|
175
|
+
if (spawnSync('ccache', ['--version']).status === 0) {
|
|
176
|
+
args.push('-DCMAKE_C_COMPILER_LAUNCHER=ccache');
|
|
177
|
+
args.push('-DCMAKE_CXX_COMPILER_LAUNCHER=ccache');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (prefer_clang) {
|
|
182
|
+
if (process.platform == 'win32') {
|
|
183
|
+
args.push('-T', 'ClangCL');
|
|
184
|
+
} else {
|
|
185
|
+
args.push('-DCMAKE_C_COMPILER=clang');
|
|
186
|
+
args.push('-DCMAKE_CXX_COMPILER=clang++');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (toolset != null)
|
|
190
|
+
args.push('-T', toolset);
|
|
191
|
+
|
|
192
|
+
args.push(`-DCMAKE_BUILD_TYPE=${mode}`);
|
|
193
|
+
for (let type of ['ARCHIVE', 'RUNTIME', 'LIBRARY']) {
|
|
194
|
+
for (let suffix of ['', '_DEBUG', '_RELEASE', '_RELWITHDEBINFO'])
|
|
195
|
+
args.push(`-DCMAKE_${type}_OUTPUT_DIRECTORY${suffix}=${build_dir}`);
|
|
196
|
+
}
|
|
197
|
+
args.push('--no-warn-unused-cli');
|
|
198
|
+
|
|
199
|
+
console.log('>> Running configuration');
|
|
200
|
+
|
|
201
|
+
let proc = spawnSync(cmake_bin, args, { cwd: work_dir, stdio: 'inherit' });
|
|
202
|
+
if (proc.status !== 0) {
|
|
203
|
+
tools.unlink_recursive(work_dir);
|
|
204
|
+
if (retry)
|
|
205
|
+
return self.configure(false);
|
|
206
|
+
|
|
207
|
+
throw new Error('Failed to run configure step');
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
this.build = async function() {
|
|
212
|
+
check_compatibility();
|
|
213
|
+
|
|
214
|
+
if (prebuild)
|
|
215
|
+
await check_prebuild();
|
|
216
|
+
|
|
217
|
+
check_cmake();
|
|
218
|
+
|
|
219
|
+
if (!fs.existsSync(work_dir + '/CMakeCache.txt'))
|
|
220
|
+
await self.configure();
|
|
221
|
+
|
|
222
|
+
// In case Make gets used
|
|
223
|
+
if (process.env.MAKEFLAGS == null)
|
|
224
|
+
process.env.MAKEFLAGS = '-j' + os.cpus().length;
|
|
225
|
+
|
|
226
|
+
let args = [
|
|
227
|
+
'--build', work_dir,
|
|
228
|
+
'--config', mode
|
|
229
|
+
];
|
|
230
|
+
|
|
231
|
+
if (verbose)
|
|
232
|
+
args.push('--verbose');
|
|
233
|
+
for (let target of targets)
|
|
234
|
+
args.push('--target', target);
|
|
235
|
+
|
|
236
|
+
console.log('>> Running build');
|
|
237
|
+
|
|
238
|
+
let proc = spawnSync(cmake_bin, args, { stdio: 'inherit' });
|
|
239
|
+
if (proc.status !== 0)
|
|
240
|
+
throw new Error('Failed to run build step');
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
async function check_prebuild() {
|
|
244
|
+
let pkg = read_package_json();
|
|
245
|
+
|
|
246
|
+
if (pkg.cnoke.prebuild != null) {
|
|
247
|
+
fs.mkdirSync(build_dir, { recursive: true, mode: 0o755 });
|
|
248
|
+
|
|
249
|
+
let url = expand_path(pkg.cnoke.prebuild);
|
|
250
|
+
let basename = path.basename(url);
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
let archive_filename = null;
|
|
254
|
+
|
|
255
|
+
if (url.startsWith('file:/')) {
|
|
256
|
+
if (url.startsWith('file://localhost/')) {
|
|
257
|
+
url = url.substr(16);
|
|
258
|
+
} else {
|
|
259
|
+
let offset = 6;
|
|
260
|
+
while (offset < 9 && url[offset] == '/')
|
|
261
|
+
offset++;
|
|
262
|
+
url = url.substr(offset - 1);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (process.platform == 'win32' && url.match(/^\/[a-zA-Z]+:[\\\/]/))
|
|
266
|
+
url = url.substr(1);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (url.match(/^[a-z]+:\/\//)) {
|
|
270
|
+
archive_filename = build_dir + '/' + basename;
|
|
271
|
+
await tools.download_http(url, archive_filename);
|
|
272
|
+
} else {
|
|
273
|
+
archive_filename = url;
|
|
274
|
+
|
|
275
|
+
if (!tools.path_is_absolute(archive_filename))
|
|
276
|
+
archive_filename = path.join(package_dir, archive_filename);
|
|
277
|
+
|
|
278
|
+
if (!fs.existsSync(archive_filename))
|
|
279
|
+
throw new Error('Cannot find local prebuilt archive');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
console.log('>> Extracting prebuilt binaries...');
|
|
283
|
+
await tools.extract_targz(archive_filename, build_dir, 1);
|
|
284
|
+
} catch (err) {
|
|
285
|
+
console.error('Failed to find prebuilt binary for your platform, building manually');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (pkg.cnoke.require != null) {
|
|
290
|
+
let binary_filename = expand_path(pkg.cnoke.require);
|
|
291
|
+
|
|
292
|
+
if (!tools.path_is_absolute(binary_filename))
|
|
293
|
+
binary_filename = path.join(package_dir, binary_filename);
|
|
294
|
+
|
|
295
|
+
if (fs.existsSync(binary_filename)) {
|
|
296
|
+
let proc = spawnSync(process.execPath, ['-e', 'require(process.argv[1])', binary_filename]);
|
|
297
|
+
if (proc.status === 0)
|
|
298
|
+
return false;
|
|
299
|
+
|
|
300
|
+
fs.unlinkSync(binary_filename);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
console.error('Failed to load prebuilt binary, rebuilding from source');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this.clean = function() {
|
|
310
|
+
tools.unlink_recursive(build_dir);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
function find_parent_directory(dirname, basename)
|
|
314
|
+
{
|
|
315
|
+
if (process.platform == 'win32')
|
|
316
|
+
dirname = dirname.replace(/\\/g, '/');
|
|
317
|
+
|
|
318
|
+
do {
|
|
319
|
+
if (fs.existsSync(dirname + '/' + basename))
|
|
320
|
+
return dirname;
|
|
321
|
+
|
|
322
|
+
dirname = path.dirname(dirname);
|
|
323
|
+
} while (!dirname.endsWith('/'));
|
|
324
|
+
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function get_cache_directory() {
|
|
329
|
+
if (process.platform == 'win32') {
|
|
330
|
+
let cache_dir = process.env['APPDATA'];
|
|
331
|
+
if (cache_dir == null)
|
|
332
|
+
throw new Error('Missing APPDATA environment variable');
|
|
333
|
+
|
|
334
|
+
cache_dir = path.join(cache_dir, 'cnoke');
|
|
335
|
+
return cache_dir;
|
|
336
|
+
} else {
|
|
337
|
+
let cache_dir = process.env['XDG_CACHE_HOME'];
|
|
338
|
+
|
|
339
|
+
if (cache_dir == null) {
|
|
340
|
+
let home = process.env['HOME'];
|
|
341
|
+
if (home == null)
|
|
342
|
+
throw new Error('Missing HOME environment variable');
|
|
343
|
+
|
|
344
|
+
cache_dir = path.join(home, '.cache');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
cache_dir = path.join(cache_dir, 'cnoke');
|
|
348
|
+
return cache_dir;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function check_cmake() {
|
|
353
|
+
if (cmake_bin != null)
|
|
354
|
+
return;
|
|
355
|
+
|
|
356
|
+
// Check for CMakeLists.txt
|
|
357
|
+
if (!fs.existsSync(project_dir + '/CMakeLists.txt'))
|
|
358
|
+
throw new Error('This directory does not appear to have a CMakeLists.txt file');
|
|
359
|
+
|
|
360
|
+
// Check for CMake
|
|
361
|
+
{
|
|
362
|
+
let proc = spawnSync('cmake', ['--version']);
|
|
363
|
+
|
|
364
|
+
if (proc.status === 0) {
|
|
365
|
+
cmake_bin = 'cmake';
|
|
366
|
+
} else {
|
|
367
|
+
if (process.platform == 'win32') {
|
|
368
|
+
// I really don't want to depend on anything in CNoke, and Node.js does not provide
|
|
369
|
+
// anything to read from the registry. This is okay, REG.exe exists since Windows XP.
|
|
370
|
+
let proc = spawnSync('reg', ['query', 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\CMake', '/v', 'InstallDir']);
|
|
371
|
+
|
|
372
|
+
if (proc.status === 0) {
|
|
373
|
+
let matches = proc.stdout.toString('utf-8').match(/InstallDir[ \t]+REG_[A-Z_]+[ \t]+(.*)+/);
|
|
374
|
+
|
|
375
|
+
if (matches != null) {
|
|
376
|
+
let bin = path.join(matches[1].trim(), 'bin\\cmake.exe');
|
|
377
|
+
|
|
378
|
+
if (fs.existsSync(bin))
|
|
379
|
+
cmake_bin = bin;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (cmake_bin == null)
|
|
385
|
+
throw new Error('CMake does not seem to be available');
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
console.log(`>> Using CMake binary: ${cmake_bin}`);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function check_compatibility() {
|
|
393
|
+
let pkg = read_package_json();
|
|
394
|
+
|
|
395
|
+
if (pkg.cnoke.node != null && tools.cmp_version(runtime_version, pkg.cnoke.node) < 0)
|
|
396
|
+
throw new Error(`Project ${pkg.name} requires Node.js >= ${pkg.cnoke.node}`);
|
|
397
|
+
|
|
398
|
+
if (pkg.cnoke.napi != null) {
|
|
399
|
+
let major = parseInt(runtime_version, 10);
|
|
400
|
+
let required = tools.get_napi_version(pkg.cnoke.napi, major);
|
|
401
|
+
|
|
402
|
+
if (required == null)
|
|
403
|
+
throw new Error(`Project ${pkg.name} does not support the Node ${major}.x branch (old or missing N-API)`);
|
|
404
|
+
if (tools.cmp_version(runtime_version, required) < 0)
|
|
405
|
+
throw new Error(`Project ${pkg.name} requires Node >= ${required} in the Node ${major}.x branch (with N-API >= ${pkg.engines.napi})`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function read_package_json() {
|
|
410
|
+
let pkg = {};
|
|
411
|
+
|
|
412
|
+
if (package_dir != null) {
|
|
413
|
+
try {
|
|
414
|
+
let json = fs.readFileSync(package_dir + '/package.json', { encoding: 'utf-8' });
|
|
415
|
+
pkg = JSON.parse(json);
|
|
416
|
+
} catch (err) {
|
|
417
|
+
if (err.code != 'ENOENT')
|
|
418
|
+
throw err;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (pkg.cnoke == null)
|
|
423
|
+
pkg.cnoke = {};
|
|
424
|
+
|
|
425
|
+
return pkg;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function expand_path(str) {
|
|
429
|
+
let ret = str.replace(/{{([a-zA-Z_][a-zA-Z_0-9]*)}}/g, (match, p1) => {
|
|
430
|
+
switch (p1) {
|
|
431
|
+
case 'version': {
|
|
432
|
+
let pkg = read_package_json();
|
|
433
|
+
return pkg.version || '';
|
|
434
|
+
} break;
|
|
435
|
+
case 'platform': return process.platform;
|
|
436
|
+
case 'arch': return arch;
|
|
437
|
+
|
|
438
|
+
default: return match;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
return ret;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
module.exports = {
|
|
447
|
+
Builder
|
|
448
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// This program is free software: you can redistribute it and/or modify
|
|
2
|
+
// it under the terms of the GNU Lesser General Public License as published by
|
|
3
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
4
|
+
// (at your option) any later version.
|
|
5
|
+
//
|
|
6
|
+
// This program is distributed in the hope that it will be useful,
|
|
7
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
8
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
9
|
+
// GNU Lesser General Public License for more details.
|
|
10
|
+
//
|
|
11
|
+
// You should have received a copy of the GNU Lesser General Public License
|
|
12
|
+
// along with this program. If not, see https://www.gnu.org/licenses/.
|
|
13
|
+
|
|
14
|
+
const { Builder } = require('./builder.js');
|
|
15
|
+
const tools = require('./tools.js');
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
Builder,
|
|
19
|
+
...tools
|
|
20
|
+
};
|