Skip to content
This repository was archived by the owner on Jan 28, 2024. It is now read-only.

Commit f0d4d9a

Browse files
mannprerak2jpnurmi
andauthored
Remove setup phase and usage of --no-sound-null-safety flag (#135, #137) (#164)
Co-authored-by: J-P Nurmi <[email protected]>
1 parent 069e36f commit f0d4d9a

28 files changed

+1065
-2082
lines changed

.github/workflows/test-package.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ jobs:
4949
run: dart pub get
5050
- name: Install libclang-10-dev
5151
run: sudo apt-get install libclang-10-dev
52-
- name: Setup ffigen
53-
run: dart run ffigen:setup
5452
- name: Build test dylib
5553
run: cd test/native_test && dart build_test_dylib.dart && cd ../..
5654
- name: Run VM tests

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2.0.0-dev.3
2+
- Removed the usage of `--no-sound-null-safety` flag.
3+
4+
# 2.0.0-dev.2
5+
- Removed setup phase for ffigen. Added new optional config key `llvm-lib`
6+
to specify path to `llvm/lib` folder.
7+
18
# 2.0.0-dev.1
29
- Added support for passing and returning struct by value in functions.
310

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ typedef _dart_sum = int Function(int a, int b);
3636
```
3737
## Using this package
3838
- Add `ffigen` under `dev_dependencies` in your `pubspec.yaml`.
39-
- Setup for use (see [Setup](#Setup)).
39+
- Install LLVM (see [Installing LLVM](#installing-llvm)).
4040
- Configurations must be provided in `pubspec.yaml` or in a custom YAML file (see [configurations](#configurations)).
4141
- Run the tool- `dart run ffigen`.
4242

4343
Jump to [FAQ](#faq).
4444

45-
## Setup
45+
## Installing LLVM
4646
`package:ffigen` uses LLVM. Install LLVM (9+) in the following way.
4747

4848
#### ubuntu/linux
@@ -83,6 +83,16 @@ The following configuration options are available-
8383

8484
```yaml
8585
output: 'generated_bindings.dart'
86+
```
87+
</td>
88+
</tr>
89+
<tr>
90+
<td>llvm-lib</td>
91+
<td>Path to <i>llvm/lib</i> folder. Required if ffigen is unable to find this at default locations.</td>
92+
<td>
93+
94+
```yaml
95+
llvm-lib: '/usr/local/opt/llvm/lib'
8696
```
8797
</td>
8898
</tr>
@@ -379,13 +389,12 @@ class ArrayHelper_CXFileUniqueID_data_level0 {
379389
2. Run `pub run ffigen`.
380390

381391
## Running Tests
382-
1. Run setup to build the LLVM wrapper - `pub run ffigen:setup`.
383-
2. Dynamic library for some tests also need to be built before running the examples.
392+
1. Dynamic library for some tests need to be built before running the examples.
384393
1. `cd test/native_test`.
385394
2. Run `dart build_test_dylib.dart`.
386395

387396
Run tests from the root of the package with `pub run test`.
388-
397+
> Note: If llvm is not installed in one of the default locations, tests may fail.
389398
## FAQ
390399
### Can ffigen be used for removing underscores or renaming declarations?
391400
Ffigen supports **regexp based renaming**, the regexp must be a

bin/setup.dart

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/libclang-example/pubspec.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ ffigen:
1515
output: 'generated_bindings.dart'
1616
sort: true
1717

18+
# This is required if LLVM can't be found in default locations by ffigen.
19+
# llvm-lib: '/usr/local/opt/llvm/lib'
20+
1821
# Bash style Glob matching is also supported.
1922
# TODO(11): Globs dont work on windows if they begin with '.' or '..'.
2023
headers:

lib/src/README.md

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,17 @@
22
## Table of Contents -
33
1. [Overview](#overview)
44
2. [LibClang](#LibClang)
5-
1. [The Wrapper library](#The-Wrapper-library)
6-
2. [Generation and Usage](#Generation-and-Usage)
7-
3. [Bindings](#Bindings)
5+
1. [Bindings](#Bindings)
86
3. [Scripts](#scripts)
97
1. [ffigen.dart](#ffigen.dart)
10-
2. [setup.dart](#setup.dart)
118
4. [Components](#components)
129
1. [Config Provider](#Config-Provider)
1310
2. [Header Parser](#Header-Parser)
1411
3. [Code Generator](#Code-Generator)
1512
# Overview
1613
`package:ffigen` simplifies the process of generating `dart:ffi` bindings from C header files. It is simple to use, with the input being a small YAML config file. It requires LLVM (9+) to work. This document tries to give a complete overview of every component without going into too many details about every single class/file.
1714
# LibClang
18-
`package:ffigen` binds to LibClang using `dart:ffi` for parsing C header files. A wrapper library must be generated to use it, as `dart:ffi` currently [doesn't support structs by value](https://github.com/dart-lang/ffigen/issues/3).
19-
## The Wrapper library
20-
> Note: The wrapper is only needed because `dart:ffi` currently doesn't support Structs by value.
21-
22-
The `wrapper.c` file consists of functions that wrap LibClang functions. Most of them simply convert structs by value to pointers. Except -
23-
- `clang_visitChildren_wrap` - The bindings for this function internally uses a **list** of **stack** for maintaining the supplied visitor functions. This is required because this function takes a function pointer which itself passes a struct by value. All this effort makes `clang_visitChildren_wrap` behave exactly like `clang_visitChildren`.
24-
## Generation and Usage
25-
The files needed for generating the wrapper are in `lib/src/clang_library`.
26-
> The `wrapper.def` file is only needed on windows because the symbols are otherwise hidden.
27-
28-
The libclang wrapper can be _manually_ generated using `pub run ffigen:setup`. See [setup.dart](#setup.dart) for details.
29-
30-
The generated file is placed in the project's `.dart_tool/ffigen` folder, the file name also specifies the ffigen version (E.g - `_v0_2_4_libclang_wrapper.dylib`), this helps ensure the correct wrapper is being used for its corresponding version.
31-
32-
This dynamic library is then used by [Header Parser](#header-parser) for parsing C files.
15+
`package:ffigen` binds to LibClang using `dart:ffi` for parsing C header files.
3316
## Bindings
3417
The config file for generating bindings is `tool/libclang_config.yaml`. The bindings are generated to `lib/src/header_parser/clang_bindings/clang_bindings.dart`. These are used by [Header Parser](#header-parser) for calling libclang functions.
3518
# Scripts
@@ -38,19 +21,11 @@ This is the main entry point for the user- `pub run ffigen`.
3821
- Command-line options:
3922
- `--verbose`: Sets log level.
4023
- `--config`: Specifies a config file.
41-
- `ffigen.dart` will first check if a dynamic library already exists and is up to date. If not, it tries to auto-create it. If that fails, user must excplicitly call [setup.dart](#setup.dart).
4224
- The internal modules are called by `ffigen.dart` in the following way:
25+
- `ffigen.dart` will try to find dynamic library in default locations. If that fails, the user must excplicitly specify location in ffigen's config under the key `llvm-lib`.
4326
- It first creates a `Config` object from an input Yaml file. This is used by other modules.
4427
- The `parse` method is then invoked to generate a `Library` object.
4528
- Finally, the code is generated from the `Library` object to the specified file.
46-
## setup.dart
47-
Used to generate the wrapper dynamic library. Users will need to explicitly call this if `pub run ffigen` is unable to auto-create the dynamic library.
48-
> `clang` must be on user's path for `setup.dart` to work.
49-
50-
- Command-line options:
51-
- `-I`: Specifies header includes.
52-
- `-L`: Specifies library includes.
53-
- `setup.dart` generates the dynamic library to the project's `.dart_tool/ffigen` folder using `clang`.
5429
# Components
5530
## Config Provider
5631
The Config Provider holds all the configurations required by other modules.

0 commit comments

Comments
 (0)