[ffigen] Generate build.dart script if a .m file is generated
The main design goal is that the script should be composable. It should be easy for the user to integrate the new build stuff with their existing build script if they have one.
@brianquinlan
The main design goal is that the script should be composable.
I'd suggest something along the lines of:
hook/build.dart
import 'package:hooks/hooks.dart';
import 'package:sqlite/src/ffigen_build.g.dart';
void main(List<String> args) async {
await build(args, (input, output) async {
await buildFfiGenAsset(input, output);
});
}
lib/src/ffigen_build.g.dart:
// GENERATED BY FFIGEN DO NOT EDIT.
import 'package:code_assets/code_assets.dart';
import 'package:hooks/hooks.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';
Future<void> buildFfiGenAsset(
BuildInput input,
BuildOutputBuilder output,
) async {
if (input.config.buildCodeAssets) {
final builder = CBuilder.library(
// ...
);
await builder.run(input: input, output: output);
}
}
And throw an error if there's no call await buildFfiGenAsset(input, output); in hook/build.dart but it does exist.
I'll probably also generate a main() in ffigen_build.g.dart, so that if this is the user's only native asset they can just generate this file directly as their hook/build.dart.
And throw an error if there's no call
await buildFfiGenAsset(input, output);inhook/build.dartbut it does exist.
@dcharkes Not quite sure what you mean here. Isn't hook/build.dart written by the user in this hypothetical? How do we throw the error?
I'd let the code generator generate the build hook if it doesn't exist yet, and if it already exists check that buildFfiGenAsset is called. And het the code generator always regenerate ffigen_build.g.dart.
So the build hook can be written by the user, in that case we check that it calls buildFfiGenAsset. But if it's not written by the user we just generate the hook.