koffi 2.14.1 → 2.15.1

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/koffi/darwin_x64/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  6. package/build/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm64/koffi.node +0 -0
  8. package/build/koffi/linux_armhf/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_loong64/koffi.node +0 -0
  11. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  12. package/build/koffi/linux_x64/koffi.node +0 -0
  13. package/build/koffi/musl_arm64/koffi.node +0 -0
  14. package/build/koffi/musl_x64/koffi.node +0 -0
  15. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  16. package/build/koffi/openbsd_x64/koffi.node +0 -0
  17. package/build/koffi/win32_arm64/koffi.node +0 -0
  18. package/build/koffi/win32_ia32/koffi.node +0 -0
  19. package/build/koffi/win32_x64/koffi.node +0 -0
  20. package/doc/assets.ini +2 -1
  21. package/doc/build.sh +9 -0
  22. package/doc/pages/404.md +17 -0
  23. package/doc/pages/index.md +5 -3
  24. package/doc/pages/misc.md +18 -11
  25. package/doc/pages.ini +4 -0
  26. package/doc/static/highlight.js +2 -14
  27. package/doc/static/koffi.css +3 -15
  28. package/doc/static/print.css +2 -14
  29. package/doc/templates/code.html +1 -2
  30. package/doc/templates/page.html +1 -2
  31. package/index.d.ts +29 -24
  32. package/index.js +9 -9
  33. package/indirect.js +9 -9
  34. package/{src/core → lib/native}/base/base.cc +1137 -674
  35. package/{src/core → lib/native}/base/base.hh +362 -195
  36. package/{src/core → lib/native}/base/crc.inc +2 -20
  37. package/lib/native/base/crc_gen.py +72 -0
  38. package/{src/core → lib/native}/base/mimetypes.inc +2 -20
  39. package/{src/core → lib/native}/base/mimetypes_gen.py +2 -21
  40. package/lib/native/base/tower.cc +821 -0
  41. package/lib/native/base/tower.hh +81 -0
  42. package/{src/core → lib/native}/base/unicode.inc +2 -20
  43. package/{src/core → lib/native}/base/unicode_gen.py +4 -41
  44. package/package.json +2 -2
  45. package/src/cnoke/assets/FindCNoke.cmake +24 -30
  46. package/src/cnoke/assets/win_delay_hook.c +6 -20
  47. package/src/cnoke/cnoke.js +2 -21
  48. package/src/cnoke/src/builder.js +51 -66
  49. package/src/cnoke/src/index.js +2 -20
  50. package/src/cnoke/src/tools.js +2 -20
  51. package/src/koffi/CMakeLists.txt +30 -23
  52. package/src/koffi/cmake/raylib.cmake +5 -22
  53. package/src/koffi/cmake/sqlite3.cmake +2 -20
  54. package/src/koffi/src/abi_arm32.cc +7 -25
  55. package/src/koffi/src/abi_arm32_asm.S +2 -20
  56. package/src/koffi/src/abi_arm64.cc +7 -25
  57. package/src/koffi/src/abi_arm64_asm.S +2 -20
  58. package/src/koffi/src/abi_arm64_asm.asm +2 -20
  59. package/src/koffi/src/abi_loong64.cc +2 -20
  60. package/src/koffi/src/abi_loong64_asm.S +2 -20
  61. package/src/koffi/src/abi_riscv64.cc +7 -25
  62. package/src/koffi/src/abi_riscv64_asm.S +2 -20
  63. package/src/koffi/src/abi_x64_sysv.cc +7 -25
  64. package/src/koffi/src/abi_x64_sysv_asm.S +2 -20
  65. package/src/koffi/src/abi_x64_win.cc +12 -30
  66. package/src/koffi/src/abi_x64_win_asm.S +162 -0
  67. package/src/koffi/src/abi_x64_win_asm.asm +2 -20
  68. package/src/koffi/src/abi_x86.cc +7 -25
  69. package/src/koffi/src/abi_x86_asm.S +2 -20
  70. package/src/koffi/src/abi_x86_asm.asm +2 -20
  71. package/src/koffi/src/call.cc +25 -45
  72. package/src/koffi/src/call.hh +3 -21
  73. package/src/koffi/src/errno.inc +2 -20
  74. package/src/koffi/src/ffi.cc +64 -63
  75. package/src/koffi/src/ffi.hh +15 -30
  76. package/src/koffi/src/init.js +2 -20
  77. package/src/koffi/src/parser.cc +13 -27
  78. package/src/koffi/src/parser.hh +3 -21
  79. package/src/koffi/src/trampolines/armasm.inc +0 -21
  80. package/src/koffi/src/trampolines/gnu.inc +0 -21
  81. package/src/koffi/src/trampolines/masm32.inc +0 -21
  82. package/src/koffi/src/trampolines/masm64.inc +0 -21
  83. package/src/koffi/src/trampolines/prototypes.inc +0 -21
  84. package/src/koffi/src/util.cc +50 -64
  85. package/src/koffi/src/util.hh +8 -25
  86. package/src/koffi/src/uv.cc +193 -0
  87. package/src/koffi/src/uv.def +10 -0
  88. package/src/koffi/src/uv.hh +40 -0
  89. package/src/koffi/src/win32.cc +2 -20
  90. package/src/koffi/src/win32.hh +3 -21
  91. package/vendor/node-api-headers/CHANGELOG.md +22 -0
  92. package/vendor/node-api-headers/README.md +6 -17
  93. package/vendor/node-api-headers/include/js_native_api.h +3 -13
  94. package/vendor/node-api-headers/include/js_native_api_types.h +15 -0
  95. package/vendor/node-api-headers/include/node_api.h +0 -4
  96. package/vendor/node-api-headers/include/node_api_types.h +6 -0
  97. package/vendor/node-api-headers/include/uv/aix.h +32 -0
  98. package/vendor/node-api-headers/include/uv/bsd.h +34 -0
  99. package/vendor/node-api-headers/include/uv/darwin.h +61 -0
  100. package/vendor/node-api-headers/include/uv/errno.h +483 -0
  101. package/vendor/node-api-headers/include/uv/linux.h +34 -0
  102. package/vendor/node-api-headers/include/uv/os390.h +33 -0
  103. package/vendor/node-api-headers/include/uv/posix.h +31 -0
  104. package/vendor/node-api-headers/include/uv/sunos.h +44 -0
  105. package/vendor/node-api-headers/include/uv/threadpool.h +37 -0
  106. package/vendor/node-api-headers/include/uv/tree.h +521 -0
  107. package/vendor/node-api-headers/include/uv/unix.h +512 -0
  108. package/vendor/node-api-headers/include/uv/version.h +43 -0
  109. package/vendor/node-api-headers/include/uv/win.h +698 -0
  110. package/vendor/node-api-headers/include/uv.h +1990 -0
  111. package/vendor/node-api-headers/package.json +1 -1
  112. package/vendor/node-api-headers/scripts/update-headers.js +6 -0
  113. package/src/core/base/crc_gen.py +0 -109
