Skip to content

Commit cd85f23

Browse files
Migrate from manual bindings to auto generated bindings by ffigen package (#84)
* add ffigen to dependencies * use bindings by ffigen * dart format --fix -l 120 . * manual edit bindings * add struct packed config * dart format --fix -l 120 . * fix codecov ignore * bump version * Update pointer_int8.dart * private dylib
1 parent bdf492e commit cd85f23

28 files changed

Lines changed: 9843 additions & 1672 deletions

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ comment: # See: https://docs.codecov.io/docs/pull-request-comments
3232
require_head: true
3333

3434
ignore: # See: https://docs.codecov.io/docs/ignoring-paths
35-
- lib/src/ffi/bindings/structs
35+
- lib/src/ffi/bindings.dart

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.0.0
2+
3+
- [internal migration] Migrate from manual bindings to auto generated bindings by ffigen package.
4+
15
# 1.5.0
26

37
- delete deprecated functions.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ dartdoc && open doc/api/index.html
8181
libedax_build_command="make libbuild ARCH=x64-modern COMP=gcc OS=osx" dst="." ./scripts/build_libedax.sh
8282
```
8383

84+
#### generate bindings
85+
86+
```sh
87+
# Before this, you must run build_libedax.sh
88+
pub run ffigen --config ffigen.yaml --verbose severe
89+
```
90+
8491
### reference
8592

8693
- [dart:ffi](https://dart.dev/guides/libraries/c-interop)

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ include: package:pedantic_sensuikan1973/analysis_options.yaml
22

33
analyzer:
44
exclude:
5-
- lib/src/ffi/bindings/structs
5+
- lib/src/ffi/bindings.dart

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ packages:
9191
path: ".."
9292
relative: true
9393
source: path
94-
version: "1.5.0"
94+
version: "2.0.0"
9595
meta:
9696
dependency: transitive
9797
description:

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: libedax4dart_example
2-
version: 1.5.0-example
2+
version: 2.0.0-example
33
publish_to: none
44

55
environment:

ffigen.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# See: https://pub.dev/packages/ffigen#configurations
2+
name: 'LibEdaxBindings'
3+
description: 'bindings to libedax'
4+
output: 'lib/src/ffi/bindings.dart'
5+
sort: true
6+
headers:
7+
entry-points:
8+
- './edax-reversi/src/all.c'
9+
structs:
10+
pack:
11+
# See: https://github.com/sensuikan1973/libedax4dart/pull/74#issuecomment-890427516
12+
# See: https://github.com/dart-lang/sdk/issues/46644
13+
'sockaddr_storage': 1
14+
functions:
15+
include:
16+
- 'bit_count'
17+
- 'edax_book_count_bestpath'
18+
- 'edax_book_load'
19+
- 'edax_book_new'
20+
- 'edax_book_off'
21+
- 'edax_book_on'
22+
- 'edax_book_randomness'
23+
- 'edax_book_show'
24+
- 'edax_book_stop_count_bestpath'
25+
- 'edax_can_move'
26+
- 'edax_get_board'
27+
- 'edax_get_bookmove_with_position_by_moves'
28+
- 'edax_get_bookmove_with_position'
29+
- 'edax_get_bookmove'
30+
- 'edax_get_current_player'
31+
- 'edax_get_disc'
32+
- 'edax_get_last_move'
33+
- 'edax_get_mobility_count'
34+
- 'edax_get_moves'
35+
- 'edax_go'
36+
- 'edax_hint_next_no_multipv_depth'
37+
- 'edax_hint_next'
38+
- 'edax_hint_prepare'
39+
- 'edax_hint'
40+
- 'edax_init'
41+
- 'edax_is_game_over'
42+
- 'edax_mode'
43+
- 'edax_move'
44+
- 'edax_new'
45+
- 'edax_opening'
46+
- 'edax_play'
47+
- 'edax_redo'
48+
- 'edax_rotate'
49+
- 'edax_set_option'
50+
- 'edax_setboard'
51+
- 'edax_stop'
52+
- 'edax_undo'
53+
- 'edax_version'
54+
- 'edax_vmirror'
55+
- 'libedax_initialize'
56+
- 'libedax_terminate'

lib/extensions/pointer_int8.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// See: https://github.com/dart-lang/ffigen/issues/72
2+
3+
import 'dart:ffi';
4+
5+
import 'package:ffi/ffi.dart';
6+
7+
extension Int8PointerString on Pointer<Int8> {
8+
// See: https://pub.dev/packages/ffigen#how-does-ffigen-handle-c-strings
9+
String toStr() => cast<Utf8>().toDartString();
10+
}

lib/extensions/string.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// See: https://github.com/dart-lang/ffigen/issues/72
2+
3+
import 'dart:ffi';
4+
5+
import 'package:ffi/ffi.dart';
6+
7+
extension Int8Pointer on String {
8+
Pointer<Int8> toInt8Pointer() => toNativeUtf8().cast<Int8>();
9+
}

lib/src/board.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import 'package:meta/meta.dart';
22

33
import 'constants.dart';
4-
import 'ffi/bindings/structs/board.dart' as c_board;
4+
import 'ffi/bindings.dart' as bindings;
55
import 'util.dart';
66

77
@immutable
88
class Board {
99
const Board(this.player, this.opponent);
1010

1111
/// initialize from C struct
12-
Board.fromCStruct(final c_board.Board cBoard)
12+
Board.fromCStruct(final bindings.Board cBoard)
1313
: player = cBoard.player,
1414
opponent = cBoard.opponent;
1515

0 commit comments

Comments
 (0)