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
//! Build utilities for Pinocchio programs in LiteSVM testing.
//!
//! This module provides build script utilities specifically designed for compiling Pinocchio
//! programs for use in LiteSVM tests. Pinocchio is a lightweight Solana program framework
//! that offers minimal boilerplate and direct BPF compilation.
//!
//! ## Key features:
//!
//! - **Automatic compilation**: Compiles Pinocchio programs during test build
//! - **Feature management**: Handles Pinocchio-specific feature flags like `bpf-entrypoint`
//! - **Build caching**: Only rebuilds when source files change
//! - **Error handling**: Clear error messages for common build issues
//!
//! ## Typical workflow:
//!
//! ```text
//! 1. Developer runs `cargo test`
//! 2. build.rs calls `build_pinocchio_program(program_path)`
//! 3. Function runs `cargo build-sbf --features bpf-entrypoint`
//! 4. Compiled .so file lands in target/deploy/
//! 5. Tests load program via `include_bytes!` and `svm.add_program()`
//! ```
//!
//! ## Pinocchio specifics:
//!
//! **Feature requirements**: Pinocchio programs need `bpf-entrypoint` feature for Solana deployment
//! **Minimal dependencies**: No IDL generation or complex build pipeline like Anchor
//! **Direct compilation**: Straight Rust-to-BPF compilation with minimal processing
//!
//! ## Example usage:
//!
//! In your test crate's `build.rs`:
//! ```rust,no_run
//! use litesvm_testing::pinocchio_testing::build_pinocchio_program;
//!
//! build_pinocchio_program("../my-pinocchio-program");
//! ```
use Path;
/// Build a Pinocchio program from a given path with the default features.
///
/// This is the standard entry point for compiling Pinocchio programs in test build scripts.
/// It automatically applies the `bpf-entrypoint` feature which is required for Solana deployment.
///
/// # Arguments
///
/// * `program_path` - The path to the Pinocchio program directory (contains Cargo.toml and src/ directory)
///
/// # Features applied
///
/// - `bpf-entrypoint` - Required for Solana BPF program compilation
///
/// # Example
///
/// ```rust,no_run
/// // In build.rs
/// use litesvm_testing::pinocchio_testing::build_pinocchio_program;
///
/// build_pinocchio_program("../simple-pinocchio-program");
/// ```
///
/// For custom feature configurations, use [`build_pinocchio_program_with_features`].
/// Build a Pinocchio program from a given path with specific features.
///
/// This function provides fine-grained control over which features are enabled during
/// Pinocchio program compilation. Use this when you need custom feature combinations
/// beyond the standard `bpf-entrypoint`.
///
/// # Arguments
///
/// * `program_path` - The path to the Pinocchio program directory (contains Cargo.toml and src/ directory)
/// * `features` - Array of feature names to enable during compilation
///
/// # Build process
///
/// 1. **Change detection**: Registers the Cargo.toml and src/ directory for rebuild triggers
/// 2. **Compilation**: Runs `cargo build-sbf` with specified features in a temp directory
/// 3. **Output**: Copies compiled `.so` file to `target/sbf-solana-solana/release/` directory
/// 4. **Error handling**: Provides detailed error messages for build failures
///
/// # Example
///
/// ```rust,no_run
/// // Custom features for specialized builds
/// use litesvm_testing::pinocchio_testing::build_pinocchio_program_with_features;
///
/// build_pinocchio_program_with_features(
/// "../my-program",
/// &["bpf-entrypoint", "custom-feature", "debug-mode"]
/// );
/// ```
///
/// # Error handling
///
/// The function will terminate the build process (`std::process::exit(1)`) if:
/// - `cargo build-sbf` command fails to execute
/// - Program compilation fails (non-zero exit status)
/// - Missing Solana CLI tools in PATH
///
/// Error output includes both stdout and stderr from the compilation process for debugging.
///
/// # Dependencies
///
/// Requires Solana CLI tools to be installed and available in PATH:
/// ```bash
/// sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
/// ```