@@ -0,0 +1,81 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
3
+
4
+ #pragma once
5
+
6
+ #include "lib/native/base/base.hh"
7
+ #include "lib/native/wrap/json.hh"
8
+
9
+ namespace K {
10
+
11
+ static const int MaxTowerSources = 10;
12
+
13
+ class TowerServer {
14
+ #if defined(_WIN32)
15
+ char name[512] = {};
16
+ LocalArray<struct OverlappedPipe *, MaxTowerSources> pipes;
17
+ #else
18
+ int fd = -1;
19
+ #endif
20
+
21
+ LocalArray<WaitSource, MaxTowerSources> sources;
22
+
23
+ std::function<bool(StreamReader *, StreamWriter *)> handle_func;
24
+
25
+ public:
26
+ TowerServer() {}
27
+ ~TowerServer() { Stop(); }
28
+
29
+ bool Bind(const char *path);
30
+ void Start(std::function<bool(StreamReader *, StreamWriter *)> func);
31
+ void Stop();
32
+
33
+ Span<const WaitSource> GetWaitSources() const { return sources; }
34
+ bool Process(uint64_t ready = UINT64_MAX);
35
+
36
+ void Send(FunctionRef<void(StreamWriter *)> func);
37
+ void Send(Span<const uint8_t> buf) { Send([&](StreamWriter *writer) { writer->Write(buf); }); }
38
+ void Send(Span<const char> buf) { Send([&](StreamWriter *writer) { writer->Write(buf); }); }
39
+
40
+ private:
41
+ #if defined(_WIN32)
42
+ void RunClients(FunctionRef<bool(Size, struct OverlappedPipe *)> func);
43
+ #else
44
+ void RunClients(FunctionRef<bool(Size, int)> func);
45
+ #endif
46
+ };
47
+
48
+ class TowerClient {
49
+ #if defined(_WIN32)
50
+ struct OverlappedPipe *pipe = nullptr;
51
+ #else
52
+ int sock = -1;
53
+ #endif
54
+
55
+ std::function<void(StreamReader *)> handle_func;
56
+
57
+ WaitSource src = {};
58
+
59
+ public:
60
+ ~TowerClient() { Stop(); }
61
+
62
+ bool Connect(const char *path);
63
+ void Start(std::function<void(StreamReader *)> func);
64
+ void Stop();
65
+
66
+ WaitSource GetWaitSource() const { return src; }
67
+ bool Process();
68
+
69
+ bool Send(FunctionRef<void(StreamWriter *)> func);
70
+ bool Send(Span<const uint8_t> buf) { return Send([&](StreamWriter *writer) { writer->Write(buf); }); }
71
+ bool Send(Span<const char> buf) { return Send([&](StreamWriter *writer) { writer->Write(buf); }); }
72
+ };
73
+
74
+ enum class ControlScope {
75
+ System,
76
+ User
77
+ };
78
+
79
+ const char *GetControlSocketPath(ControlScope scope, const char *name, Allocator *alloc);
80
+
81
+ }
@@ -1,23 +1,5 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
-
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
-
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
-
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  // This file is autogenerated by unicode_gen.py
23
5
  // Version: DerivedCoreProperties-16.0.0.txt -- Date: 2024-05-31, 18:09:32 GMT
