Skip to main content

Crate crepuscularity_lite

Crate crepuscularity_lite 

Source
Expand description

crepuscularity-lite — embed a V8 guest + Capacitor-shaped Rust bridge inside a GPUI (or other) host.

Development can run TypeScript / TSX guest entries through the built-in Oxc transpiler. Production bundling, chunking, and code splitting are still the embedder’s or CLI toolchain’s job; use the cl build esbuild path for bundled output, or multiple sources with config::CrepusLiteConfig::guest_prelude / separate worker scripts (see docs/THREADING.md).

§How this relates to GPUI and Rust

  • Rust plugins are normal Rust: types implementing NativePlugin. They are registered on a Bridge and reached from JS via Crepus.invoke(...).
  • GPUI is not “hooked” automatically. V8 does not register GPUI actions!, keymaps, or subscriptions for you. You call V8Host::eval (or run scripts) from your GPUI event closures—the same places you would call any other Rust code.
  • Window / UI-thread work from plugins is deferred (e.g. HostDeferred::SetWindowTitle). After guest code runs, call integration::apply_window_deferred with a live GPUI Window so those operations hit the real window.
  • Hot reload: guest_watch::spawn_guest_file_watcher watches guest file paths; the callback must be Send and should only signal the UI thread (see docs/THREADING.md and the package binary).
  • Bridge in V8: each V8Host installs an embedder slot on the isolate’s context (CrepusBridgeSlot in v8_host.rs); Crepus.invoke reads the bridge from the current context (no process-global ACTIVE_BRIDGE).
  • Optional TOML caps: config::CrepusLiteConfig::build_bridge respects [capabilities] (see examples/*/crepus-lite.example.toml).

For a full demo, run the package binary (see src/main.rs).

Re-exports§

pub use bench_eval::bench_matrix_shared_for_configs;
pub use bench_eval::eval_guest_from_config_file;
pub use bench_eval::BenchMatrixShared;
pub use bench_plugin::BenchPlugin;
pub use bridge::Bridge;
pub use bridge::BridgeError;
pub use bridge::Capability;
pub use bridge::NativePlugin;
pub use download_plugin::DownloadPlugin;
pub use guest_compiler::prepare_guest_source;
pub use host::HostEventRecord;
pub use host::HostNode;
pub use host::HostRoute;
pub use host::HostSnapshot;
pub use host::HostState;
pub use host::HostStyle;
pub use host_queue::DeferredWindowDecorations;
pub use host_queue::HostCommandQueue;
pub use host_queue::HostDeferred;
pub use plugins::AppPlugin;
pub use plugins::ClipboardPlugin;
pub use plugins::CorePlugin;
pub use plugins::FsPlugin;
pub use plugins::HostPlugin;
pub use plugins::WindowPlugin;
pub use v8_host::V8Host;
pub use v8_thread::V8ThreadHandle;
pub use v8_thread::V8ThreadRequest;
pub use v8_thread::V8ThreadRuntime;
pub use worker::WorkerHandle;
pub use worker::WorkerRuntime;

Modules§

bench_eval
Headless guest evaluation for benchmark tooling (no GPUI).
bench_plugin
Native benchmark plugin — Rust and GPUI-simulated suites.
bridge
Capacitor-shaped native bridge: plugins live in Rust; JS calls Crepus.invoke(plugin, method, payloadJson).
clipboard
Shared clipboard backend used by the Rust plugin and the host UI.
config
Optional crepus-lite.toml project file (guest entry path, flags, capabilities).
download_plugin
Native download manager used by the Motrix example.
guest_compiler
Guest-source preparation before V8 evaluation.
guest_watch
Debounced filesystem watch for a guest script path. The callback runs on the debouncer thread (see notify-debouncer-mini); schedule GPUI / UI-thread work yourself (for example via gpui::AsyncApp::foreground_executor).
host
Host-side state for the GPUI-backed guest runtime.
host_queue
Deferred work that must run on the GPUI thread with a live window (e.g. native title APIs).
integration
Glue between the bridge / V8 host and GPUI on the UI thread.
plugins
Built-in plugins registered on Bridge.
v8_host
Embedded JavaScript via the official v8 crate (the Rust bindings project is often called rusty_v8). See docs/THREADING.md for thread constraints.
v8_thread
Dedicated OS thread that owns a V8Host so GPUI never blocks on eval.
worker
Optional compute worker: a second V8 isolate on a dedicated thread with a restricted bridge (Bridge::compute_only_bridge) — core + app only, no FS/window until those plugins are audited for concurrent invoke.