koffi 3.0.0-rc.2 → 3.0.0
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/cnoke.cjs +7 -7
- package/doc/benchmarks.md +25 -0
- package/package.json +15 -15
- package/src/koffi/index.cjs +10 -10
- package/src/koffi/index.js +7 -7
- package/src/koffi/indirect.cjs +10 -10
- package/src/koffi/indirect.js +7 -7
package/cnoke.cjs
CHANGED
|
@@ -22,16 +22,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
|
|
25
|
-
//
|
|
25
|
+
// ../cnoke/cnoke.js
|
|
26
26
|
var import_node_fs4 = __toESM(require("node:fs"), 1);
|
|
27
27
|
|
|
28
|
-
//
|
|
28
|
+
// ../cnoke/src/builder.js
|
|
29
29
|
var import_node_fs3 = __toESM(require("node:fs"), 1);
|
|
30
30
|
var import_node_os = __toESM(require("node:os"), 1);
|
|
31
31
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
32
32
|
var import_node_child_process = require("node:child_process");
|
|
33
33
|
|
|
34
|
-
//
|
|
34
|
+
// ../cnoke/src/abi.js
|
|
35
35
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
36
|
function determineAbi() {
|
|
37
37
|
let abi = process.arch;
|
|
@@ -121,7 +121,7 @@ function decodeElfHeader(buf) {
|
|
|
121
121
|
return header;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
//
|
|
124
|
+
// ../cnoke/src/util.js
|
|
125
125
|
var import_node_fs2 = __toESM(require("node:fs"), 1);
|
|
126
126
|
function pathIsAbsolute(path2) {
|
|
127
127
|
if (process.platform == "win32" && path2.match(/^[a-zA-Z]:/))
|
|
@@ -194,7 +194,7 @@ function compareVersions(ver1, ver2) {
|
|
|
194
194
|
return cmp;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
//
|
|
197
|
+
// ../cnoke/src/assets.js
|
|
198
198
|
var FIND_CNOKE_CMAKE = `# SPDX-License-Identifier: MIT
|
|
199
199
|
# SPDX-FileCopyrightText: 2026 Niels Martign\xE8ne <niels.martignene@protonmail.com>
|
|
200
200
|
|
|
@@ -361,7 +361,7 @@ const PfnDliHook __pfnDliNotifyHook2 = self_exe_hook;
|
|
|
361
361
|
#endif
|
|
362
362
|
`;
|
|
363
363
|
|
|
364
|
-
//
|
|
364
|
+
// ../cnoke/src/builder.js
|
|
365
365
|
var DefaultOptions = {
|
|
366
366
|
mode: "RelWithDebInfo"
|
|
367
367
|
};
|
|
@@ -650,7 +650,7 @@ function Builder(config = {}) {
|
|
|
650
650
|
}
|
|
651
651
|
}
|
|
652
652
|
|
|
653
|
-
//
|
|
653
|
+
// ../cnoke/cnoke.js
|
|
654
654
|
var VALID_COMMANDS = ["build", "configure", "clean"];
|
|
655
655
|
main();
|
|
656
656
|
async function main() {
|
package/doc/benchmarks.md
CHANGED
|
@@ -8,6 +8,7 @@ Here is a quick overview of the execution time of Koffi calls on three benchmark
|
|
|
8
8
|
|
|
9
9
|
<div class="benchmark chart" data-platform="linux_x64"></div>
|
|
10
10
|
<div class="benchmark chart" data-platform="win32_x64"></div>
|
|
11
|
+
<div class="benchmark chart" data-platform="darwin_arm64"></div>
|
|
11
12
|
|
|
12
13
|
These results are detailed and explained below, and compared to node-ffi/node-ffi-napi.
|
|
13
14
|
|
|
@@ -57,6 +58,30 @@ This test is based around repeated calls to the standard C function `memset`. Al
|
|
|
57
58
|
|
|
58
59
|
<div class="benchmark table" data-platform="win32_x64" data-benchmark="memset"></div>
|
|
59
60
|
|
|
61
|
+
# macOS ARM64
|
|
62
|
+
|
|
63
|
+
The results presented below were measured on an Apple Mac mini M2 hosted by Scaleway.
|
|
64
|
+
|
|
65
|
+
## rand results
|
|
66
|
+
|
|
67
|
+
This test is based around repeated calls to a simple standard C function `rand`, which takes no parameter and returns a 32-bit integer.
|
|
68
|
+
|
|
69
|
+
<div class="benchmark table" data-platform="darwin_arm64" data-benchmark="rand"></div>
|
|
70
|
+
|
|
71
|
+
Because rand is a pretty small function, the FFI overhead is clearly visible.
|
|
72
|
+
|
|
73
|
+
## atoi results
|
|
74
|
+
|
|
75
|
+
This test is similar to the rand one, but it is based on `atoi`, which takes a string parameter. Javascript (V8) to C string conversion is relatively slow and heavy.
|
|
76
|
+
|
|
77
|
+
<div class="benchmark table" data-platform="darwin_arm64" data-benchmark="atoi"></div>
|
|
78
|
+
|
|
79
|
+
## memset results
|
|
80
|
+
|
|
81
|
+
This test is based around repeated calls to the standard C function `memset`. All implementations pass a Node.js Buffer for the pointer argument.
|
|
82
|
+
|
|
83
|
+
<div class="benchmark table" data-platform="darwin_arm64" data-benchmark="memset"></div>
|
|
84
|
+
|
|
60
85
|
# Running benchmarks
|
|
61
86
|
|
|
62
87
|
Please note that all benchmark results on this page are made with Clang-built binaries.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koffi",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foreign",
|
|
@@ -33,20 +33,20 @@
|
|
|
33
33
|
},
|
|
34
34
|
"funding": "https://liberapay.com/Koromix",
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@koromix/koffi-linux-arm64": "3.0.0
|
|
37
|
-
"@koromix/koffi-linux-ia32": "3.0.0
|
|
38
|
-
"@koromix/koffi-linux-x64": "3.0.0
|
|
39
|
-
"@koromix/koffi-linux-riscv64": "3.0.0
|
|
40
|
-
"@koromix/koffi-freebsd-ia32": "3.0.0
|
|
41
|
-
"@koromix/koffi-freebsd-x64": "3.0.0
|
|
42
|
-
"@koromix/koffi-freebsd-arm64": "3.0.0
|
|
43
|
-
"@koromix/koffi-openbsd-ia32": "3.0.0
|
|
44
|
-
"@koromix/koffi-openbsd-x64": "3.0.0
|
|
45
|
-
"@koromix/koffi-win32-ia32": "3.0.0
|
|
46
|
-
"@koromix/koffi-win32-x64": "3.0.0
|
|
47
|
-
"@koromix/koffi-darwin-x64": "3.0.0
|
|
48
|
-
"@koromix/koffi-darwin-arm64": "3.0.0
|
|
49
|
-
"@koromix/koffi-linux-loong64": "3.0.0
|
|
36
|
+
"@koromix/koffi-linux-arm64": "3.0.0",
|
|
37
|
+
"@koromix/koffi-linux-ia32": "3.0.0",
|
|
38
|
+
"@koromix/koffi-linux-x64": "3.0.0",
|
|
39
|
+
"@koromix/koffi-linux-riscv64": "3.0.0",
|
|
40
|
+
"@koromix/koffi-freebsd-ia32": "3.0.0",
|
|
41
|
+
"@koromix/koffi-freebsd-x64": "3.0.0",
|
|
42
|
+
"@koromix/koffi-freebsd-arm64": "3.0.0",
|
|
43
|
+
"@koromix/koffi-openbsd-ia32": "3.0.0",
|
|
44
|
+
"@koromix/koffi-openbsd-x64": "3.0.0",
|
|
45
|
+
"@koromix/koffi-win32-ia32": "3.0.0",
|
|
46
|
+
"@koromix/koffi-win32-x64": "3.0.0",
|
|
47
|
+
"@koromix/koffi-darwin-x64": "3.0.0",
|
|
48
|
+
"@koromix/koffi-darwin-arm64": "3.0.0",
|
|
49
|
+
"@koromix/koffi-linux-loong64": "3.0.0"
|
|
50
50
|
},
|
|
51
51
|
"type": "module",
|
|
52
52
|
"main": "./index.cjs",
|
package/src/koffi/index.cjs
CHANGED
|
@@ -32,7 +32,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
));
|
|
33
33
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// ../cnoke/src/abi.js
|
|
36
36
|
function determineAbi() {
|
|
37
37
|
let abi = process.arch;
|
|
38
38
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
@@ -122,20 +122,20 @@ function decodeElfHeader(buf) {
|
|
|
122
122
|
}
|
|
123
123
|
var import_node_fs;
|
|
124
124
|
var init_abi = __esm({
|
|
125
|
-
"
|
|
125
|
+
"../cnoke/src/abi.js"() {
|
|
126
126
|
import_node_fs = __toESM(require("node:fs"), 1);
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
-
//
|
|
130
|
+
// package.json
|
|
131
131
|
var package_default;
|
|
132
132
|
var init_package = __esm({
|
|
133
|
-
"
|
|
134
|
-
package_default = { name: "koffi", version: "3.0.0
|
|
133
|
+
"package.json"() {
|
|
134
|
+
package_default = { name: "koffi", version: "3.0.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
// src/
|
|
138
|
+
// src/init.js
|
|
139
139
|
var init_exports = {};
|
|
140
140
|
__export(init_exports, {
|
|
141
141
|
detectPlatform: () => detectPlatform,
|
|
@@ -217,7 +217,7 @@ function wrapNative(native2) {
|
|
|
217
217
|
}
|
|
218
218
|
var import_node_util, import_node_fs2, import_node_module, requireNative;
|
|
219
219
|
var init_init = __esm({
|
|
220
|
-
"src/
|
|
220
|
+
"src/init.js"() {
|
|
221
221
|
import_node_util = __toESM(require("node:util"));
|
|
222
222
|
import_node_fs2 = __toESM(require("node:fs"));
|
|
223
223
|
import_node_module = require("node:module");
|
|
@@ -227,9 +227,9 @@ var init_init = __esm({
|
|
|
227
227
|
}
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
-
// src/
|
|
230
|
+
// src/static.js
|
|
231
231
|
var require_static = __commonJS({
|
|
232
|
-
"src/
|
|
232
|
+
"src/static.js"(exports2, module2) {
|
|
233
233
|
var { createRequire: createRequire2 } = require("node:module");
|
|
234
234
|
var requireNative2 = createRequire2(__filename);
|
|
235
235
|
var BINARY_ROOT2 = __dirname + "/../../build/koffi";
|
|
@@ -314,7 +314,7 @@ var require_static = __commonJS({
|
|
|
314
314
|
}
|
|
315
315
|
});
|
|
316
316
|
|
|
317
|
-
//
|
|
317
|
+
// index.cjs
|
|
318
318
|
var { detectPlatform: detectPlatform2, loadDynamic: loadDynamic2, wrapNative: wrapNative2 } = (init_init(), __toCommonJS(init_exports));
|
|
319
319
|
var { BINARY_ROOT, loadStatic } = require_static();
|
|
320
320
|
var [version, pkg, triplets] = detectPlatform2();
|
package/src/koffi/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/init.js
|
|
2
2
|
import util from "node:util";
|
|
3
3
|
import fs2 from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// ../cnoke/src/abi.js
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
function determineAbi() {
|
|
9
9
|
let abi = process.arch;
|
|
@@ -93,10 +93,10 @@ function decodeElfHeader(buf) {
|
|
|
93
93
|
return header;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
var package_default = { name: "koffi", version: "3.0.0
|
|
96
|
+
// package.json
|
|
97
|
+
var package_default = { name: "koffi", version: "3.0.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
98
98
|
|
|
99
|
-
// src/
|
|
99
|
+
// src/init.js
|
|
100
100
|
var requireNative = createRequire(import.meta.url);
|
|
101
101
|
function detectPlatform() {
|
|
102
102
|
if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
|
|
@@ -172,7 +172,7 @@ function wrapNative(native2) {
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
// src/
|
|
175
|
+
// src/static.js
|
|
176
176
|
import { createRequire as createRequire2 } from "node:module";
|
|
177
177
|
var requireNative2 = createRequire2(import.meta.url);
|
|
178
178
|
var BINARY_ROOT = import.meta.dirname + "/../../build/koffi";
|
|
@@ -251,7 +251,7 @@ function loadStatic(pkg2) {
|
|
|
251
251
|
return native2;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
//
|
|
254
|
+
// index.js
|
|
255
255
|
var [version, pkg, triplets] = detectPlatform();
|
|
256
256
|
var native = null;
|
|
257
257
|
STATIC: native = loadStatic(pkg);
|
package/src/koffi/indirect.cjs
CHANGED
|
@@ -32,7 +32,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
));
|
|
33
33
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
34
|
|
|
35
|
-
//
|
|
35
|
+
// ../cnoke/src/abi.js
|
|
36
36
|
function determineAbi() {
|
|
37
37
|
let abi = process.arch;
|
|
38
38
|
if (abi == "riscv32" || abi == "riscv64") {
|
|
@@ -122,20 +122,20 @@ function decodeElfHeader(buf) {
|
|
|
122
122
|
}
|
|
123
123
|
var import_node_fs;
|
|
124
124
|
var init_abi = __esm({
|
|
125
|
-
"
|
|
125
|
+
"../cnoke/src/abi.js"() {
|
|
126
126
|
import_node_fs = __toESM(require("node:fs"), 1);
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
-
//
|
|
130
|
+
// package.json
|
|
131
131
|
var package_default;
|
|
132
132
|
var init_package = __esm({
|
|
133
|
-
"
|
|
134
|
-
package_default = { name: "koffi", version: "3.0.0
|
|
133
|
+
"package.json"() {
|
|
134
|
+
package_default = { name: "koffi", version: "3.0.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
// src/
|
|
138
|
+
// src/init.js
|
|
139
139
|
var init_exports = {};
|
|
140
140
|
__export(init_exports, {
|
|
141
141
|
detectPlatform: () => detectPlatform,
|
|
@@ -217,7 +217,7 @@ function wrapNative(native2) {
|
|
|
217
217
|
}
|
|
218
218
|
var import_node_util, import_node_fs2, import_node_module, requireNative;
|
|
219
219
|
var init_init = __esm({
|
|
220
|
-
"src/
|
|
220
|
+
"src/init.js"() {
|
|
221
221
|
import_node_util = __toESM(require("node:util"));
|
|
222
222
|
import_node_fs2 = __toESM(require("node:fs"));
|
|
223
223
|
import_node_module = require("node:module");
|
|
@@ -227,9 +227,9 @@ var init_init = __esm({
|
|
|
227
227
|
}
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
-
// src/
|
|
230
|
+
// src/static.js
|
|
231
231
|
var require_static = __commonJS({
|
|
232
|
-
"src/
|
|
232
|
+
"src/static.js"(exports2, module2) {
|
|
233
233
|
var { createRequire: createRequire2 } = require("node:module");
|
|
234
234
|
var requireNative2 = createRequire2(__filename);
|
|
235
235
|
var BINARY_ROOT2 = __dirname + "/../../build/koffi";
|
|
@@ -314,7 +314,7 @@ var require_static = __commonJS({
|
|
|
314
314
|
}
|
|
315
315
|
});
|
|
316
316
|
|
|
317
|
-
//
|
|
317
|
+
// index.cjs
|
|
318
318
|
var { detectPlatform: detectPlatform2, loadDynamic: loadDynamic2, wrapNative: wrapNative2 } = (init_init(), __toCommonJS(init_exports));
|
|
319
319
|
var { BINARY_ROOT, loadStatic } = require_static();
|
|
320
320
|
var [version, pkg, triplets] = detectPlatform2();
|
package/src/koffi/indirect.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/init.js
|
|
2
2
|
import util from "node:util";
|
|
3
3
|
import fs2 from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// ../cnoke/src/abi.js
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
function determineAbi() {
|
|
9
9
|
let abi = process.arch;
|
|
@@ -93,10 +93,10 @@ function decodeElfHeader(buf) {
|
|
|
93
93
|
return header;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
var package_default = { name: "koffi", version: "3.0.0
|
|
96
|
+
// package.json
|
|
97
|
+
var package_default = { name: "koffi", version: "3.0.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
|
|
98
98
|
|
|
99
|
-
// src/
|
|
99
|
+
// src/init.js
|
|
100
100
|
var requireNative = createRequire(import.meta.url);
|
|
101
101
|
function detectPlatform() {
|
|
102
102
|
if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
|
|
@@ -172,12 +172,12 @@ function wrapNative(native2) {
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
// src/
|
|
175
|
+
// src/static.js
|
|
176
176
|
import { createRequire as createRequire2 } from "node:module";
|
|
177
177
|
var requireNative2 = createRequire2(import.meta.url);
|
|
178
178
|
var BINARY_ROOT = import.meta.dirname + "/../../build/koffi";
|
|
179
179
|
|
|
180
|
-
//
|
|
180
|
+
// index.js
|
|
181
181
|
var [version, pkg, triplets] = detectPlatform();
|
|
182
182
|
var native = null;
|
|
183
183
|
if (native == null)
|