Skip to main content

ComponentManager

Struct ComponentManager 

Source
pub struct ComponentManager { /* private fields */ }

Implementations§

Source§

impl ComponentManager

Source

pub fn from_lock( lock: ComponentLock, cache_root: impl Into<PathBuf>, target: impl Into<String>, host: AlefHostApiV1, ) -> Result<Self, ComponentError>

A manager for lock that accepts unsigned locks (SignaturePolicy::AllowUnsigned); see Self::from_lock_with_signature_policy to require signatures.

Source

pub fn from_lock_with_signature_policy( lock: ComponentLock, cache_root: impl Into<PathBuf>, target: impl Into<String>, host: AlefHostApiV1, signatures: SignaturePolicy, ) -> Result<Self, ComponentError>

Like Self::from_lock. With SignaturePolicy::Require the lock must embed at least one public key and every artifact (for every target) must name one of them in key_id, or this fails with ComponentError::UnsignedLock; every install then verifies the manifest signature. Without it, a lock with no keys is checked by digest alone, so anyone able to edit the lock can substitute an artifact.

Source

pub fn with_stdio_component(self, component_id: impl Into<String>) -> Self

Select the framed stdio transport for an executable component before first use.

The artifact, signature, lock and cache contract are identical to native components. All contracts of this component share one long-lived process. Only bytes invocation is supported; generated typed C tables and host callback services are unavailable.

Source

pub fn with_sidecar_timeout(self, timeout: Duration) -> Self

Set the response deadline for stdio handshakes and calls (default: 30 seconds). A timeout terminates the child; the connection is then respawned from the verified executable on a later call, within the restart budget (see Self::with_sidecar_restart_budget). On a protocol-2 connection a call’s timeout terminates the child only when the sidecar answered nothing during the whole deadline; otherwise only that call fails and its late response is dropped.

Source

pub fn with_sidecar_restart_budget(self, budget: u32) -> Self

Set how many times a stdio connection may be respawned from its verified executable after a fatal error (a timeout, a broken frame, a dead child: default 1). 0 restores the previous behavior, where the first fatal error stops the connection for good. A respawn re-runs the describe validation and replays the session setup before the connection serves calls again.

Source

pub fn with_sidecar_session(self, setup: SidecarSessionSetup) -> Self

Replay setup after the first spawn of every stdio component and after every respawn of its connection, where it re-sends whatever session the host had built on the previous connection (an Init call, one RegisterConfig per engine config). A setup failure stops the connection and fails the call that triggered the respawn. The setup must send its calls through the [SidecarSession] it is given: calling back into the manager, or into a component handle captured earlier, deadlocks.

Source

pub fn with_sidecar_restart_event(self, handler: SidecarRestartEvent) -> Self

Call handler with the component id and the new restart count after each successful stdio respawn, so hosts can log that a connection was rebuilt.

Source

