koffi 2.5.15 → 2.5.17
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 +8 -3
- 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_arm32hf/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_riscv64hf64/koffi.node +0 -0
- package/build/koffi/linux_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_arm64/koffi.node +0 -0
- package/build/koffi/win32_ia32/koffi.node +0 -0
- package/build/koffi/win32_x64/koffi.node +0 -0
- package/doc/benchmarks.md +9 -9
- package/doc/start.md +1 -1
- package/package.json +3 -3
- package/src/cnoke/assets/win_delay_hook.c +12 -29
- package/src/cnoke/cnoke.js +11 -3
- package/src/cnoke/package.json +1 -1
- package/src/cnoke/src/builder.js +31 -11
- package/src/index.js +2 -2
- package/src/koffi/examples/electron-builder/package.json +1 -1
- package/src/koffi/examples/electron-forge/package.json +1 -1
- package/src/koffi/examples/node-esbuild/package.json +1 -1
- package/src/koffi/examples/nwjs/src/package.json +1 -1
- package/koffi-2.5.15.tgz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,15 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
### Koffi 2.5
|
|
6
6
|
|
|
7
|
-
#### Koffi 2.5.
|
|
7
|
+
#### Koffi 2.5.17 (2023-08-27)
|
|
8
8
|
|
|
9
|
-
-
|
|
9
|
+
- Fix compatibility with Electron
|
|
10
10
|
|
|
11
|
-
#### Koffi 2.5.
|
|
11
|
+
#### Koffi 2.5.16 (2023-08-25)
|
|
12
12
|
|
|
13
|
+
- Run Koffi tests through usual index.js entry point
|
|
13
14
|
- Fix DLL error when using Koffi from NW.js on Windows
|
|
14
15
|
- Simplify NW.js Koffi example
|
|
15
16
|
|
|
17
|
+
```{warning}
|
|
18
|
+
Pre-built binaries don't work correctly in Koffi 2.5.13 to 2.5.15, skip those versions.
|
|
19
|
+
```
|
|
20
|
+
|
|
16
21
|
#### Koffi 2.5.12 (2023-08-21)
|
|
17
22
|
|
|
18
23
|
- Fix native module bundling for FreeBSD ARM64 and Linux RISC-V 64
|
|
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
|
|
Binary file
|
package/doc/benchmarks.md
CHANGED
|
@@ -23,10 +23,10 @@ The results presented below were measured on my x86_64 Linux machine (Intel® Co
|
|
|
23
23
|
|
|
24
24
|
### rand results
|
|
25
25
|
|
|
26
|
-
This test is based around repeated calls to a simple standard C function
|
|
26
|
+
This test is based around repeated calls to a simple standard C function `rand`, and has three implementations:
|
|
27
27
|
|
|
28
|
-
- the first one is the reference, it calls
|
|
29
|
-
- the second one calls
|
|
28
|
+
- the first one is the reference, it calls rand through an N-API module, and is close to the theoretical limit of a perfect (no overhead) Node.js > C FFI implementation (pre-compiled static glue code)
|
|
29
|
+
- the second one calls rand through Koffi
|
|
30
30
|
- the third one uses the official Node.js FFI implementation, node-ffi-napi
|
|
31
31
|
|
|
32
32
|
Benchmark | Iteration time | Relative performance | Overhead
|
|
@@ -39,7 +39,7 @@ Because rand is a pretty small function, the FFI overhead is clearly visible.
|
|
|
39
39
|
|
|
40
40
|
### atoi results
|
|
41
41
|
|
|
42
|
-
This test is similar to the rand one, but it is based on atoi
|
|
42
|
+
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.
|
|
43
43
|
|
|
44
44
|
Benchmark | Iteration time | Relative performance | Overhead
|
|
45
45
|
------------- | -------------- | -------------------- | --------
|
|
@@ -51,7 +51,7 @@ Because atoi is a pretty small function, the FFI overhead is clearly visible.
|
|
|
51
51
|
|
|
52
52
|
### Raylib results
|
|
53
53
|
|
|
54
|
-
This benchmark uses the CPU-based image drawing functions in Raylib. The calls are much heavier than in
|
|
54
|
+
This benchmark uses the CPU-based image drawing functions in Raylib. The calls are much heavier than in previous benchmarks, thus the FFI overhead is reduced. In this implementation, Koffi is compared to:
|
|
55
55
|
|
|
56
56
|
- Baseline: Full C++ version of the code (no JS)
|
|
57
57
|
- [node-raylib](https://github.com/RobLoach/node-raylib): This is a native wrapper implemented with N-API
|
|
@@ -69,10 +69,10 @@ The results presented below were measured on my x86_64 Windows machine (Intel®
|
|
|
69
69
|
|
|
70
70
|
### rand results
|
|
71
71
|
|
|
72
|
-
This test is based around repeated calls to a simple standard C function
|
|
72
|
+
This test is based around repeated calls to a simple standard C function `rand`, and has three implementations:
|
|
73
73
|
|
|
74
|
-
- the first one is the reference, it calls
|
|
75
|
-
- the second one calls
|
|
74
|
+
- the first one is the reference, it calls rand through an N-API module, and is close to the theoretical limit of a perfect (no overhead) Node.js > C FFI implementation (pre-compiled static glue code)
|
|
75
|
+
- the second one calls rand through Koffi
|
|
76
76
|
- the third one uses the official Node.js FFI implementation, node-ffi-napi
|
|
77
77
|
|
|
78
78
|
Benchmark | Iteration time | Relative performance | Overhead
|
|
@@ -85,7 +85,7 @@ Because rand is a pretty small function, the FFI overhead is clearly visible.
|
|
|
85
85
|
|
|
86
86
|
### atoi results
|
|
87
87
|
|
|
88
|
-
This test is similar to the rand one, but it is based on atoi
|
|
88
|
+
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.
|
|
89
89
|
|
|
90
90
|
The results below were measured on my x86_64 Windows machine (Intel® Core™ i5-4460):
|
|
91
91
|
|
package/doc/start.md
CHANGED
|
@@ -20,7 +20,7 @@ import koffi from 'koffi';
|
|
|
20
20
|
|
|
21
21
|
## Simple examples
|
|
22
22
|
|
|
23
|
-
Below you can find
|
|
23
|
+
Below you can find two examples:
|
|
24
24
|
|
|
25
25
|
* The first one runs on Linux. The functions are declared with the C-like prototype language.
|
|
26
26
|
* The second one runs on Windows, and uses the node-ffi like syntax to declare functions.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koffi",
|
|
3
|
-
"version": "2.5.
|
|
4
|
-
"stable": "2.5.
|
|
3
|
+
"version": "2.5.17",
|
|
4
|
+
"stable": "2.5.17",
|
|
5
5
|
"description": "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"foreign",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"main": "src/index.js",
|
|
26
26
|
"types": "src/index.d.ts",
|
|
27
27
|
"scripts": {
|
|
28
|
-
"install": "node src/cnoke/cnoke.js
|
|
28
|
+
"install": "node src/cnoke/cnoke.js -p . -d src/koffi --prebuild"
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"cnoke": {
|
|
@@ -29,41 +29,24 @@
|
|
|
29
29
|
#include <windows.h>
|
|
30
30
|
#include <delayimp.h>
|
|
31
31
|
|
|
32
|
-
static HMODULE node_dll;
|
|
33
|
-
static HMODULE nw_dll;
|
|
34
|
-
|
|
35
32
|
static FARPROC WINAPI self_exe_hook(unsigned int event, DelayLoadInfo *info)
|
|
36
33
|
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (nw_dll) {
|
|
52
|
-
FARPROC ret = GetProcAddress(nw_dll, info->dlp.szProcName);
|
|
53
|
-
if (ret)
|
|
54
|
-
return ret;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (event == dliNotePreLoadLibrary && _stricmp(info->szDll, "node.exe") != 0) {
|
|
59
|
-
if (!node_dll) {
|
|
60
|
-
node_dll = GetModuleHandleA(NULL);
|
|
34
|
+
static const wchar_t *const NodeLibraries[] = {
|
|
35
|
+
L"node.dll",
|
|
36
|
+
NULL
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (event == dliNotePreLoadLibrary && !stricmp(info->szDll, "node.exe")) {
|
|
40
|
+
for (int i = 0; i < sizeof(NodeLibraries) / sizeof(*NodeLibraries); i++) {
|
|
41
|
+
const wchar_t *name = NodeLibraries[i];
|
|
42
|
+
HMODULE h = GetModuleHandleW(name);
|
|
43
|
+
|
|
44
|
+
if (h)
|
|
45
|
+
return (FARPROC)h;
|
|
61
46
|
}
|
|
62
|
-
return (FARPROC)node_dll;
|
|
63
47
|
}
|
|
64
48
|
|
|
65
49
|
return NULL;
|
|
66
50
|
}
|
|
67
51
|
|
|
68
52
|
const PfnDliHook __pfnDliNotifyHook2 = self_exe_hook;
|
|
69
|
-
const PfnDliHook __pfnDliFailureHook2 = self_exe_hook;
|
package/src/cnoke/cnoke.js
CHANGED
|
@@ -77,7 +77,12 @@ async function main() {
|
|
|
77
77
|
throw new Error(`Missing value for ${arg}`);
|
|
78
78
|
|
|
79
79
|
config.project_dir = fs.realpathSync(value);
|
|
80
|
-
} else if (arg == '-
|
|
80
|
+
} else if (arg == '-p' || arg == '--package') {
|
|
81
|
+
if (value == null)
|
|
82
|
+
throw new Error(`Missing value for ${arg}`);
|
|
83
|
+
|
|
84
|
+
config.package_dir = fs.realpathSync(value);
|
|
85
|
+
} else if (arg == '-O' || arg == '--out') {
|
|
81
86
|
if (value == null)
|
|
82
87
|
throw new Error(`Missing value for ${arg}`);
|
|
83
88
|
|
|
@@ -153,9 +158,12 @@ Commands:
|
|
|
153
158
|
clean Clean build files
|
|
154
159
|
|
|
155
160
|
Options:
|
|
156
|
-
-d, --directory <DIR> Change
|
|
161
|
+
-d, --directory <DIR> Change source directory
|
|
157
162
|
(default: current working directory)
|
|
158
|
-
-
|
|
163
|
+
-p, --package <DIR> Change package directory
|
|
164
|
+
(default: current working directory)
|
|
165
|
+
|
|
166
|
+
-O, --out <DIR> Set explicit output directory
|
|
159
167
|
(default: ./build)
|
|
160
168
|
|
|
161
169
|
-B, --config <CONFIG> Change build type: RelWithDebInfo, Debug, Release
|
package/src/cnoke/package.json
CHANGED
package/src/cnoke/src/builder.js
CHANGED
|
@@ -36,6 +36,7 @@ function Builder(config = {}) {
|
|
|
36
36
|
|
|
37
37
|
let app_dir = config.app_dir;
|
|
38
38
|
let project_dir = config.project_dir;
|
|
39
|
+
let package_dir = config.package_dir;
|
|
39
40
|
|
|
40
41
|
if (app_dir == null)
|
|
41
42
|
app_dir = __dirname.replace(/\\/g, '/') + '/..';
|
|
@@ -43,6 +44,9 @@ function Builder(config = {}) {
|
|
|
43
44
|
project_dir = process.cwd();
|
|
44
45
|
app_dir = app_dir.replace(/\\/g, '/');
|
|
45
46
|
project_dir = project_dir.replace(/\\/g, '/');
|
|
47
|
+
if (package_dir == null)
|
|
48
|
+
package_dir = project_dir;
|
|
49
|
+
package_dir = package_dir.replace(/\\/g, '/');
|
|
46
50
|
|
|
47
51
|
let runtime_version = config.runtime_version;
|
|
48
52
|
let arch = config.arch;
|
|
@@ -68,15 +72,14 @@ function Builder(config = {}) {
|
|
|
68
72
|
let pkg = read_package_json();
|
|
69
73
|
|
|
70
74
|
if (pkg.cnoke.output != null) {
|
|
71
|
-
build_dir = pkg.cnoke.output;
|
|
75
|
+
build_dir = expand_path(pkg.cnoke.output);
|
|
72
76
|
|
|
73
77
|
if (!tools.path_is_absolute(build_dir))
|
|
74
|
-
build_dir =
|
|
78
|
+
build_dir = package_dir + '/' + build_dir;
|
|
75
79
|
} else {
|
|
76
80
|
build_dir = project_dir + '/build';
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
|
-
build_dir = expand_path(build_dir);
|
|
80
83
|
work_dir = build_dir + `/v${runtime_version}_${arch}`;
|
|
81
84
|
|
|
82
85
|
let cmake_bin = null;
|
|
@@ -285,7 +288,7 @@ function Builder(config = {}) {
|
|
|
285
288
|
archive_filename = url;
|
|
286
289
|
|
|
287
290
|
if (!tools.path_is_absolute(archive_filename))
|
|
288
|
-
archive_filename = path.join(
|
|
291
|
+
archive_filename = path.join(package_dir, archive_filename);
|
|
289
292
|
|
|
290
293
|
if (!fs.existsSync(archive_filename))
|
|
291
294
|
throw new Error('Cannot find local prebuilt archive');
|
|
@@ -302,7 +305,7 @@ function Builder(config = {}) {
|
|
|
302
305
|
let require_filename = expand_path(pkg.cnoke.require);
|
|
303
306
|
|
|
304
307
|
if (!tools.path_is_absolute(require_filename))
|
|
305
|
-
require_filename = path.join(
|
|
308
|
+
require_filename = path.join(package_dir, require_filename);
|
|
306
309
|
|
|
307
310
|
if (fs.existsSync(require_filename)) {
|
|
308
311
|
let proc = spawnSync(process.execPath, ['-e', 'require(process.argv[1])', require_filename]);
|
|
@@ -320,6 +323,21 @@ function Builder(config = {}) {
|
|
|
320
323
|
tools.unlink_recursive(build_dir);
|
|
321
324
|
};
|
|
322
325
|
|
|
326
|
+
function find_parent_directory(dirname, basename)
|
|
327
|
+
{
|
|
328
|
+
if (process.platform == 'win32')
|
|
329
|
+
dirname = dirname.replace(/\\/g, '/');
|
|
330
|
+
|
|
331
|
+
do {
|
|
332
|
+
if (fs.existsSync(dirname + '/' + basename))
|
|
333
|
+
return dirname;
|
|
334
|
+
|
|
335
|
+
dirname = path.dirname(dirname);
|
|
336
|
+
} while (!dirname.endsWith('/'));
|
|
337
|
+
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
|
|
323
341
|
function get_cache_directory() {
|
|
324
342
|
if (process.platform == 'win32') {
|
|
325
343
|
let cache_dir = process.env['APPDATA'];
|
|
@@ -404,12 +422,14 @@ function Builder(config = {}) {
|
|
|
404
422
|
function read_package_json() {
|
|
405
423
|
let pkg = {};
|
|
406
424
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
425
|
+
if (package_dir != null) {
|
|
426
|
+
try {
|
|
427
|
+
let json = fs.readFileSync(package_dir + '/package.json', { encoding: 'utf-8' });
|
|
428
|
+
pkg = JSON.parse(json);
|
|
429
|
+
} catch (err) {
|
|
430
|
+
if (err.code != 'ENOENT')
|
|
431
|
+
throw err;
|
|
432
|
+
}
|
|
413
433
|
}
|
|
414
434
|
|
|
415
435
|
if (pkg.cnoke == null)
|
package/src/index.js
CHANGED
|
@@ -378,8 +378,8 @@ var require_package = __commonJS({
|
|
|
378
378
|
"build/dist/src/koffi/package.json"(exports2, module2) {
|
|
379
379
|
module2.exports = {
|
|
380
380
|
name: "koffi",
|
|
381
|
-
version: "2.5.
|
|
382
|
-
stable: "2.5.
|
|
381
|
+
version: "2.5.17",
|
|
382
|
+
stable: "2.5.17",
|
|
383
383
|
description: "Fast and simple C FFI (foreign function interface) for Node.js",
|
|
384
384
|
keywords: [
|
|
385
385
|
"foreign",
|
package/koffi-2.5.15.tgz
DELETED
|
Binary file
|