@@ -1,25 +1,6 @@
1
1
  #!/usr/bin/env python3
2
-
3
- # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
4
-
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- # this software and associated documentation files (the “Software”), to deal in
7
- # the Software without restriction, including without limitation the rights to use,
8
- # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9
- # Software, and to permit persons to whom the Software is furnished to do so,
10
- # subject to the following conditions:
11
-
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
-
15
- # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- # OTHER DEALINGS IN THE SOFTWARE.
2
+ # SPDX-License-Identifier: MIT
3
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
23
4
 
24
5
  import sys
25
6
  import re
@@ -30,26 +11,8 @@ from collections import namedtuple
30
11
 
31
12
  DEFAULT_URL = 'https://unicode.org/Public/16.0.0'
32
13
 
33
- LICENSE_HEADER = """// Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
34
-
35
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
36
- // this software and associated documentation files (the “Software”), to deal in
37
- // the Software without restriction, including without limitation the rights to use,
38
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
39
- // Software, and to permit persons to whom the Software is furnished to do so,
40
- // subject to the following conditions:
41
-
42
- // The above copyright notice and this permission notice shall be included in all
43
- // copies or substantial portions of the Software.
44
-
45
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
46
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
47
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
49
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
51
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
52
- // OTHER DEALINGS IN THE SOFTWARE."""
14
+ LICENSE_HEADER = """// SPDX-License-Identifier: MIT
15
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>"""
53
16
 
54
17
  WcWidthResult = namedtuple('WcWidthResult', ['null', 'wide'])
55
18
  XidResult = namedtuple('XidResult', ['id_start', 'id_continue'])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.14.1",
