Skip to content

Commit 595b81e

Browse files
authored
Add a generator script to regenerate native bindings (#264)
1 parent 9ea41b1 commit 595b81e

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

.github/workflows/io_file.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ jobs:
4747
with:
4848
sdk: dev
4949
- run: dart pub get
50-
- run: dart run ffigen --config ffigen.yaml
51-
- run: dart run ffigen --config constants-ffigen.yaml
52-
- run: dart --enable-experiment=native-assets run tool/build_constants.dart
53-
- run: dart format lib/src/*.dart
50+
- run: dart --enable-experiment=native-assets run tool/generate.dart
5451
- run: git diff --exit-code
5552

5653
desktop-vm-test:

pkgs/io_file/constants-ffigen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: NativeAddBindings
33
description: |
44
Bindings for `constants.g.h`.
55
6-
Regenerate bindings with `dart run ffigen --config constants-ffigen.yaml`.
6+
Regenerate bindings with `dart run tool/generate.dart`.
77
output: 'lib/src/constant_bindings.g.dart'
88
headers:
99
entry-points:

pkgs/io_file/ffigen.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: NativeAddBindings
33
description: |
44
Bindings for `src/libc_shim.h`.
55
6-
Regenerate bindings with `dart run ffigen --config ffigen.yaml`.
6+
Regenerate bindings with `dart run tool/generate.dart`.
77
output: 'lib/src/libc_bindings.g.dart'
88
headers:
99
entry-points:

pkgs/io_file/tool/generate.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Run all code generation and formatting steps.
6+
7+
import 'dart:convert';
8+
import 'dart:io';
9+
10+
import 'package:ffigen/src/executables/ffigen.dart' as ffigen;
11+
import 'build_constants.dart' as build_constants;
12+
13+
void _formatFile(String path) {
14+
final result = Process.runSync(Platform.executable, [
15+
'format',
16+
path,
17+
], stderrEncoding: utf8);
18+
if (result.exitCode != 0) {
19+
throw Exception('failed to format $path:\n${result.stderr}');
20+
}
21+
}
22+
23+
void main() async {
24+
build_constants.main();
25+
26+
await ffigen.main(['--no-format', '-v', 'severe', '--config', 'ffigen.yaml']);
27+
await ffigen.main([
28+
'--no-format',
29+
'-v',
30+
'severe',
31+
'--config',
32+
'constants-ffigen.yaml',
33+
]);
34+
35+
_formatFile('lib/src/constant_bindings.g.dart');
36+
_formatFile('lib/src/constants.g.dart');
37+
_formatFile('lib/src/libc_bindings.g.dart');
38+
}

0 commit comments

Comments
 (0)