Skip to content

Extract function signatures from dynamic libraries

License

Notifications You must be signed in to change notification settings

rland93/dwarffi

Repository files navigation

dwarffi

extract a structured representation of function signatures from a dynamic library

how to use:

  1. compile your C library with debug symbols.
  2. use __attribute__((visibility("default"))) to selectively make symbols visible.
  3. run the tool:
dwarffi-js --js --functions path/to/library.dylib >> ./bindings.js
  1. the javascript code is printed to stdout, so you can pipe it to a file like the example above.

this tool only works with dynamic C libraries, compiled with gcc or clang, on a macos or linux system. Your library MUST have DWARF debug symbols -- i.e. -g flag passed in. So, it may not work with pre-compiled libraries especially in cases where the source is not available for compilation.

the intended use case is for generating bindings for a program whose build/configuration system is very complex, whose compilation is expensive, or whose source code cannot be changed or annotated, or where compilation of the library and running of the library is done in a very different context.

for an example library, see the test_c folder and its makefile.

Supported platforms

  • linux x86
  • macos arm64

integration tests run on linux and mac.

windows is too difficult to test because I do not have a windows machine.

repository structure

--> dwarffi - library. Parsing logic, type extraction, function extraction. not an executable, but can be included in other (rust) projects as a static library.

--> dwarffi-js - CLI tool (Rust) installable via cargo install. Also -- eventually -- NPM package, released via cargo-dist.

dwarffi-js can generate bindings in Javascript using koffi

other stuff

run tests. you have to comopile the test_c library because there are some integration tests included that rely on generated files. this means you have to have a compiler on your system.

cd test_c && make
# then
cargo test

coverage:

cargo llvm-cov --workspace --html --output-dir coverage

About

Extract function signatures from dynamic libraries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published