3
+ "version": "2.15.1",
4
4
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
5
5
  "keywords": [
6
6
  "foreign",
@@ -34,5 +34,5 @@
34
34
  "napi": 8,
35
35
  "require": "./index.js"
36
36
  },
37
- "funding": "https://buymeacoffee.com/koromix"
37
+ "funding": "https://liberapay.com/Koromix"
38
38
  }
@@ -1,23 +1,5 @@
1
- # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the “Software”), to deal in
5
- # the Software without restriction, including without limitation the rights to use,
6
- # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- # Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- # OTHER DEALINGS IN THE SOFTWARE.
1
+ # SPDX-License-Identifier: MIT
2
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR
23
5
  CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
@@ -27,12 +9,19 @@ else()
27
9
  endif()
28
10
 
29
11
  if(NODE_JS_LINK_DEF)
30
- add_custom_command(OUTPUT ${NODE_JS_LINK_LIB}
31
- COMMAND ${CMAKE_AR} ${CMAKE_STATIC_LINKER_FLAGS}
32
- /def:${NODE_JS_LINK_DEF} /out:${NODE_JS_LINK_LIB}
33
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
34
- MAIN_DEPENDENCY ${NODE_JS_LINK_DEF})
35
- add_custom_target(node.lib DEPENDS ${NODE_JS_LINK_LIB})
12
+ set(NODE_JS_LINK_LIB "${CMAKE_CURRENT_BINARY_DIR}/node.lib")
13
+ if (MSVC)
14
+ add_custom_command(OUTPUT node.lib
15
+ COMMAND ${CMAKE_AR} ${CMAKE_STATIC_LINKER_FLAGS}
16
+ /def:${NODE_JS_LINK_DEF} /out:${NODE_JS_LINK_LIB}
17
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
18
+ MAIN_DEPENDENCY ${NODE_JS_LINK_DEF})
19
+ else()
20
+ add_custom_command(OUTPUT node.lib
21
+ COMMAND ${CMAKE_DLLTOOL} -d ${NODE_JS_LINK_DEF} -l ${NODE_JS_LINK_LIB}
22
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
23
+ MAIN_DEPENDENCY ${NODE_JS_LINK_DEF})
24
+ endif()
36
25
  endif()
37
26
 
38
27
  function(add_node_addon)
@@ -44,10 +33,10 @@ endfunction()
44
33
 
45
34
  function(target_link_node TARGET)
46
35
  target_include_directories(${TARGET} PRIVATE ${NODE_JS_INCLUDE_DIRS})
36
+ if(NODE_JS_LINK_DEF)
37
+ target_sources(${TARGET} PRIVATE node.lib)
38
+ endif()
47
39
  if(NODE_JS_LINK_LIB)
48
- if(TARGET node.lib)
49
- add_dependencies(${TARGET} node.lib)
50
- endif()
51
40
  target_link_libraries(${TARGET} PRIVATE ${NODE_JS_LINK_LIB})
52
41
  endif()
53
42
  target_compile_options(${TARGET} PRIVATE ${NODE_JS_COMPILE_FLAGS})
@@ -58,6 +47,8 @@ endfunction()
58
47
 
59
48
  if(USE_UNITY_BUILDS)
60
49
  function(enable_unity_build TARGET)
50
+ cmake_parse_arguments(ARG "" "" "EXCLUDE" ${ARGN})
51
+
61
52
  get_target_property(sources ${TARGET} SOURCES)
62
53
  string(GENEX_STRIP "${sources}" sources)
63
54
 
@@ -69,6 +60,10 @@ if(USE_UNITY_BUILDS)
69
60
  set(cpp_definitions "")
70
61
 
71
62
  foreach(src ${sources})
63
+ if (src IN_LIST ARG_EXCLUDE)
64
+ continue()
65
+ endif()
66
+
72
67
  get_source_file_property(language ${src} LANGUAGE)
73
68
  get_property(definitions SOURCE ${src} PROPERTY COMPILE_DEFINITIONS)
