Skip to main content

hm_plugin_protocol/
hook.rs

1//! Lifecycle hook wire types.
2
3use schemars::JsonSchema as DeriveJsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::events::BuildEvent;
7
8/// Hook entry-point input. The host wraps a `BuildEvent` and tells
9/// the plugin which phase this call is.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
11#[serde(deny_unknown_fields)]
12pub struct HookEvent {
13    pub event: BuildEvent,
14    pub phase: HookPhase,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
18#[serde(rename_all = "snake_case")]
19pub enum HookPhase {
20    /// May return [`HookOutcome::Abort`] to fail the build.
21    Before,
22    /// Read-only; the return value is discarded.
23    After,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, DeriveJsonSchema)]
27#[serde(tag = "kind", rename_all = "snake_case")]
28pub enum HookOutcome {
29    /// Continue the build.
30    Continue,
31    /// Abort the build. Only honoured for `phase: Before`; ignored on
32    /// `After` (with a host-side warning).
33    Abort { reason: String },
34}
35
36/// Subset of [`crate::hook::HookEvent`] discriminants used at manifest time.
37///
38/// The manifest declares *what* events the plugin wants, not the per-event
39/// payload. Kept in this file so plugin authors only import one module.
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, DeriveJsonSchema)]
41#[serde(rename_all = "snake_case")]
42pub enum HookEventKind {
43    BuildStart,
44    StepQueued,
45    StepStart,
46    StepLog,
47    StepCacheHit,
48    StepEnd,
49    BuildEnd,
50}