vyre_build_scan/config.rs
1//! Public configuration types consumed by `build.rs`.
2
3/// Description of one flat responsibility registry to emit from `build.rs`.
4///
5/// The scanner resolves [`Registry::scan_dir`] under `CARGO_MANIFEST_DIR` and
6/// resolves [`Registry::output_file`] under `OUT_DIR`. `output_file` must be a
7/// bare file name, which prevents consumer build scripts from writing generated
8/// registry files into `src/`.
9///
10/// # build.rs example
11///
12/// ```ignore
13/// vyre_build_scan::scan(&vyre_build_scan::Registry {
14/// scan_dir: "src/enforce/gates",
15/// const_name: "ALL_GATES",
16/// element_type: "&'static dyn crate::enforce::EnforceGate",
17/// item_const_name: "REGISTERED",
18/// output_file: "gates_registry.rs",
19/// module_prefix: "crate::enforce::gates",
20/// });
21/// ```
22pub struct Registry<'a> {
23 /// Source directory relative to the crate manifest, e.g. `"src/gates"`.
24 pub scan_dir: &'a str,
25 /// Name of the emitted constant slice, e.g. `"ALL_GATES"`.
26 pub const_name: &'a str,
27 /// Fully-qualified trait the constant slice references, e.g.
28 /// `"&dyn crate::gates::EnforceGate"`.
29 ///
30 /// The emitted slice has type `&[Item]` where `Item` is this string.
31 pub element_type: &'a str,
32 /// Name of the `pub const` each scanned file must export.
33 pub item_const_name: &'a str,
34 /// Bare output file name under `$OUT_DIR`, e.g. `"gates_registry.rs"`.
35 pub output_file: &'a str,
36 /// Module path prefix used when referencing each file's constant.
37 ///
38 /// For `src/gates/atomics.rs` with `module_prefix = "crate::gates"`,
39 /// the emitted entry is `&crate::gates::atomics::REGISTERED`.
40 pub module_prefix: &'a str,
41}
42
43/// Description of one Rust-source `OpSpec` registry to emit from `build.rs`.
44///
45/// Use this when operation implementations expose `pub const SPEC: OpSpec` or
46/// an associated `impl Type { pub const SPEC: OpSpec = ...; }` and the crate
47/// wants a generated `&[&OpSpec]` in `OUT_DIR`.
48///
49/// # build.rs example
50///
51/// ```ignore
52/// vyre_build_scan::scan_rust_specs(&vyre_build_scan::RustSpecRegistry {
53/// scan_dirs: &["src/ops"],
54/// const_name: "GENERATED_REGISTRY",
55/// output_file: "ops_registry.rs",
56/// });
57/// ```
58pub struct RustSpecRegistry<'a> {
59 /// Source directories relative to the crate manifest, e.g. `"src/ops"`.
60 pub scan_dirs: &'a [&'a str],
61 /// Name of the emitted slice, e.g. `"GENERATED_REGISTRY"`.
62 pub const_name: &'a str,
63 /// Bare output file name under `$OUT_DIR`, e.g. `"ops_registry.rs"`.
64 pub output_file: &'a str,
65}