74
69
  if(IS_ABSOLUTE ${src})
@@ -112,7 +107,6 @@ else()
112
107
  endif()
113
108
 
114
109
  if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
115
- message(STATUS ${CMAKE_SYSTEM_PROCESSOR})
116
110
  if(CMAKE_SYSTEM_PROCESSOR MATCHES "(amd64|x86_64)")
117
111
  foreach(lang C CXX)
118
112
  set(CMAKE_${lang}_FLAGS_RELEASE "${CMAKE_${lang}_FLAGS_RELEASE} -mpopcnt -msse4.1 -msse4.2 -mssse3 -mcx16")
@@ -1,23 +1,5 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  #include <stdlib.h>
23
5
  #if !defined(NOMINMAX)
@@ -47,4 +29,8 @@ static FARPROC WINAPI self_exe_hook(unsigned int event, DelayLoadInfo *info)
47
29
  return NULL;
48
30
  }
49
31
 
32
+ #if defined(__MINGW32__)
33
+ PfnDliHook __pfnDliNotifyHook2 = self_exe_hook;
34
+ #else
50
35
  const PfnDliHook __pfnDliNotifyHook2 = self_exe_hook;
36
+ #endif
@@ -1,25 +1,6 @@
1
1
  #!/usr/bin/env node
2
-
3
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
4
- //
5
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- // this software and associated documentation files (the “Software”), to deal in
7
- // the Software without restriction, including without limitation the rights to use,
8
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9
- // Software, and to permit persons to whom the Software is furnished to do so,
10
- // subject to the following conditions:
11
- //
12
- // The above copyright notice and this permission notice shall be included in all
13
- // copies or substantial portions of the Software.
14
- //
15
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
16
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- // OTHER DEALINGS IN THE SOFTWARE.
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
23
4
 
24
5
  'use strict';
25
6
 
@@ -1,23 +1,5 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  'use strict';
23
5
 
@@ -124,44 +106,41 @@ function Builder(config = {}) {
124
106
  args.push(`-DNODE_JS_INCLUDE_DIRS=${options.api}/include`);
125
107
  }
126
108
 
