capnpc_dart_builder 0.2.0
capnpc_dart_builder: ^0.2.0 copied to clipboard
build_runner integration for capnpc-dart. Add as a dev_dependency to generate .capnp.dart files from .capnp schema files via `dart run build_runner build`, instead of invoking `capnp compile` yourself [...]
capnpc_dart_builder #
build_runner integration for capnpc_dart.
How the pieces fit together #
capnpc_dart_builder(this package)
wrapscapnpc_dart's generator in abuild_runnerbuilder.- The generated code
depends on
capnproto_dart
Install #
dev_dependencies:
build_runner: ^2.4.13
capnpc_dart_builder: ^0.1.0
dart pub get
The official capnp compiler must also be installed and on PATH. it does not parse .capnp syntax itself.
If capnp can't be launched (not installed, not on PATH, or a permissions
issue), the build fails with a CapnpLaunchException:
capnp compile failed: could not launch the `capnp` command-line compiler
(No such file or directory). This usually means `capnp` is not installed or
not on PATH — install it yourself, see https://capnproto.org/install.html —
but could also be a permissions or other OS-level launch failure. Underlying
error: ProcessException: No such file or directory
Command: capnp compile ...
Generate Dart code #
build_runner only looks under lib/, so put schema files there:
# lib/schema/hello.capnp
@0xdeadbeefdeadbeef;
struct Greeting {
name @0 :Text;
reply @1 :Text;
}
dart run build_runner build
This writes lib/schema/hello.capnp.dart next to your schema.
Re-run after editing a schema; add --delete-conflicting-outputs if build_runner complains about stale output.
Custom import paths #
Schemas that import a file outside their own package (capnp's -I-rooted imports) need an extra search root,
since build_runner can only see files inside the package being built. Add one via the builder's import_paths option in your own build.yaml:
targets:
$default:
builders:
capnpc_dart_builder|capnp:
options:
import_paths: ["../shared_schemas"]
See the schema and code-generation guide for imports, constants, generated names, and current limitations.