pub fn with_sidecar_env_passthrough( self, names: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Pass these host environment variables through to stdio sidecars, on top of the default allowlist. A sidecar starts with a cleared environment holding only PATH, HOME, USER, LOGNAME, TMPDIR/TEMP/TMP, TZ, LANG, LANGUAGE and LC_* (plus SYSTEMROOT, WINDIR, SYSTEMDRIVE, USERPROFILE, PATHEXT and COMSPEC, which Windows processes need) and the protocol variable the runtime sets, and runs in its component’s cache directory. A name ending in * passes every variable with that prefix; names compare case-insensitively on Windows.

Source

pub fn sidecar_restart_count(&self, component_id: &str) -> Option<u32>

How many times the stdio connection of component_id has been respawned, or None when it was never spawned in this manager (or is not a stdio component).

Source

pub fn with_host_services(self, services: Arc<dyn HostServices>) -> Self

Expose services to components loaded from now on, through the host table’s service_call / service_notify callbacks. Components already loaded keep the table they were created with, so call this before Self::ensure_contract.

Source

pub fn offline(self, offline: bool) -> Self

Disable network downloads: Self::ensure_contract and Self::prefetch fail a missing artifact with ComponentError::Offline instead of attempting a request, and a damaged installed artifact with ComponentError::CachedObjectInvalid. An artifact already verified on disk (or served via a file:// URL) is unaffected. Generated bindings call this when the crate-specific {CRATE}_COMPONENT_OFFLINE environment variable is set.

Source

pub fn with_download_options(self, options: DownloadOptions) -> Self

Tune downloads: timeouts, retry policy, progress reporting and cancellation. Applies to Self::ensure_contract and Self::prefetch.

Source

pub fn with_url_override( self, resolve: impl Fn(&ComponentLockEntry) -> String + Send + Sync + 'static, ) -> Self

Download from resolve(entry) instead of the lock entry’s url, for mirrors and air-gapped hosts. The archive size, SHA-256 and signature are still checked against the lock, so a mirror cannot substitute different content. A file:// URL reads from disk.

ⓘ
let manager = manager.with_url_override(|entry| {
    entry.url.replacen("https://github.com/", "https://mirror.corp.example/github/", 1)
});
Source

pub fn with_mirror_base(self, base: impl Into<String>) -> Self

Download every archive from base instead of the lock’s URL, keeping only the archive file name: {base}/{file name}. A trailing slash on base is ignored.

Source

pub fn with_verified_stamp(self, enabled: bool) -> Self

Skip re-hashing installed libraries that match their verified stamp. See ArtifactCache::with_verified_stamp for the threat model.

Source

pub fn lock_entry( &self, component_id: &str, ) -> Result<&ComponentLockEntry, ComponentError>

The lock entry for component_id on this manager’s target, whatever its delivery mode.

Source

pub fn lock_entries(&self) -> Vec<&ComponentLockEntry>

Every lock entry for this manager’s target, sorted by component id.

Source

pub fn list_cached(&self) -> Result<Vec<CachedObject>, ComponentError>

Every object installed in the cache, including ones other host versions installed. component names the lock entry referencing the object, when this lock has one.

Source

pub fn remove( &self, component_id: &str, ) -> Result<RemovalReport, ComponentError>

Remove component_id’s cached object. It re-downloads on next use. On Windows an object whose library is loaded cannot be deleted; it is reported under skipped.

Source

pub fn prune(&self, retain: &Retain) -> Result<RemovalReport, ComponentError>

Remove cached objects retain does not keep, plus orphaned .install-* staging directories and stamps. Objects loaded in this process or being installed by another thread or process are skipped, as are files Windows refuses to delete; all are listed in the report.

Source

pub fn ensure_contract( &self, component_id: &str, contract_name: &str, entry_symbol: &[u8], ) -> Result<Arc<LoadedComponent>, ComponentError>

Load one contract a component provides.

entry_symbol is that contract’s NUL-terminated producer entry-point symbol (alef::codegen::component::entry_point_symbol); the caller supplies it because computing it requires the same identifier-casing logic the producer used, which this crate does not depend on.

Concurrent calls for the same (component_id, contract_name) coalesce onto one download-and-load: a second caller waits behind the first instead of racing a duplicate download or dlopen. A call for a different key is unaffected and proceeds immediately – the mutex guarding the loaded-component map is only ever held for a map lookup or insert, never across I/O.

Source

pub fn prefetch( &self, component_ids: &[&str], ) -> Result<Vec<CachedArtifact>, ComponentError>

Source

pub fn status( &self, component_id: &str, ) -> Result<ComponentStatus, ComponentError>

Report where component_id currently stands. Unlike Self::ensure_contract, Self::prefetch, and Self::cache_path, a Bundled entry is a legitimate answer here rather than a failure: it is this manager’s way of saying “linked in ahead of time, never downloaded or loaded through me”, not an error.

Source

pub fn cache_path(&self, component_id: &str) -> Result<PathBuf, ComponentError>

Source

pub fn cache_root(&self) -> &Path

Source

pub fn target(&self) -> &str

Trait Implementations§

Auto Trait Implementations§

§

impl !Freeze for ComponentManager

§

impl !RefUnwindSafe for ComponentManager

§

impl !UnwindSafe for ComponentManager

§

impl Forget for ComponentManager

§

impl Move for ComponentManager

§

impl Unpin for ComponentManager
where *const u8 is !null: Unpin, *const LeafNode<String, String> is !null: Unpin, Box<(String, String)>: Unpin, Arc<dyn Fn(u64, u64) + Send + Sync>: Unpin, Arc<Atomic<bool>>: Unpin, Arc<dyn Fn(&ComponentLockEntry) -> String + Send + Sync>: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, Arc<LoadedComponent>: Unpin, Arc<SidecarProcess>: Unpin, Arc<dyn Fn(&SidecarSession<'_>) -> Result<(), ComponentError> + Send + Sync>: Unpin, Arc<dyn Fn(&str, u32) + Send + Sync>: Unpin, Arc<Mutex<()>>: Unpin, Arc<File>: Unpin, *mut c_void: Unpin, Arc<dyn HostServices>: Unpin,

§

impl UnsafeUnpin for ComponentManager
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const LeafNode<String, String> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, String)>>: UnsafeUnpin, *const ArcInner<dyn Fn(u64, u64) + Send + Sync> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(u64, u64) + Send + Sync>>: UnsafeUnpin, *const ArcInner<Atomic<bool>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin, *const ArcInner<dyn Fn(&ComponentLockEntry) -> String + Send + Sync> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&ComponentLockEntry) -> String + Send + Sync>>: UnsafeUnpin, PhantomData<(String, ComponentLockEntry)>: UnsafeUnpin, Align4<u32>: UnsafeUnpin, Align1<u8>: UnsafeUnpin, PhantomData<(String, Arc<LoadedComponent>)>: UnsafeUnpin, PhantomData<(String, ())>: UnsafeUnpin, PhantomData<(String, Arc<SidecarProcess>)>: UnsafeUnpin, *const ArcInner<dyn Fn(&SidecarSession<'_>) -> Result<(), ComponentError> + Send + Sync> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&SidecarSession<'_>) -> Result<(), ComponentError> + Send + Sync>>: UnsafeUnpin, *const ArcInner<dyn Fn(&str, u32) + Send + Sync> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&str, u32) + Send + Sync>>: UnsafeUnpin, PhantomData<String>: UnsafeUnpin, PhantomData<(String, Arc<Mutex<()>>)>: UnsafeUnpin, PhantomData<(String, (CachedArtifact, VerifiedFile))>: UnsafeUnpin, *mut c_void: UnsafeUnpin, *const ArcInner<dyn HostServices> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn HostServices>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.