127
- // Download or create Node import library (Windows)
128
- if (process.platform == 'win32') {
129
- if (options.api == null) {
130
- let dirname;
131
- switch (arch) {
132
- case 'ia32': { dirname = 'win-x86'; } break;
133
- case 'x64': { dirname = 'win-x64'; } break;
134
- case 'arm64': { dirname = 'win-arm64'; } break;
135
-
136
- default: {
137
- throw new Error(`Unsupported architecture '${arch}' for Node on Windows`);
138
- } break;
139
- }
140
-
141
- let destname = `${cache_dir}/node_v${runtime_version}_${arch}.lib`;
142
-
143
- if (!fs.existsSync(destname)) {
144
- fs.mkdirSync(cache_dir, { recursive: true, mode: 0o755 });
109
+ args.push(`-DCMAKE_MODULE_PATH=${app_dir}/assets`);
145
110
 
146
- let url = `https://nodejs.org/dist/v${runtime_version}/${dirname}/node.lib`;
147
- await tools.download_http(url, destname);
148
- }
111
+ let win32 = (process.platform == 'win32');
112
+ let msvc = (process.platform == 'win32' && process.env.MSYSTEM == null);
113
+ let darwin = (process.platform == 'darwin');
114
+
115
+ // Handle Node import library on Windows
116
+ if (win32) {
117
+ if (msvc) {
118
+ if (options.api == null) {
119
+ let dirname;
120
+ switch (arch) {
121
+ case 'ia32': { dirname = 'win-x86'; } break;
122
+ case 'x64': { dirname = 'win-x64'; } break;
123
+ case 'arm64': { dirname = 'win-arm64'; } break;
124
+
125
+ default: {
126
+ throw new Error(`Unsupported architecture '${arch}' for Node on Windows`);
127
+ } break;
128
+ }
149
129
 
150
- fs.copyFileSync(destname, work_dir + '/node.lib');
151
- } else {
152
- args.push(`-DNODE_JS_LINK_DEF=${options.api}/def/node_api.def`);
153
- }
154
- }
130
+ let destname = `${cache_dir}/node_v${runtime_version}_${arch}.lib`;
155
131
 
156
- args.push(`-DCMAKE_MODULE_PATH=${app_dir}/assets`);
132
+ if (!fs.existsSync(destname)) {
133
+ fs.mkdirSync(cache_dir, { recursive: true, mode: 0o755 });
157
134
 
158
- // Set platform flags
159
- switch (process.platform) {
160
- case 'win32': {
161
- fs.copyFileSync(`${app_dir}/assets/win_delay_hook.c`, work_dir + '/win_delay_hook.c');
135
+ let url = `https://nodejs.org/dist/v${runtime_version}/${dirname}/node.lib`;
136
+ await tools.download_http(url, destname);
137
+ }
162
138
 
163
- args.push(`-DNODE_JS_SOURCES=${work_dir}/win_delay_hook.c`);
164
- args.push(`-DNODE_JS_LINK_LIB=${work_dir}/node.lib`);
139
+ fs.copyFileSync(destname, work_dir + '/node.lib');
140
+ args.push(`-DNODE_JS_LINK_LIB=${work_dir}/node.lib`);
141
+ } else {
142
+ args.push(`-DNODE_JS_LINK_DEF=${options.api}/def/node_api.def`);
143
+ }
165
144
 
166
145
  switch (arch) {
167
146
  case 'ia32': {
@@ -177,22 +156,29 @@ function Builder(config = {}) {
177
156
  args.push('-A', 'x64');
178
157
  } break;
179
158
  }
180
- } break;
181
159
 
182
- case 'darwin': {
183
- args.push('-DNODE_JS_LINK_FLAGS=-undefined;dynamic_lookup');
160
+ fs.copyFileSync(`${app_dir}/assets/win_delay_hook.c`, work_dir + '/win_delay_hook.c');
161
+ args.push(`-DNODE_JS_SOURCES=${work_dir}/win_delay_hook.c`);
162
+ } else {
163
+ args.push(`-DNODE_JS_LINK_LIB=node.dll`);
164
+ }
165
+ }
166
+
167
+ if (darwin) {
168
+ args.push('-DNODE_JS_LINK_FLAGS=-undefined;dynamic_lookup');
184
169
 
185
- switch (arch) {
186
- case 'arm64': { args.push('-DCMAKE_OSX_ARCHITECTURES=arm64'); } break;
187
- case 'x64': { args.push('-DCMAKE_OSX_ARCHITECTURES=x86_64'); } break;
188
- }
189
- } break;
170
+ switch (arch) {
171
+ case 'arm64': { args.push('-DCMAKE_OSX_ARCHITECTURES=arm64'); } break;
172
+ case 'x64': { args.push('-DCMAKE_OSX_ARCHITECTURES=x86_64'); } break;
173
+ }
190
174
  }
191
175
 
192
- if (process.platform != 'win32') {
193
- // Prefer Ninja if available
194
- if (spawnSync('ninja', ['--version']).status === 0)
176
+ if (!msvc) {
177
+ if (spawnSync('ninja', ['--version']).status === 0) {
195
178
  args.push('-G', 'Ninja');
179
+ } else if (process.platform == 'win32') {
180
+ args.push('-G', 'MinGW Makefiles');
181
+ }
196
182
 
197
183
  // Use CCache if available
198
184
  if (spawnSync('ccache', ['--version']).status === 0) {
@@ -200,9 +186,8 @@ function Builder(config = {}) {
200
186
  args.push('-DCMAKE_CXX_COMPILER_LAUNCHER=ccache');
201
187
  }
202
188
  }
203
-
204
189
  if (prefer_clang) {
205
- if (process.platform == 'win32') {
190
+ if (msvc) {
206
191
  args.push('-T', 'ClangCL');
207
192
  } else {
208
193
  args.push('-DCMAKE_C_COMPILER=clang');
@@ -1,23 +1,5 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  const builder = require('./builder.js');
23
5
  const tools = require('./tools.js');
@@ -1,23 +1,5 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
- //
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
- //
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  'use strict';
23
5
 
@@ -1,23 +1,5 @@
1
- # Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the “Software”), to deal in
5
- # the Software without restriction, including without limitation the rights to use,
6
- # copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- # Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- # OTHER DEALINGS IN THE SOFTWARE.
1
+ # SPDX-License-Identifier: MIT
2
+ # SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
21
3
 
22
4
  cmake_minimum_required(VERSION 3.6)
23
5
  cmake_policy(SET CMP0091 NEW)
@@ -54,6 +36,8 @@ if(UNIX AND NOT APPLE)
54
36
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack")
55
37
  endif()
56
38
 
39
+ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
40
+
57
41
  # ---- Koffi ----
58
42
 
59
43
  # Recompute the version string after each commit
@@ -75,8 +59,9 @@ set(KOFFI_SRC
75
59
  src/ffi.cc
76
60
  src/parser.cc
77
61
  src/util.cc
62
+ src/uv.cc
78
63
  src/win32.cc
79
- ../../src/core/base/base.cc
64
+ ../../lib/native/base/base.cc
80
65
  )
81
66
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
82
67
  # CMAKE_SYSTEM_PROCESSOR is wrong on Windows ARM64
@@ -114,7 +99,11 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
114
99
  list(APPEND KOFFI_SRC src/abi_riscv64.cc src/abi_loong64_asm.S)
115
100
  else()
116
101
  if(WIN32)
117
- list(APPEND KOFFI_SRC src/abi_x64_win.cc src/abi_x64_win_asm.asm)
102
+ if(MSVC)
103
+ list(APPEND KOFFI_SRC src/abi_x64_win.cc src/abi_x64_win_asm.asm)
104
+ else()
105
+ list(APPEND KOFFI_SRC src/abi_x64_win.cc src/abi_x64_win_asm.S)
106
+ endif()
118
107
  else()
119
108
  list(APPEND KOFFI_SRC src/abi_x64_sysv.cc src/abi_x64_sysv_asm.S)
120
109
  endif()
@@ -134,6 +123,24 @@ endif()
134
123
  add_node_addon(NAME koffi SOURCES ${KOFFI_SRC})
135
124
  target_include_directories(koffi PRIVATE . ../.. ../../vendor/node-addon-api)
136
125
 
126
+ if(WIN32)
127
+ set(UV_LINK_LIB "${CMAKE_CURRENT_BINARY_DIR}/uv.lib")
128
+ if(MSVC)
129
+ add_custom_command(OUTPUT uv.lib
130
+ COMMAND ${CMAKE_AR} ${CMAKE_STATIC_LINKER_FLAGS}
131
+ /def:src/uv.def /out:${UV_LINK_LIB}
132
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
133
+ MAIN_DEPENDENCY src/uv.def)
134
+ else()
135
+ add_custom_command(OUTPUT uv.lib
136
+ COMMAND ${CMAKE_DLLTOOL} -d src/uv.def -l ${UV_LINK_LIB}
137
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
138
+ MAIN_DEPENDENCY src/uv.def)
139
+ endif()
140
+ target_sources(koffi PRIVATE uv.lib)
141
+ target_link_libraries(koffi PRIVATE ${UV_LINK_LIB})
142
+ endif()
143
+
137
144
  target_compile_definitions(koffi PRIVATE FELIX_TARGET=koffi NAPI_DISABLE_CPP_EXCEPTIONS NAPI_VERSION=8 CORE_NO_STATX)
138
145
  if(WIN32)
139
146
  target_compile_definitions(koffi PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
@@ -157,4 +164,4 @@ if(NOT MSVC OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
157
164
  endif()
158
165
  endif()
159
166
 
160
- enable_unity_build(koffi)
167
+ enable_unity_build(koffi EXCLUDE src/uv.cc)