1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Build step: precompile the embedded builtin baseline into a serialized `RegexSet`.
//!
//! The migration plan (open-questions resolution) measured that compiling the full
//! ported baseline at scanner startup is not viable: individual faithful rules take
//! seconds to determinize, tens of seconds in the worst case. So the baseline is
//! compiled once here, at build time, and serialized with the engine's `to_bytes`;
//! `lib.rs` embeds the blob with `include_bytes!` and the runtime loader rebuilds it
//! through the stage-one `load_precompiled` (the engine's validating `from_bytes`),
//! which only decodes, never recompiles. Only the small runtime rules files still
//! compile from text at startup.
//!
//! The two-form parse and literal escaper are shared verbatim with the runtime frx
//! compiler by `#[path]`-including the same source files: the build script cannot
//! `use` its own crate, so this is the only way to keep one parser. The engine is a
//! build-dependency so this script can call `RegexSet::new`.
// Scoped to this build-script compilation only. The shared `error.rs` this script
// `#[path]`-includes declares `LoadError::Compile` and `LoadError::Precompiled`, which
// the runtime `frx.rs` constructs but this build step does not (it only calls
// `parse_patterns`). Those variants are dead in the build-script crate yet live in the
// real crate, which keeps `-D dead_code`; suppressing here avoids editing the shared
// stage-one source to satisfy a build-script-only false positive.
/// Imports the engine's compiled-ruleset type built and serialized here.
use RegexSet;
/// Imports the environment and filesystem std pieces the build step reads and writes.
use ;
/// Registers the redacted load-error type shared with the runtime frx compiler.
///
/// The parser returns it; the build step never renders it with rule text, only its
/// `Display`, whose interpolations are an opaque index and a config flag letter.
/// Registers the literal-to-verbose-dialect escaper shared with the runtime compiler.
/// Registers the two-form file-format parser and flag policy shared with the runtime.
/// Compiles the ported baseline once and writes its serialized bytes into `OUT_DIR`.
///
/// Parses the committed, generated `data/builtin-rules.ported.txt` through the shared
/// two-form parser, compiles the whole set through the engine, serializes it, and
/// writes the blob for `include_bytes!`. A parse or compile failure fails the build,
/// which is the correct fail-closed response to a corrupt or un-ported baseline; the
/// error is surfaced only through its redacted `Display`, never rule text.