Skip to main content

hara_native/
runtime_lib.rs

1#![allow(clippy::too_many_lines)] // Temporary compatibility facade during Java-port split.
2#[cfg(not(target_arch = "wasm32"))]
3pub mod asset;
4// Public embedding surface used by native hosts such as Hoplite. The module's
5// value, protocol, promise, and host-call types form the runtime integration ABI.
6#[cfg(all(target_arch = "wasm32", not(feature = "raw-wasm")))]
7mod browser_wasm_provider;
8pub mod command;
9mod clock;
10pub mod compiled_product;
11pub mod core;
12mod direct_wasm;
13pub mod extension;
14pub mod file;
15#[path = "file/interface.rs"]
16pub mod filesystem;
17#[path = "runtime/filesystem_bridge.rs"]
18mod filesystem_bridge;
19#[path = "runtime/filesystem_mount.rs"]
20mod filesystem_mount;
21#[path = "runtime/filesystem_adapter.rs"]
22pub mod filesystem_runtime;
23pub mod hta;
24#[cfg(not(target_arch = "wasm32"))]
25pub mod invoke_hta;
26pub mod wasm_binding;
27#[cfg(not(target_arch = "wasm32"))]
28pub use invoke_hta::{InvokeHtaError, MAX_INVOKE_HTA_RESULT_BYTES};
29#[cfg(not(target_arch = "wasm32"))]
30pub mod identity_tool;
31pub mod instrumentation;
32pub mod interpreter_observation;
33#[cfg(feature = "evaluation-journal")]
34pub mod journal;
35pub mod json;
36pub mod kernel;
37pub mod lang;
38pub mod live_session;
39#[cfg(not(target_arch = "wasm32"))]
40pub mod native_cli;
41#[cfg(not(target_arch = "wasm32"))]
42mod native_extension;
43#[cfg(not(target_arch = "wasm32"))]
44pub mod native_link;
45#[cfg(not(target_arch = "wasm32"))]
46pub mod native_module;
47#[cfg(not(target_arch = "wasm32"))]
48mod native_process;
49mod numeric;
50#[cfg(not(target_arch = "wasm32"))]
51pub mod package;
52pub mod package_catalog;
53#[cfg(not(target_arch = "wasm32"))]
54pub mod package_hta_loader;
55#[cfg(not(target_arch = "wasm32"))]
56pub mod package_manifest;
57#[cfg(not(target_arch = "wasm32"))]
58pub mod package_wasm_loader;
59#[cfg(not(target_arch = "wasm32"))]
60mod process_extension;
61#[cfg(not(target_arch = "wasm32"))]
62pub mod project;
63#[cfg(not(target_arch = "wasm32"))]
64pub mod resp;
65pub mod snapshot;
66#[cfg(not(target_arch = "wasm32"))]
67pub mod snapshot_tool;
68pub mod spec_registry;
69#[cfg(not(target_arch = "wasm32"))]
70pub mod tap;
71pub mod task;
72pub mod work;
73#[path = "work/session.rs"]
74mod work_session;
75// Experimental staged bytecode VM (issue #195). Non-default feature; the
76// default evaluator is untouched.
77#[cfg(all(feature = "direct-native", not(target_arch = "wasm32")))]
78pub mod direct_native;
79#[cfg(feature = "bytecode-vm")]
80#[path = "vm/schema_catalog.rs"]
81pub mod hbc_schema_catalog;
82#[cfg(feature = "bytecode-vm")]
83#[path = "vm/schema_links.rs"]
84pub mod hbc_schema_links;
85#[cfg(feature = "tracing-jit")]
86pub mod jit;
87#[cfg(feature = "bytecode-vm")]
88pub mod vm;
89#[cfg(not(target_arch = "wasm32"))]
90pub mod wasmtime_provider;
91#[cfg(feature = "whole-wasm")]
92pub mod whole_wasm;
93use crate::kernel::Form;
94use crate::lang::data::{OrderedMap as POrderedMap, Vector as PVector};
95use crate::lang::protocol::INamespaced;
96use std::cell::RefCell;
97use std::collections::{HashMap, HashSet};
98use std::rc::Rc;
99
100#[cfg(feature = "raw-wasm")]
101#[derive(Debug, Clone)]
102pub struct JsValue;
103
104#[cfg(feature = "raw-wasm")]
105impl JsValue {
106    fn from_str(_value: &str) -> Self {
107        Self
108    }
109}
110
111include!("runtime/execution_state.rs");
112include!("runtime/model.rs");
113include!("runtime/session_model.rs");
114include!("runtime/sandbox_model.rs");
115include!("runtime/session.rs");
116include!("runtime/session_live.rs");
117include!("runtime/session_instrumentation.rs");
118include!("runtime/sandbox.rs");
119include!("runtime/runtime.rs");
120include!("runtime/bytecode.rs");
121include!("runtime/evaluation.rs");
122include!("runtime/wasm.rs");
123
124/// Constructs the zero-authority Runtime profile used by an external secure
125/// [`SandboxProvider`] evaluator process.
126#[cfg(not(target_arch = "wasm32"))]
127pub fn restricted_sandbox_runtime() -> Runtime {
128    Runtime::sandbox()
129}
130
131/// Constructs the same restricted Runtime while restoring exactly the fully
132/// qualified `std.native.Host/call` operation behind a caller-supplied handler.
133#[cfg(not(target_arch = "wasm32"))]
134pub fn restricted_sandbox_runtime_with_host(
135    handler: Rc<dyn Fn(String, String, Vec<core::Value>) -> Result<core::Value, String>>,
136) -> Runtime {
137    let mut runtime = Runtime::sandbox();
138    runtime
139        .namespace_registry
140        .find_or_create("std.native.Host")
141        .intern_with_origin(
142            "call",
143            core::native_type_function_value("Host", "call")
144                .expect("std.native.Host/call must have a direct implementation"),
145            kernel::VarOrigin::RuntimePrimitive,
146        );
147    runtime.install_native_host_handler(handler);
148    runtime
149}
150
151#[cfg(test)]
152#[path = "runtime/filesystem_tests.rs"]
153mod filesystem_runtime_tests;
154
155#[cfg(test)]
156mod native_behavioral_conformance_tests;