Skip to content

Commit 5b1f6da

Browse files
committed
fix: add suffix
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 4d36946 commit 5b1f6da

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

doc/api/ffi.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ const signature = {
137137
};
138138
```
139139

140+
## `ffi.suffix`
141+
142+
<!-- YAML
143+
added: REPLACEME
144+
-->
145+
146+
* {string}
147+
148+
The native shared library suffix for the current platform:
149+
150+
* `'dylib'` on macOS
151+
* `'so'` on Unix-like platforms
152+
* `'dll'` on Windows
153+
154+
This can be used to build portable library paths:
155+
156+
```cjs
157+
const { suffix } = require('node:ffi');
158+
159+
const path = `libsqlite3.${suffix}`;
160+
```
161+
140162
## `ffi.dlopen(path[, definitions])`
141163

142164
<!-- YAML

lib/ffi.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const {
1717
validateInteger,
1818
validateString,
1919
} = require('internal/validators');
20-
const { __proto__ } = require('console');
2120

2221
emitExperimentalWarning('FFI');
2322

@@ -132,6 +131,8 @@ function exportBuffer(buffer, data, len) {
132131
buffer.copy(targetBuffer, 0, 0, buffer.length);
133132
}
134133

134+
const suffix = process.platform === 'win32' ? 'dll' : process.platform === 'darwin' ? 'dylib' : 'so';
135+
135136
const types = ObjectFreeze({
136137
__proto__: null,
137138
VOID: 'void',
@@ -184,6 +185,7 @@ module.exports = {
184185
setUint64,
185186
setFloat32,
186187
setFloat64,
188+
suffix,
187189
toString,
188190
toArrayBuffer,
189191
toBuffer,

0 commit comments

Comments
 (0)