Improved generated comments (#16)

closes #16 
- Added comments option to config, Possible options are - {full, brief, none}
- Extracting comments for enum values, struct members
- Wrap brief comments (see `clang_bindings.dart`)
- Removed comment markups from full comments (see `libclang-example/generated_bindings.dart`)
13 files changed
tree: 4c35cb52f35158e12191bd3226a35d5a4e2249ff
  1. bin/
  2. example/
  3. lib/
  4. test/
  5. third_party/
  6. tool/
  7. .gitignore
  8. .travis.yml
  9. analysis_options.yaml
  10. AUTHORS
  11. CHANGELOG.md
  12. LICENSE
  13. pubspec.yaml
  14. README.md
README.md

Build Status

Experimental binding generator for FFI bindings.

Example

For some header file example.h:

int sum(int a, int b);

Add configurations to Pubspec File:

ffigen:
  output: 'generated_bindings.dart'
  headers:
    - 'example.h'

Output (generated_bindings.dart).

DynamicLibrary _dylib;

/// Initialises dynamic library
void init(DynamicLibrary dylib) {
  _dylib = dylib;
}

int sum(int a,int b) {
  return _sum(a,b);
}

final _dart_sum _sum = _dylib.lookupFunction<_c_sum, _dart_sum>('sum');

typedef _c_sum = Int32 Function(Int32 a,Int32 b);

typedef _dart_sum = int Function(int a,int b);

Using this package

  • clone/download this repository.
  • Build it (see building).
  • Add this package as dev_dependency in your pubspec.yaml.
  • Configurations must be provided in the pubspec.yaml file under the key ffigen (or directly under a seperate yaml file which when u specify it passing --config filename when running the tool)
  • Run the tool- pub run ffigen.

Building

A dynamic library for a wrapper to libclang needs to be generated as it is used by the parser submodule.

ubuntu/linux

  1. Install libclangdev - sudo apt-get install libclang-dev.
  2. cd tool/wrapped_libclang, then run dart build.dart.

Windows

  1. Install Visual Studio with C++ development support.
  2. Install LLVM.
  3. cd tool\wrapped_libclang, then run dart build.dart.

MacOS

  1. Install LLVM.
  2. cd tool/wrapped_libclang, then run dart build.dart.

Trying out examples

  1. cd examples/<example_u_want_to_run>, Run pub get.
  2. Run pub run ffigen.

Running Tests

Dynamic library for some tests need to be built before running the examples.

  1. cd test/native_functions_test.
  2. Run dart build_test_dylib.dart.

Run tests from the root of the package with pub run test.