README · Changelog · Development
- Used by node-ffi-packager to generate node-ffi-libraries.
- Depends on a similarly forked node-libclang.
- Use this version by referencing the repository/branch in
package.json
instead of the official version published on npm. - Based on
node-ffi-generate
(5ad34dc, v0.0.8) by Timothy J Fontaine.
A tool to generate Node.js Foreign Function Interface (FFI) bindings for a given C/C++ header file. Based on node-libclang.
For command line usage.
# NOTE: global installation is not necessary, but convenient for command line usage.
npm install --global github:node-ffi-packager/node-ffi-generate#semver:^v2.0.2
For programmatic usage.
npm install --save github:node-ffi-packager/node-ffi-generate#semver:^v2.0.2
- Selected parts of the The LLVM Compiler Infrastructure.
- The
llvm-config
tool.- Used to automatically look up the location of
libclang
, but it can be manually configured. - Try symlinking versioned executables (such as
llvm-config-9
) tollvm-config
in yourPATH
.
- Used to automatically look up the location of
- The
libclang
library.- Indirectly required by node-libclang.
- Installing using a package manager is strongly recommended.
- The
Parse the given header file and print the rendered javascript to standard. Fast and simple to use.
ffi-generate --file '/path/to/myLibrary/header.h' --library 'libmyLibrary'
Generate node-ffi-napi javascript bindings for a given C/C++ header file
Options:
-f, --file The header file to parse [required]
-l, --library The name of the library to dlopen [required]
-x, --single-file Only export functions found in this file
-p, --prefix Only import functions whose name start with prefix. Can be specified multiple times.
It may be necessary to pass additional flags/arguments to libclang so it can better parse the header (for example include paths). To pass options directly to libclang use --
so ffi-generate knows to stop parsing arguments. The rest will be passed to libclang without modification.
ffi-generate --file '/usr/include/ImageMagick/wand/MagickWand.h' --library 'libMagickWand' --prefix 'Magick' -- $(Magick-config --cflags)
- See
lib/generateffi.js
for options to pass. - See
examples/
.
Setting LD_LIBRARY_PATH
(or DYLD_LIBRARY_PATH
on macOS) might be necessary for ffi-generate
to find the libclang
dynamic library. For the ffi-generate
command, this is performed internally by calling llvm-config
. For programmatic use try setting it manually as an environment variable.
LD_LIBRARY_PATH="$(llvm-config --libdir)" node my-generator-code.js
Get additional debug
messages by setting the DEBUG
environment variable.
DEBUG='ffi-generate:*' ffi-generate <other arguments as usual>
node-ffi-generate
Copyright © 2011, 2012, 2013, 2014 Timothy J Fontaine, © 2020, 2021 Joel Purra. Released under MIT License.