Grove/lib.rs
1#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
2
3//! Grove - Rust/WASM Extension Host for VS Code
4//!
5//! Grove provides a secure, sandboxed environment for running VS Code
6//! extensions compiled to WebAssembly or native Rust. It complements Cocoon
7//! (Node.js) by offering a native extension host with full WASM support.
8//!
9//! # Architecture
10//!
11//! ```text
12//! +++++++++++++++++++++++++++++++++++++++++++
13//! + Extension Host +
14//! +++++++++++++++++++++++++++++++++++++++++++
15//! + Extension Manager → Activation Engine +
16//! + API Bridge → VS Code API +
17//! +++++++++++++++++++++++++++++++++++++++++++
18//! +
19//! ++++++++++++++++++++▼++++++++++++++++++++++
20//! + WASM Runtime (WASMtime) +
21//! + Module Loader → Host Bridge +
22//! +++++++++++++++++++++++++++++++++++++++++++
23//! +
24//! ++++++++++++++++++++▼++++++++++++++++++++++
25//! + Transport Layer +
26//! + gRPC | IPC | Direct WASM +
27//! +++++++++++++++++++++++++++++++++++++++++++
28//! ```
29//!
30//! # Features
31//!
32//! - **Standalone Operation**: Run independently or connect to Mountain via
33//! gRPC
34//! - **WASM Support**: Full WebAssembly runtime with WASMtime
35//! - **Multiple Transport**: gRPC, IPC, and direct WASM communication
36//! - **Secure Sandboxing**: WASMtime-based isolation for untrusted extensions
37//! - **Cocoon Compatible**: Shares API surface with Node.js host
38//!
39//! # Example: Standalone Usage
40//!
41//! ```rust,no_run
42//! use grove::{ExtensionHost, Transport};
43//!
44//! #[tokio::main]
45//! async fn main() -> anyhow::Result<()> {
46//! let host = ExtensionHost::new(Transport::default()).await?;
47//! host.load_extension("/path/to/extension").await?;
48//! host.activate().await?;
49//! Ok(())
50//! }
51//! ```
52//!
53//! # Module Organization
54//!
55//! - [`Host`] - Extension hosting core (ExtensionHost, ExtensionManager, etc.)
56//! - [`WASM`] - WebAssembly runtime integration
57//! - [`Transport`] - Communication strategies (gRPC, IPC, WASM)
58//! - [`API`] - VS Code API facade and types
59//! - [`Protocol`] - Protocol handling (Spine connection)
60//! - [`Services`] - Host services (configuration, etc.)
61//! - [`Common`] - Shared utilities and error types
62
63#![warn(missing_docs)]
64#![deny(unsafe_code)]
65#![warn(clippy::all)]
66#![allow(non_snake_case, non_camel_case_types, unexpected_cfgs)]
67
68// Public module declarations
69pub mod API;
70
71pub mod Binary;
72
73pub mod Common;
74
75pub mod DevLog;
76
77pub mod Host;
78
79pub mod Protocol;
80
81pub mod Services;
82
83pub mod Transport;
84
85pub mod WASM;
86
87// Library version
88const VERSION:&str = env!("CARGO_PKG_VERSION");
89
90/// Grove library information
91#[derive(Debug, Clone)]
92pub struct GroveInfo {
93 /// Version string
94 pub version:&'static str,
95
96 /// Build timestamp
97 #[allow(dead_code)]
98 build_timestamp:String,
99}
100
101impl GroveInfo {
102 /// Create new GroveInfo with current build information
103 pub fn new() -> Self { Self { version:VERSION, build_timestamp:env!("VERGEN_BUILD_TIMESTAMP").to_string() } }
104
105 /// Get the Grove version
106 pub fn version(&self) -> &'static str { self.version }
107}
108
109impl Default for GroveInfo {
110 fn default() -> Self { Self::new() }
111}
112
113/// Initialize Grove library
114///
115/// This sets up logging and other global state.
116/// Call once at application startup.
117pub fn init() -> anyhow::Result<()> {
118 use crate::dev_log;
119
120 dev_log!("grove", "Grove v{} initialized", VERSION);
121
122 Ok(())
123}
124
125#[cfg(test)]
126mod tests {
127
128 use super::*;
129
130 #[test]
131 fn test_version() {
132 assert!(!VERSION.is_empty());
133
134 assert!(VERSION.contains('.'));
135 }
136
137 #[test]
138 fn test_grove_info() {
139 let info = GroveInfo::new();
140
141 assert_eq!(info.version(), VERSION);
142 }
143}