koffi 3.0.0-alpha.2 → 3.0.0-alpha.3
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/build/koffi/darwin_arm64/koffi.node +0 -0
- package/build/koffi/darwin_x64/koffi.node +0 -0
- package/build/koffi/freebsd_arm64/koffi.node +0 -0
- package/build/koffi/freebsd_ia32/koffi.node +0 -0
- package/build/koffi/freebsd_x64/koffi.node +0 -0
- package/build/koffi/linux_arm64/koffi.node +0 -0
- package/build/koffi/linux_ia32/koffi.node +0 -0
- package/build/koffi/linux_x64/koffi.node +0 -0
- package/build/koffi/musl_arm64/koffi.node +0 -0
- package/build/koffi/musl_x64/koffi.node +0 -0
- package/build/koffi/openbsd_ia32/koffi.node +0 -0
- package/build/koffi/openbsd_x64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/package.json +1 -1
- package/src/build.js +15 -377
- package/src/koffi/index.js +88 -88
- package/src/koffi/indirect.js +38 -38
- package/doc/benchmarks.xlsx +0 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/build.js
CHANGED
|
@@ -28,7 +28,7 @@ var import_fs4 = __toESM(require("fs"), 1);
|
|
|
28
28
|
// ../cnoke/src/builder.js
|
|
29
29
|
var import_fs3 = __toESM(require("fs"), 1);
|
|
30
30
|
var import_os = __toESM(require("os"), 1);
|
|
31
|
-
var
|
|
31
|
+
var import_path = __toESM(require("path"), 1);
|
|
32
32
|
var import_child_process = require("child_process");
|
|
33
33
|
|
|
34
34
|
// ../cnoke/src/abi.js
|
|
@@ -122,168 +122,11 @@ function decodeElfHeader(buf) {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// ../cnoke/src/util.js
|
|
125
|
-
var import_crypto = __toESM(require("crypto"), 1);
|
|
126
125
|
var import_fs2 = __toESM(require("fs"), 1);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
console.log(">> Downloading " + url);
|
|
132
|
-
let [tmp_name, file] = openTemporaryStream(dest);
|
|
133
|
-
try {
|
|
134
|
-
await new Promise((resolve, reject) => {
|
|
135
|
-
let request = import_https.default.get(url, (response) => {
|
|
136
|
-
if (response.statusCode != 200) {
|
|
137
|
-
let err = new Error(`Download failed: ${response.statusMessage} [${response.statusCode}]`);
|
|
138
|
-
err.code = response.statusCode;
|
|
139
|
-
reject(err);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
response.pipe(file);
|
|
143
|
-
file.on("finish", () => file.close(() => {
|
|
144
|
-
try {
|
|
145
|
-
import_fs2.default.renameSync(file.path, dest);
|
|
146
|
-
} catch (err) {
|
|
147
|
-
if (!import_fs2.default.existsSync(dest))
|
|
148
|
-
reject(err);
|
|
149
|
-
}
|
|
150
|
-
resolve();
|
|
151
|
-
}));
|
|
152
|
-
});
|
|
153
|
-
request.on("error", reject);
|
|
154
|
-
file.on("error", reject);
|
|
155
|
-
});
|
|
156
|
-
} catch (err) {
|
|
157
|
-
file.close();
|
|
158
|
-
try {
|
|
159
|
-
import_fs2.default.unlinkSync(tmp_name);
|
|
160
|
-
} catch (err2) {
|
|
161
|
-
if (err2.code != "ENOENT")
|
|
162
|
-
throw err2;
|
|
163
|
-
}
|
|
164
|
-
throw err;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function openTemporaryStream(prefix) {
|
|
168
|
-
let buf = Buffer.allocUnsafe(4);
|
|
169
|
-
for (; ; ) {
|
|
170
|
-
try {
|
|
171
|
-
import_crypto.default.randomFillSync(buf);
|
|
172
|
-
let suffix = buf.toString("hex").padStart(8, "0");
|
|
173
|
-
let filename = `${prefix}.${suffix}`;
|
|
174
|
-
let file = import_fs2.default.createWriteStream(filename, { flags: "wx", mode: 420 });
|
|
175
|
-
return [filename, file];
|
|
176
|
-
} catch (err) {
|
|
177
|
-
if (err.code != "EEXIST")
|
|
178
|
-
throw err;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function extractTarGz(filename, dest_dir, strip = 0) {
|
|
183
|
-
let reader = import_fs2.default.createReadStream(filename).pipe(import_zlib.default.createGunzip());
|
|
184
|
-
return new Promise((resolve, reject) => {
|
|
185
|
-
let header = null;
|
|
186
|
-
let extended = {};
|
|
187
|
-
reader.on("readable", () => {
|
|
188
|
-
try {
|
|
189
|
-
for (; ; ) {
|
|
190
|
-
if (header == null) {
|
|
191
|
-
let buf = reader.read(512);
|
|
192
|
-
if (buf == null)
|
|
193
|
-
break;
|
|
194
|
-
if (!buf[0])
|
|
195
|
-
continue;
|
|
196
|
-
header = {
|
|
197
|
-
filename: buf.toString("utf-8", 0, 100).replace(/\0/g, ""),
|
|
198
|
-
mode: parseInt(buf.toString("ascii", 100, 109), 8),
|
|
199
|
-
size: parseInt(buf.toString("ascii", 124, 137), 8),
|
|
200
|
-
type: String.fromCharCode(buf[156])
|
|
201
|
-
};
|
|
202
|
-
Object.assign(header, extended);
|
|
203
|
-
extended = {};
|
|
204
|
-
header.filename = header.filename.replace(/\\/g, "/");
|
|
205
|
-
if (!header.filename.length)
|
|
206
|
-
throw new Error(`Insecure empty filename inside TAR archive`);
|
|
207
|
-
if (pathIsAbsolute(header.filename[0]))
|
|
208
|
-
throw new Error(`Insecure filename starting with / inside TAR archive`);
|
|
209
|
-
if (pathHasDotDot(header.filename))
|
|
210
|
-
throw new Error(`Insecure filename containing '..' inside TAR archive`);
|
|
211
|
-
for (let i = 0; i < strip; i++)
|
|
212
|
-
header.filename = header.filename.substr(header.filename.indexOf("/") + 1);
|
|
213
|
-
}
|
|
214
|
-
let aligned = Math.floor((header.size + 511) / 512) * 512;
|
|
215
|
-
let data = header.size ? reader.read(aligned) : null;
|
|
216
|
-
if (data == null) {
|
|
217
|
-
if (header.size)
|
|
218
|
-
break;
|
|
219
|
-
data = Buffer.alloc(0);
|
|
220
|
-
}
|
|
221
|
-
data = data.subarray(0, header.size);
|
|
222
|
-
if (header.type == "0" || header.type == "7") {
|
|
223
|
-
let filename2 = dest_dir + "/" + header.filename;
|
|
224
|
-
let dirname = import_path.default.dirname(filename2);
|
|
225
|
-
import_fs2.default.mkdirSync(dirname, { recursive: true, mode: 493 });
|
|
226
|
-
import_fs2.default.writeFileSync(filename2, data, { mode: header.mode });
|
|
227
|
-
} else if (header.type == "5") {
|
|
228
|
-
let filename2 = dest_dir + "/" + header.filename;
|
|
229
|
-
import_fs2.default.mkdirSync(filename2, { recursive: true, mode: header.mode });
|
|
230
|
-
} else if (header.type == "L") {
|
|
231
|
-
extended.filename = data.toString("utf-8").replace(/\0/g, "");
|
|
232
|
-
} else if (header.type == "x") {
|
|
233
|
-
let str = data.toString("utf-8");
|
|
234
|
-
try {
|
|
235
|
-
while (str.length) {
|
|
236
|
-
let matches = str.match(/^([0-9]+) ([a-zA-Z0-9\._]+)=(.*)\n/);
|
|
237
|
-
let skip = parseInt(matches[1], 10);
|
|
238
|
-
let key = matches[2];
|
|
239
|
-
let value = matches[3];
|
|
240
|
-
switch (key) {
|
|
241
|
-
case "path":
|
|
242
|
-
{
|
|
243
|
-
extended.filename = value;
|
|
244
|
-
}
|
|
245
|
-
break;
|
|
246
|
-
case "size":
|
|
247
|
-
{
|
|
248
|
-
extended.size = parseInt(value, 10);
|
|
249
|
-
}
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
str = str.substr(skip).trimStart();
|
|
253
|
-
}
|
|
254
|
-
} catch (err) {
|
|
255
|
-
throw new Error("Malformed PAX entry");
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
header = null;
|
|
259
|
-
}
|
|
260
|
-
} catch (err) {
|
|
261
|
-
reject(err);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
reader.on("error", reject);
|
|
265
|
-
reader.on("end", resolve);
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
function pathIsAbsolute(path3) {
|
|
269
|
-
if (process.platform == "win32" && path3.match(/^[a-zA-Z]:/))
|
|
270
|
-
path3 = path3.substr(2);
|
|
271
|
-
return isPathSeparator(path3[0]);
|
|
272
|
-
}
|
|
273
|
-
function pathHasDotDot(path3) {
|
|
274
|
-
let start = 0;
|
|
275
|
-
for (; ; ) {
|
|
276
|
-
let offset = path3.indexOf("..", start);
|
|
277
|
-
if (offset < 0)
|
|
278
|
-
break;
|
|
279
|
-
start = offset + 2;
|
|
280
|
-
if (offset && !isPathSeparator(path3[offset - 1]))
|
|
281
|
-
continue;
|
|
282
|
-
if (offset + 2 < path3.length && !isPathSeparator(path3[offset + 2]))
|
|
283
|
-
continue;
|
|
284
|
-
return true;
|
|
285
|
-
}
|
|
286
|
-
return false;
|
|
126
|
+
function pathIsAbsolute(path2) {
|
|
127
|
+
if (process.platform == "win32" && path2.match(/^[a-zA-Z]:/))
|
|
128
|
+
path2 = path2.substr(2);
|
|
129
|
+
return isPathSeparator(path2[0]);
|
|
287
130
|
}
|
|
288
131
|
function isPathSeparator(c) {
|
|
289
132
|
if (c == "/")
|
|
@@ -314,9 +157,9 @@ function syncFiles(src_dir, dest_dir) {
|
|
|
314
157
|
}
|
|
315
158
|
}
|
|
316
159
|
}
|
|
317
|
-
function unlinkRecursive(
|
|
160
|
+
function unlinkRecursive(path2) {
|
|
318
161
|
try {
|
|
319
|
-
import_fs2.default.rmSync(
|
|
162
|
+
import_fs2.default.rmSync(path2, { recursive: true, maxRetries: process.platform == "win32" ? 3 : 0 });
|
|
320
163
|
} catch (err) {
|
|
321
164
|
if (err.code !== "ENOENT")
|
|
322
165
|
throw err;
|
|
@@ -518,128 +361,6 @@ const PfnDliHook __pfnDliNotifyHook2 = self_exe_hook;
|
|
|
518
361
|
#endif
|
|
519
362
|
`;
|
|
520
363
|
|
|
521
|
-
// ../cnoke/src/toolchains.json
|
|
522
|
-
var toolchains_default = {
|
|
523
|
-
linux_ia32: {
|
|
524
|
-
system: "Linux",
|
|
525
|
-
processor: "i386",
|
|
526
|
-
triplet: "i686-linux-gnu",
|
|
527
|
-
sysroot: "../../tools/cross/sysroots/debian_i386"
|
|
528
|
-
},
|
|
529
|
-
linux_x64: {
|
|
530
|
-
system: "Linux",
|
|
531
|
-
processor: "x86_64",
|
|
532
|
-
triplet: "x86_64-linux-gnu",
|
|
533
|
-
sysroot: "../../tools/cross/sysroots/debian_x64"
|
|
534
|
-
},
|
|
535
|
-
linux_armhf: {
|
|
536
|
-
system: "Linux",
|
|
537
|
-
processor: "arm",
|
|
538
|
-
triplet: "arm-linux-gnueabihf",
|
|
539
|
-
sysroot: "../../tools/cross/sysroots/debian_arm32"
|
|
540
|
-
},
|
|
541
|
-
linux_arm64: {
|
|
542
|
-
system: "Linux",
|
|
543
|
-
processor: "aarch64",
|
|
544
|
-
triplet: "aarch64-linux-gnu",
|
|
545
|
-
sysroot: "../../tools/cross/sysroots/debian_arm64"
|
|
546
|
-
},
|
|
547
|
-
linux_riscv64d: {
|
|
548
|
-
system: "Linux",
|
|
549
|
-
processor: "riscv64",
|
|
550
|
-
triplet: "riscv64-linux-gnu",
|
|
551
|
-
sysroot: "../../tools/cross/sysroots/debian_riscv64"
|
|
552
|
-
},
|
|
553
|
-
linux_loong64: {
|
|
554
|
-
system: "Linux",
|
|
555
|
-
processor: "loongarch64",
|
|
556
|
-
triplet: "loongarch64-linux-gnu",
|
|
557
|
-
sysroot: "../../tools/cross/sysroots/debian_loong64"
|
|
558
|
-
},
|
|
559
|
-
win32_ia32: {
|
|
560
|
-
system: "Windows",
|
|
561
|
-
processor: "X86",
|
|
562
|
-
lib: "win-x86",
|
|
563
|
-
flags: ["-DNODE_JS_LINK_FLAGS=/DELAYLOAD:node.exe;/SAFESEH:NO", "-A", "Win32"],
|
|
564
|
-
triplet: "i386-pc-windows-msvc",
|
|
565
|
-
linux: {
|
|
566
|
-
sysroot: "../../tools/cross/sysroots/windows_i386",
|
|
567
|
-
flags: ["-DNODE_JS_LINK_FLAGS=-Wl,/DELAYLOAD:node.exe,/SAFESEH:NO", "-DNODE_JS_DLLTOOL_MACHINE=i386"],
|
|
568
|
-
variables: {
|
|
569
|
-
CMAKE_DLLTOOL: "llvm-dlltool",
|
|
570
|
-
CMAKE_RC_COMPILER: "llvm-rc",
|
|
571
|
-
CMAKE_C_FLAGS: "-Xmicrosoft-windows-sys-root {{ sysroot }}",
|
|
572
|
-
CMAKE_CXX_FLAGS: "-Xmicrosoft-windows-sys-root {{ sysroot }}",
|
|
573
|
-
CMAKE_EXE_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/x86_64 -ldelayimp",
|
|
574
|
-
CMAKE_STATIC_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/x86_64 -ldelayimp",
|
|
575
|
-
CMAKE_SHARED_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/x86_64 -ldelayimp"
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
},
|
|
579
|
-
win32_x64: {
|
|
580
|
-
system: "Windows",
|
|
581
|
-
processor: "AMD64",
|
|
582
|
-
lib: "win-x64",
|
|
583
|
-
flags: ["-DNODE_JS_LINK_FLAGS=/DELAYLOAD:node.exe"],
|
|
584
|
-
triplet: "x86_64-pc-windows-msvc",
|
|
585
|
-
linux: {
|
|
586
|
-
sysroot: "../../tools/cross/sysroots/windows_x64",
|
|
587
|
-
flags: ["-DNODE_JS_LINK_FLAGS=-Wl,/DELAYLOAD:node.exe", "-DNODE_JS_DLLTOOL_MACHINE=i386:x86-64"],
|
|
588
|
-
variables: {
|
|
589
|
-
CMAKE_DLLTOOL: "llvm-dlltool",
|
|
590
|
-
CMAKE_RC_COMPILER: "llvm-rc",
|
|
591
|
-
CMAKE_C_FLAGS: "-Xmicrosoft-windows-sys-root {{ sysroot }}",
|
|
592
|
-
CMAKE_CXX_FLAGS: "-Xmicrosoft-windows-sys-root {{ sysroot }}",
|
|
593
|
-
CMAKE_EXE_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/x86_64 -ldelayimp",
|
|
594
|
-
CMAKE_STATIC_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/x86_64 -ldelayimp",
|
|
595
|
-
CMAKE_SHARED_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/x86_64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/x86_64 -ldelayimp"
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
},
|
|
599
|
-
win32_arm64: {
|
|
600
|
-
system: "Windows",
|
|
601
|
-
processor: "ARM64",
|
|
602
|
-
lib: "win-arm64",
|
|
603
|
-
flags: ["-DNODE_JS_LINK_FLAGS=/DELAYLOAD:node.exe;/SAFESEH:NO", "-A", "ARM64"],
|
|
604
|
-
triplet: "aarch64-pc-windows-msvc",
|
|
605
|
-
linux: {
|
|
606
|
-
sysroot: "../../tools/cross/sysroots/windows_arm64",
|
|
607
|
-
flags: ["-DNODE_JS_LINK_FLAGS=-Wl,/DELAYLOAD:node.exe,/SAFESEH:NO", "-DNODE_JS_DLLTOOL_MACHINE=arm64"],
|
|
608
|
-
variables: {
|
|
609
|
-
CMAKE_DLLTOOL: "llvm-dlltool",
|
|
610
|
-
CMAKE_RC_COMPILER: "llvm-rc",
|
|
611
|
-
CMAKE_C_FLAGS: "-Xmicrosoft-windows-sys-root {{ sysroot }}",
|
|
612
|
-
CMAKE_CXX_FLAGS: "-Xmicrosoft-windows-sys-root {{ sysroot }}",
|
|
613
|
-
CMAKE_EXE_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/aarch64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/aarch64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/aarch64 -ldelayimp",
|
|
614
|
-
CMAKE_STATIC_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/aarch64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/aarch64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/aarch64 -ldelayimp",
|
|
615
|
-
CMAKE_SHARED_LINKER_FLAGS: "-Wl,-libpath:{{ sysroot }}/VC/Tools/MSVC/Current/lib/aarch64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/ucrt/aarch64,-libpath:{{ sysroot }}/Kits/10/Lib/Current/um/aarch64 -ldelayimp"
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
},
|
|
619
|
-
darwin_x64: {
|
|
620
|
-
system: "Darwin",
|
|
621
|
-
processor: "x86_64",
|
|
622
|
-
flags: ["-DNODE_JS_LINK_FLAGS=-undefined;dynamic_lookup", "-DCMAKE_OSX_ARCHITECTURES=x86_64"]
|
|
623
|
-
},
|
|
624
|
-
darwin_arm64: {
|
|
625
|
-
system: "Darwin",
|
|
626
|
-
processor: "arm64",
|
|
627
|
-
flags: ["-DNODE_JS_LINK_FLAGS=-undefined;dynamic_lookup", "-DCMAKE_OSX_ARCHITECTURES=arm64"]
|
|
628
|
-
},
|
|
629
|
-
freebsd_x64: {
|
|
630
|
-
system: "FreeBSD",
|
|
631
|
-
processor: "amd64",
|
|
632
|
-
triplet: "x86_64-unknown-freebsd",
|
|
633
|
-
sysroot: "../../tools/cross/sysroots/freebsd_x64"
|
|
634
|
-
},
|
|
635
|
-
freebsd_arm64: {
|
|
636
|
-
system: "FreeBSD",
|
|
637
|
-
processor: "arm64",
|
|
638
|
-
triplet: "aarch64-unknown-freebsd",
|
|
639
|
-
sysroot: "../../tools/cross/sysroots/freebsd_arm64"
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
|
|
643
364
|
// ../cnoke/src/builder.js
|
|
644
365
|
var DefaultOptions = {
|
|
645
366
|
mode: "RelWithDebInfo"
|
|
@@ -668,10 +389,6 @@ function Builder(config = {}) {
|
|
|
668
389
|
runtime_version = process.version;
|
|
669
390
|
if (runtime_version.startsWith("v"))
|
|
670
391
|
runtime_version = runtime_version.substr(1);
|
|
671
|
-
UNSAFE: (() => {
|
|
672
|
-
if (toolchain != null && !Object.hasOwn(toolchains_default, toolchain))
|
|
673
|
-
throw new Error(`Unknown cross-compilation toolchain '${toolchain}'`);
|
|
674
|
-
})();
|
|
675
392
|
let options = null;
|
|
676
393
|
let cache_dir = getCacheDirectory();
|
|
677
394
|
let build_dir = config.build_dir;
|
|
@@ -703,17 +420,6 @@ function Builder(config = {}) {
|
|
|
703
420
|
args.push(`-DNODE_JS_EXECPATH=${process.execPath}`);
|
|
704
421
|
if (options2.api == null) {
|
|
705
422
|
let downloaded = false;
|
|
706
|
-
UNSAFE: await (async () => {
|
|
707
|
-
let destname = `${cache_dir}/node-v${runtime_version}-headers.tar.gz`;
|
|
708
|
-
if (!import_fs3.default.existsSync(destname)) {
|
|
709
|
-
import_fs3.default.mkdirSync(cache_dir, { recursive: true, mode: 493 });
|
|
710
|
-
let url = `https://nodejs.org/dist/v${runtime_version}/node-v${runtime_version}-headers.tar.gz`;
|
|
711
|
-
await downloadHttp(url, destname);
|
|
712
|
-
}
|
|
713
|
-
await extractTarGz(destname, work_dir + "/headers", 1);
|
|
714
|
-
downloaded = true;
|
|
715
|
-
args.push(`-DNODE_JS_INCLUDE_DIRS=${work_dir}/headers/include/node`);
|
|
716
|
-
})();
|
|
717
423
|
if (!downloaded)
|
|
718
424
|
throw new Error("Cannot download API headers");
|
|
719
425
|
} else {
|
|
@@ -731,18 +437,6 @@ function Builder(config = {}) {
|
|
|
731
437
|
} else {
|
|
732
438
|
if (options2.api == null) {
|
|
733
439
|
let downloaded = false;
|
|
734
|
-
UNSAFE: await (async () => {
|
|
735
|
-
let info = toolchains_default[toolchain ?? host];
|
|
736
|
-
let destname = `${cache_dir}/node_v${runtime_version}_${toolchain ?? host}.lib`;
|
|
737
|
-
if (!import_fs3.default.existsSync(destname)) {
|
|
738
|
-
import_fs3.default.mkdirSync(cache_dir, { recursive: true, mode: 493 });
|
|
739
|
-
let url = `https://nodejs.org/dist/v${runtime_version}/${info.lib}/node.lib`;
|
|
740
|
-
await downloadHttp(url, destname);
|
|
741
|
-
}
|
|
742
|
-
import_fs3.default.copyFileSync(destname, work_dir + "/node.lib");
|
|
743
|
-
args.push(`-DNODE_JS_LINK_LIB=${work_dir}/node.lib`);
|
|
744
|
-
downloaded = true;
|
|
745
|
-
})();
|
|
746
440
|
if (!downloaded)
|
|
747
441
|
throw new Error("Cannot download Node import library");
|
|
748
442
|
} else {
|
|
@@ -764,62 +458,6 @@ function Builder(config = {}) {
|
|
|
764
458
|
args.push("-DCMAKE_CXX_COMPILER_LAUNCHER=ccache");
|
|
765
459
|
}
|
|
766
460
|
}
|
|
767
|
-
UNSAFE: (() => {
|
|
768
|
-
let info = toolchains_default[toolchain ?? host];
|
|
769
|
-
if (info != null) {
|
|
770
|
-
if (Object.hasOwn(info, process.platform))
|
|
771
|
-
info = Object.assign({}, info, info[process.platform]);
|
|
772
|
-
if (info.flags != null)
|
|
773
|
-
args.push(...info.flags);
|
|
774
|
-
}
|
|
775
|
-
if (toolchain == null && process.arch == "ia32") {
|
|
776
|
-
let proc2 = (0, import_child_process.spawnSync)("uname", ["-m"]);
|
|
777
|
-
let machine = (proc2.stdout ?? "").toString("utf-8").trim();
|
|
778
|
-
if (machine == "x86_64") {
|
|
779
|
-
args.push("-DCMAKE_ASM_FLAGS=-m32", "-DCMAKE_C_FLAGS=-m32", "-DCMAKE_CXX_FLAGS=-m32");
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (toolchain != null && info.triplet != null) {
|
|
783
|
-
let values = [
|
|
784
|
-
["CMAKE_SYSTEM_NAME", info.system],
|
|
785
|
-
["CMAKE_SYSTEM_PROCESSOR", info.processor]
|
|
786
|
-
];
|
|
787
|
-
let sysroot = null;
|
|
788
|
-
if (process.platform != "win32" && !prefer_clang) {
|
|
789
|
-
let binary = info.triplet + "-gcc";
|
|
790
|
-
if ((0, import_child_process.spawnSync)(binary, ["-v"]).status !== 0)
|
|
791
|
-
prefer_clang = true;
|
|
792
|
-
}
|
|
793
|
-
if (prefer_clang) {
|
|
794
|
-
values.push(["CMAKE_ASM_COMPILER_TARGET", info.triplet]);
|
|
795
|
-
values.push(["CMAKE_C_COMPILER_TARGET", info.triplet]);
|
|
796
|
-
values.push(["CMAKE_CXX_COMPILER_TARGET", info.triplet]);
|
|
797
|
-
values.push(["CMAKE_EXE_LINKER_FLAGS", "-fuse-ld=lld"]);
|
|
798
|
-
values.push(["CMAKE_SHARED_LINKER_FLAGS", "-fuse-ld=lld"]);
|
|
799
|
-
values.push(["CMAKE_STATIC_LINKER_FLAGS", "-fuse-ld=lld"]);
|
|
800
|
-
} else if (process.platform != "win32") {
|
|
801
|
-
values.push(["CMAKE_ASM_COMPILER", info.triplet + "-gcc"]);
|
|
802
|
-
values.push(["CMAKE_C_COMPILER", info.triplet + "-gcc"]);
|
|
803
|
-
values.push(["CMAKE_CXX_COMPILER", info.triplet + "-g++"]);
|
|
804
|
-
}
|
|
805
|
-
if (info.sysroot != null) {
|
|
806
|
-
sysroot = expandPath(info.sysroot, __dirname + "/..");
|
|
807
|
-
if (!import_fs3.default.existsSync(sysroot))
|
|
808
|
-
throw new Error(`Cross-compilation sysroot '${sysroot}' does not exist`);
|
|
809
|
-
values.push(["CMAKE_SYSROOT", sysroot]);
|
|
810
|
-
}
|
|
811
|
-
if (info.variables != null) {
|
|
812
|
-
for (let key in info.variables) {
|
|
813
|
-
let value = expandString(info.variables[key], { sysroot });
|
|
814
|
-
values.push([key, value]);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
let filename = `${work_dir}/toolchain.cmake`;
|
|
818
|
-
let text = values.map((pair) => `set(${pair[0]} "${pair[1]}")`).join("\n");
|
|
819
|
-
import_fs3.default.writeFileSync(filename, text);
|
|
820
|
-
args.push(`-DCMAKE_TOOLCHAIN_FILE=${filename}`);
|
|
821
|
-
}
|
|
822
|
-
})();
|
|
823
461
|
if (prefer_clang) {
|
|
824
462
|
if (process.platform == "win32" && !mingw) {
|
|
825
463
|
args.push("-T", "ClangCL");
|
|
@@ -890,7 +528,7 @@ function Builder(config = {}) {
|
|
|
890
528
|
do {
|
|
891
529
|
if (import_fs3.default.existsSync(dirname + "/" + basename))
|
|
892
530
|
return dirname;
|
|
893
|
-
dirname =
|
|
531
|
+
dirname = import_path.default.dirname(dirname);
|
|
894
532
|
} while (!dirname.endsWith("/"));
|
|
895
533
|
return null;
|
|
896
534
|
}
|
|
@@ -899,7 +537,7 @@ function Builder(config = {}) {
|
|
|
899
537
|
let cache_dir2 = process.env["LOCALAPPDATA"] || process.env["APPDATA"];
|
|
900
538
|
if (cache_dir2 == null)
|
|
901
539
|
throw new Error("Missing LOCALAPPDATA and APPDATA environment variable");
|
|
902
|
-
cache_dir2 =
|
|
540
|
+
cache_dir2 = import_path.default.join(cache_dir2, "cnoke");
|
|
903
541
|
return cache_dir2;
|
|
904
542
|
} else {
|
|
905
543
|
let cache_dir2 = process.env["XDG_CACHE_HOME"];
|
|
@@ -907,9 +545,9 @@ function Builder(config = {}) {
|
|
|
907
545
|
let home = process.env["HOME"];
|
|
908
546
|
if (home == null)
|
|
909
547
|
throw new Error("Missing HOME environment variable");
|
|
910
|
-
cache_dir2 =
|
|
548
|
+
cache_dir2 = import_path.default.join(home, ".cache");
|
|
911
549
|
}
|
|
912
|
-
cache_dir2 =
|
|
550
|
+
cache_dir2 = import_path.default.join(cache_dir2, "cnoke");
|
|
913
551
|
return cache_dir2;
|
|
914
552
|
}
|
|
915
553
|
}
|
|
@@ -928,7 +566,7 @@ function Builder(config = {}) {
|
|
|
928
566
|
if (proc2.status === 0) {
|
|
929
567
|
let matches = proc2.stdout.toString("utf-8").match(/InstallDir[ \t]+REG_[A-Z_]+[ \t]+(.*)+/);
|
|
930
568
|
if (matches != null) {
|
|
931
|
-
let bin =
|
|
569
|
+
let bin = import_path.default.join(matches[1].trim(), "bin\\cmake.exe");
|
|
932
570
|
if (import_fs3.default.existsSync(bin))
|
|
933
571
|
cmake_bin = bin;
|
|
934
572
|
}
|
|
@@ -972,7 +610,7 @@ function Builder(config = {}) {
|
|
|
972
610
|
if (cnoke == null)
|
|
973
611
|
cnoke = pkg?.cnoke ?? {};
|
|
974
612
|
options = {
|
|
975
|
-
name: pkg?.name ??
|
|
613
|
+
name: pkg?.name ?? import_path.default.basename(project_dir),
|
|
976
614
|
version: pkg?.version ?? null,
|
|
977
615
|
directory,
|
|
978
616
|
...cnoke
|
|
@@ -1006,8 +644,8 @@ function Builder(config = {}) {
|
|
|
1006
644
|
function expandPath(str, root) {
|
|
1007
645
|
let expanded = expandString(str);
|
|
1008
646
|
if (!pathIsAbsolute(expanded))
|
|
1009
|
-
expanded =
|
|
1010
|
-
expanded =
|
|
647
|
+
expanded = import_path.default.join(root, expanded);
|
|
648
|
+
expanded = import_path.default.normalize(expanded);
|
|
1011
649
|
return expanded;
|
|
1012
650
|
}
|
|
1013
651
|
}
|
package/src/koffi/index.js
CHANGED
|
@@ -8,8 +8,8 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
8
8
|
var __esm = (fn, res) => function __init() {
|
|
9
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
10
|
};
|
|
11
|
-
var __commonJS = (cb,
|
|
12
|
-
return
|
|
11
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
12
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
13
13
|
};
|
|
14
14
|
var __export = (target, all) => {
|
|
15
15
|
for (var name in all)
|
|
@@ -23,22 +23,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
23
|
}
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
|
-
var __toESM = (
|
|
26
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
27
27
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
28
|
// file that has been converted to a CommonJS file using a Babel-
|
|
29
29
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
30
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !
|
|
32
|
-
|
|
31
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
32
|
+
mod2
|
|
33
33
|
));
|
|
34
|
-
var __toCommonJS = (
|
|
34
|
+
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
35
35
|
|
|
36
36
|
// ../cnoke/src/abi.js
|
|
37
37
|
var abi_exports = {};
|
|
38
38
|
__export(abi_exports, {
|
|
39
|
-
determineAbi: () =>
|
|
39
|
+
determineAbi: () => determineAbi
|
|
40
40
|
});
|
|
41
|
-
function
|
|
41
|
+
function determineAbi() {
|
|
42
42
|
let abi = process.arch;
|
|
43
43
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
44
44
|
let buf = readFileHeader(process.execPath, 512);
|
|
@@ -78,10 +78,10 @@ function determineAbi2() {
|
|
|
78
78
|
}
|
|
79
79
|
return abi;
|
|
80
80
|
}
|
|
81
|
-
function readFileHeader(
|
|
81
|
+
function readFileHeader(filename, read) {
|
|
82
82
|
let fd = null;
|
|
83
83
|
try {
|
|
84
|
-
let fd2 = import_fs.default.openSync(
|
|
84
|
+
let fd2 = import_fs.default.openSync(filename);
|
|
85
85
|
let buf = Buffer.allocUnsafe(read);
|
|
86
86
|
let len = import_fs.default.readSync(fd2, buf);
|
|
87
87
|
return buf.subarray(0, len);
|
|
@@ -137,7 +137,7 @@ var require_package = __commonJS({
|
|
|
137
137
|
"package.json"(exports2, module2) {
|
|
138
138
|
module2.exports = {
|
|
139
139
|
name: "koffi",
|
|
140
|
-
version: "3.0.0-alpha.
|
|
140
|
+
version: "3.0.0-alpha.3",
|
|
141
141
|
description: "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
142
142
|
keywords: [
|
|
143
143
|
"foreign",
|
|
@@ -180,66 +180,66 @@ var require_package = __commonJS({
|
|
|
180
180
|
|
|
181
181
|
// src/init.js
|
|
182
182
|
var require_init = __commonJS({
|
|
183
|
-
"src/init.js"(
|
|
183
|
+
"src/init.js"(exports2, module2) {
|
|
184
184
|
"use strict";
|
|
185
|
-
var
|
|
185
|
+
var fs2 = require("fs");
|
|
186
186
|
var path = require("path");
|
|
187
187
|
var util = require("util");
|
|
188
|
-
var { determineAbi } = (init_abi(), __toCommonJS(abi_exports));
|
|
188
|
+
var { determineAbi: determineAbi2 } = (init_abi(), __toCommonJS(abi_exports));
|
|
189
189
|
var PACKAGE = require_package();
|
|
190
|
-
function
|
|
190
|
+
function detect2() {
|
|
191
191
|
if (process.versions.napi == null || process.versions.napi < PACKAGE.cnoke.napi) {
|
|
192
192
|
let major = parseInt(process.versions.node, 10);
|
|
193
193
|
throw new Error(`This engine is based on Node ${process.versions.node}, but ${PACKAGE.name} does not support the Node ${major}.x branch (N-API < ${PACKAGE.cnoke.napi})`);
|
|
194
194
|
}
|
|
195
|
-
let abi =
|
|
196
|
-
let
|
|
197
|
-
let
|
|
195
|
+
let abi = determineAbi2();
|
|
196
|
+
let pkg2 = `${process.platform}-${process.arch}`;
|
|
197
|
+
let triplets2 = [`${process.platform}_${abi}`];
|
|
198
198
|
if (process.platform == "linux")
|
|
199
|
-
|
|
200
|
-
return [
|
|
199
|
+
triplets2.push(`musl_${abi}`);
|
|
200
|
+
return [pkg2, triplets2];
|
|
201
201
|
}
|
|
202
|
-
function
|
|
202
|
+
function init2(root, pkg2, triplets2, native2) {
|
|
203
203
|
let err = null;
|
|
204
|
-
if (
|
|
204
|
+
if (native2 == null) {
|
|
205
205
|
let roots = [root];
|
|
206
206
|
if (process.resourcesPath != null)
|
|
207
207
|
roots.push(process.resourcesPath);
|
|
208
|
-
let filenames = roots.flatMap((dir) =>
|
|
208
|
+
let filenames = roots.flatMap((dir) => triplets2.flatMap((triplet) => [
|
|
209
209
|
`${dir}/build/koffi/${triplet}/koffi.node`,
|
|
210
210
|
`${dir}/bin/Koffi/${triplet}/koffi.node`,
|
|
211
211
|
`${dir}/node_modules/koffi/build/koffi/${triplet}/koffi.node`,
|
|
212
|
-
`${dir}/../@koromix/koffi-${
|
|
212
|
+
`${dir}/../@koromix/koffi-${pkg2}/${triplet}/koffi.node`
|
|
213
213
|
]));
|
|
214
214
|
for (let filename of filenames) {
|
|
215
|
-
if (!
|
|
215
|
+
if (!fs2.existsSync(filename))
|
|
216
216
|
continue;
|
|
217
217
|
try {
|
|
218
|
-
|
|
218
|
+
native2 = require(filename);
|
|
219
219
|
break;
|
|
220
220
|
} catch (e) {
|
|
221
221
|
err ??= e;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
if (
|
|
225
|
+
if (native2 == null) {
|
|
226
226
|
err ??= new Error("Cannot find the native Koffi module; did you bundle it correctly?");
|
|
227
227
|
throw err;
|
|
228
228
|
}
|
|
229
|
-
if (
|
|
229
|
+
if (native2.version != PACKAGE.version)
|
|
230
230
|
throw new Error("Mismatched native Koffi modules");
|
|
231
|
-
let
|
|
232
|
-
return
|
|
231
|
+
let mod2 = wrap(native2);
|
|
232
|
+
return mod2;
|
|
233
233
|
}
|
|
234
|
-
function wrap(
|
|
234
|
+
function wrap(native2) {
|
|
235
235
|
let obj = {
|
|
236
|
-
...
|
|
236
|
+
...native2,
|
|
237
237
|
// Deprecated functions
|
|
238
|
-
handle: util.deprecate(
|
|
239
|
-
callback: util.deprecate(
|
|
238
|
+
handle: util.deprecate(native2.opaque, "The koffi.handle() function was deprecated in Koffi 2.1, use koffi.opaque() instead", "KOFFI001"),
|
|
239
|
+
callback: util.deprecate(native2.proto, "The koffi.callback() function was deprecated in Koffi 2.4, use koffi.proto() instead", "KOFFI002")
|
|
240
240
|
};
|
|
241
241
|
obj.load = (...args) => {
|
|
242
|
-
let lib =
|
|
242
|
+
let lib = native2.load(...args);
|
|
243
243
|
lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
|
|
244
244
|
lib.stdcall = util.deprecate((...args2) => lib.func("__stdcall", ...args2), 'The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func("__stdcall", ...) instead', "KOFFI004");
|
|
245
245
|
lib.fastcall = util.deprecate((...args2) => lib.func("__fastcall", ...args2), 'The koffi.fastcall() function was deprecated in Koffi 2.7, use koffi.func("__fastcall", ...) instead', "KOFFI005");
|
|
@@ -248,9 +248,9 @@ var require_init = __commonJS({
|
|
|
248
248
|
};
|
|
249
249
|
return obj;
|
|
250
250
|
}
|
|
251
|
-
|
|
252
|
-
detect,
|
|
253
|
-
init
|
|
251
|
+
module2.exports = {
|
|
252
|
+
detect: detect2,
|
|
253
|
+
init: init2
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
256
|
});
|
|
@@ -258,102 +258,102 @@ var require_init = __commonJS({
|
|
|
258
258
|
// src/static.js
|
|
259
259
|
var require_static = __commonJS({
|
|
260
260
|
"src/static.js"(exports2, module2) {
|
|
261
|
-
function find2(
|
|
262
|
-
let
|
|
263
|
-
if (
|
|
261
|
+
function find2(pkg2) {
|
|
262
|
+
let native2 = null;
|
|
263
|
+
if (native2 == null && pkg2 == "linux-arm64") {
|
|
264
264
|
try {
|
|
265
|
-
|
|
266
|
-
} catch (
|
|
265
|
+
native2 = require("../../build/koffi/linux_arm64/koffi.node");
|
|
266
|
+
} catch (err) {
|
|
267
267
|
}
|
|
268
268
|
}
|
|
269
|
-
if (
|
|
269
|
+
if (native2 == null && pkg2 == "linux-arm64") {
|
|
270
270
|
try {
|
|
271
|
-
|
|
272
|
-
} catch (
|
|
271
|
+
native2 = require("../../build/koffi/musl_arm64/koffi.node");
|
|
272
|
+
} catch (err) {
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
-
if (
|
|
275
|
+
if (native2 == null && pkg2 == "linux-ia32") {
|
|
276
276
|
try {
|
|
277
|
-
|
|
278
|
-
} catch (
|
|
277
|
+
native2 = require("../../build/koffi/linux_ia32/koffi.node");
|
|
278
|
+
} catch (err) {
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
if (
|
|
281
|
+
if (native2 == null && pkg2 == "linux-x64") {
|
|
282
282
|
try {
|
|
283
|
-
|
|
284
|
-
} catch (
|
|
283
|
+
native2 = require("../../build/koffi/linux_x64/koffi.node");
|
|
284
|
+
} catch (err) {
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
-
if (
|
|
287
|
+
if (native2 == null && pkg2 == "linux-x64") {
|
|
288
288
|
try {
|
|
289
|
-
|
|
290
|
-
} catch (
|
|
289
|
+
native2 = require("../../build/koffi/musl_x64/koffi.node");
|
|
290
|
+
} catch (err) {
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
if (
|
|
293
|
+
if (native2 == null && pkg2 == "freebsd-ia32") {
|
|
294
294
|
try {
|
|
295
|
-
|
|
296
|
-
} catch (
|
|
295
|
+
native2 = require("../../build/koffi/freebsd_ia32/koffi.node");
|
|
296
|
+
} catch (err) {
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
|
-
if (
|
|
299
|
+
if (native2 == null && pkg2 == "freebsd-x64") {
|
|
300
300
|
try {
|
|
301
|
-
|
|
302
|
-
} catch (
|
|
301
|
+
native2 = require("../../build/koffi/freebsd_x64/koffi.node");
|
|
302
|
+
} catch (err) {
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
|
-
if (
|
|
305
|
+
if (native2 == null && pkg2 == "freebsd-arm64") {
|
|
306
306
|
try {
|
|
307
|
-
|
|
308
|
-
} catch (
|
|
307
|
+
native2 = require("../../build/koffi/freebsd_arm64/koffi.node");
|
|
308
|
+
} catch (err) {
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
if (
|
|
311
|
+
if (native2 == null && pkg2 == "openbsd-ia32") {
|
|
312
312
|
try {
|
|
313
|
-
|
|
314
|
-
} catch (
|
|
313
|
+
native2 = require("../../build/koffi/openbsd_ia32/koffi.node");
|
|
314
|
+
} catch (err) {
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
|
-
if (
|
|
317
|
+
if (native2 == null && pkg2 == "openbsd-x64") {
|
|
318
318
|
try {
|
|
319
|
-
|
|
320
|
-
} catch (
|
|
319
|
+
native2 = require("../../build/koffi/openbsd_x64/koffi.node");
|
|
320
|
+
} catch (err) {
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
if (
|
|
323
|
+
if (native2 == null && pkg2 == "win32-ia32") {
|
|
324
324
|
try {
|
|
325
|
-
|
|
326
|
-
} catch (
|
|
325
|
+
native2 = require("../../build/koffi/win32_ia32/koffi.node");
|
|
326
|
+
} catch (err) {
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
|
-
if (
|
|
329
|
+
if (native2 == null && pkg2 == "win32-x64") {
|
|
330
330
|
try {
|
|
331
|
-
|
|
332
|
-
} catch (
|
|
331
|
+
native2 = require("../../build/koffi/win32_x64/koffi.node");
|
|
332
|
+
} catch (err) {
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
-
if (
|
|
335
|
+
if (native2 == null && pkg2 == "darwin-x64") {
|
|
336
336
|
try {
|
|
337
|
-
|
|
338
|
-
} catch (
|
|
337
|
+
native2 = require("../../build/koffi/darwin_x64/koffi.node");
|
|
338
|
+
} catch (err) {
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
|
-
if (
|
|
341
|
+
if (native2 == null && pkg2 == "darwin-arm64") {
|
|
342
342
|
try {
|
|
343
|
-
|
|
344
|
-
} catch (
|
|
343
|
+
native2 = require("../../build/koffi/darwin_arm64/koffi.node");
|
|
344
|
+
} catch (err) {
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
-
return
|
|
347
|
+
return native2;
|
|
348
348
|
}
|
|
349
349
|
module2.exports = { find: find2 };
|
|
350
350
|
}
|
|
351
351
|
});
|
|
352
352
|
|
|
353
353
|
// index.js
|
|
354
|
-
var { detect
|
|
354
|
+
var { detect, init } = require_init();
|
|
355
355
|
var { find } = require_static();
|
|
356
|
-
var [
|
|
357
|
-
var
|
|
358
|
-
var
|
|
359
|
-
module.exports =
|
|
356
|
+
var [pkg, triplets] = detect();
|
|
357
|
+
var native = find(pkg);
|
|
358
|
+
var mod = init(__dirname + "/../..", pkg, triplets, native);
|
|
359
|
+
module.exports = mod;
|
package/src/koffi/indirect.js
CHANGED
|
@@ -8,8 +8,8 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
8
8
|
var __esm = (fn, res) => function __init() {
|
|
9
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
10
|
};
|
|
11
|
-
var __commonJS = (cb,
|
|
12
|
-
return
|
|
11
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
12
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
13
13
|
};
|
|
14
14
|
var __export = (target, all) => {
|
|
15
15
|
for (var name in all)
|
|
@@ -23,22 +23,22 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
23
|
}
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
|
-
var __toESM = (
|
|
26
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
27
27
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
28
|
// file that has been converted to a CommonJS file using a Babel-
|
|
29
29
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
30
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !
|
|
32
|
-
|
|
31
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
32
|
+
mod2
|
|
33
33
|
));
|
|
34
|
-
var __toCommonJS = (
|
|
34
|
+
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
35
35
|
|
|
36
36
|
// ../cnoke/src/abi.js
|
|
37
37
|
var abi_exports = {};
|
|
38
38
|
__export(abi_exports, {
|
|
39
|
-
determineAbi: () =>
|
|
39
|
+
determineAbi: () => determineAbi
|
|
40
40
|
});
|
|
41
|
-
function
|
|
41
|
+
function determineAbi() {
|
|
42
42
|
let abi = process.arch;
|
|
43
43
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
44
44
|
let buf = readFileHeader(process.execPath, 512);
|
|
@@ -78,10 +78,10 @@ function determineAbi2() {
|
|
|
78
78
|
}
|
|
79
79
|
return abi;
|
|
80
80
|
}
|
|
81
|
-
function readFileHeader(
|
|
81
|
+
function readFileHeader(filename, read) {
|
|
82
82
|
let fd = null;
|
|
83
83
|
try {
|
|
84
|
-
let fd2 = import_fs.default.openSync(
|
|
84
|
+
let fd2 = import_fs.default.openSync(filename);
|
|
85
85
|
let buf = Buffer.allocUnsafe(read);
|
|
86
86
|
let len = import_fs.default.readSync(fd2, buf);
|
|
87
87
|
return buf.subarray(0, len);
|
|
@@ -134,42 +134,42 @@ var init_abi = __esm({
|
|
|
134
134
|
|
|
135
135
|
// src/init.js
|
|
136
136
|
var require_init = __commonJS({
|
|
137
|
-
"src/init.js"(
|
|
137
|
+
"src/init.js"(exports2, module2) {
|
|
138
138
|
"use strict";
|
|
139
|
-
var
|
|
139
|
+
var fs2 = require("fs");
|
|
140
140
|
var path = require("path");
|
|
141
141
|
var util = require("util");
|
|
142
|
-
var { determineAbi } = (init_abi(), __toCommonJS(abi_exports));
|
|
142
|
+
var { determineAbi: determineAbi2 } = (init_abi(), __toCommonJS(abi_exports));
|
|
143
143
|
var PACKAGE = require("./package.json");
|
|
144
|
-
function
|
|
144
|
+
function detect2() {
|
|
145
145
|
if (process.versions.napi == null || process.versions.napi < PACKAGE.cnoke.napi) {
|
|
146
146
|
let major = parseInt(process.versions.node, 10);
|
|
147
147
|
throw new Error(`This engine is based on Node ${process.versions.node}, but ${PACKAGE.name} does not support the Node ${major}.x branch (N-API < ${PACKAGE.cnoke.napi})`);
|
|
148
148
|
}
|
|
149
|
-
let abi =
|
|
150
|
-
let
|
|
151
|
-
let
|
|
149
|
+
let abi = determineAbi2();
|
|
150
|
+
let pkg2 = `${process.platform}-${process.arch}`;
|
|
151
|
+
let triplets2 = [`${process.platform}_${abi}`];
|
|
152
152
|
if (process.platform == "linux")
|
|
153
|
-
|
|
154
|
-
return [
|
|
153
|
+
triplets2.push(`musl_${abi}`);
|
|
154
|
+
return [pkg2, triplets2];
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function init2(root, pkg2, triplets2, native) {
|
|
157
157
|
let err = null;
|
|
158
158
|
if (native == null) {
|
|
159
159
|
let roots = [root];
|
|
160
160
|
if (process.resourcesPath != null)
|
|
161
161
|
roots.push(process.resourcesPath);
|
|
162
|
-
let filenames = roots.flatMap((dir) =>
|
|
162
|
+
let filenames = roots.flatMap((dir) => triplets2.flatMap((triplet) => [
|
|
163
163
|
`${dir}/build/koffi/${triplet}/koffi.node`,
|
|
164
164
|
`${dir}/bin/Koffi/${triplet}/koffi.node`,
|
|
165
165
|
`${dir}/node_modules/koffi/build/koffi/${triplet}/koffi.node`,
|
|
166
|
-
`${dir}/../@koromix/koffi-${
|
|
166
|
+
`${dir}/../@koromix/koffi-${pkg2}/${triplet}/koffi.node`
|
|
167
167
|
]));
|
|
168
168
|
for (let filename of filenames) {
|
|
169
|
-
if (!
|
|
169
|
+
if (!fs2.existsSync(filename))
|
|
170
170
|
continue;
|
|
171
171
|
try {
|
|
172
|
-
native =
|
|
172
|
+
native = require(filename);
|
|
173
173
|
break;
|
|
174
174
|
} catch (e) {
|
|
175
175
|
err ??= e;
|
|
@@ -182,18 +182,18 @@ var require_init = __commonJS({
|
|
|
182
182
|
}
|
|
183
183
|
if (native.version != PACKAGE.version)
|
|
184
184
|
throw new Error("Mismatched native Koffi modules");
|
|
185
|
-
let
|
|
186
|
-
return
|
|
185
|
+
let mod2 = wrap(native);
|
|
186
|
+
return mod2;
|
|
187
187
|
}
|
|
188
|
-
function wrap(
|
|
188
|
+
function wrap(native) {
|
|
189
189
|
let obj = {
|
|
190
|
-
...
|
|
190
|
+
...native,
|
|
191
191
|
// Deprecated functions
|
|
192
|
-
handle: util.deprecate(
|
|
193
|
-
callback: util.deprecate(
|
|
192
|
+
handle: util.deprecate(native.opaque, "The koffi.handle() function was deprecated in Koffi 2.1, use koffi.opaque() instead", "KOFFI001"),
|
|
193
|
+
callback: util.deprecate(native.proto, "The koffi.callback() function was deprecated in Koffi 2.4, use koffi.proto() instead", "KOFFI002")
|
|
194
194
|
};
|
|
195
195
|
obj.load = (...args) => {
|
|
196
|
-
let lib =
|
|
196
|
+
let lib = native.load(...args);
|
|
197
197
|
lib.cdecl = util.deprecate((...args2) => lib.func("__cdecl", ...args2), "The koffi.cdecl() function was deprecated in Koffi 2.7, use koffi.func(...) instead", "KOFFI003");
|
|
198
198
|
lib.stdcall = util.deprecate((...args2) => lib.func("__stdcall", ...args2), 'The koffi.stdcall() function was deprecated in Koffi 2.7, use koffi.func("__stdcall", ...) instead', "KOFFI004");
|
|
199
199
|
lib.fastcall = util.deprecate((...args2) => lib.func("__fastcall", ...args2), 'The koffi.fastcall() function was deprecated in Koffi 2.7, use koffi.func("__fastcall", ...) instead', "KOFFI005");
|
|
@@ -202,15 +202,15 @@ var require_init = __commonJS({
|
|
|
202
202
|
};
|
|
203
203
|
return obj;
|
|
204
204
|
}
|
|
205
|
-
|
|
206
|
-
detect,
|
|
207
|
-
init
|
|
205
|
+
module2.exports = {
|
|
206
|
+
detect: detect2,
|
|
207
|
+
init: init2
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
// indirect.js
|
|
213
|
-
var { detect
|
|
214
|
-
var [
|
|
215
|
-
var
|
|
216
|
-
module.exports =
|
|
213
|
+
var { detect, init } = require_init();
|
|
214
|
+
var [pkg, triplets] = detect();
|
|
215
|
+
var mod = init(__dirname + "/../..", pkg, triplets, null);
|
|
216
|
+
module.exports = mod;
|
package/doc/benchmarks.xlsx
DELETED
|
Binary file
|