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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! 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.
//! Mutable runtime rules use a separate
//! content-addressed per-user artifact and compile from text only on cache recovery.
//!
//! 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 format autodetector,
/// legacy line parser,
/// and flag policy shared
/// with the runtime.
/// Registers the tail-format sectioned parser shared with the runtime.
///
/// The `format` module this build script includes now routes through the section
/// parser,
/// so the section source must be included here too or the shared `#[path]`
/// parser would not compile.
/// The committed baseline is legacy-format,
/// so this parser
/// is never exercised at build time;
/// it only needs to compile.
/// Compiles the ported baseline once and writes its serialized bytes into `OUT_DIR`,
/// beside a name sidecar carrying each rule's section name for finding identity.
///
/// Parses the committed,
/// generated `data/builtin-rules.txt` through the shared
/// parser,
/// compiles the whole set through the engine,
/// serializes it,
/// and writes the
/// blob for `include_bytes!` plus one sidecar line per rule (the rule's section
/// name,
/// or an empty line for an unnamed legacy rule) for `include_str!`.
/// 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.