Stream: cargo-component

Topic: creating a crate to wrap a subset of host functionality


view this post on Zulip Chris Dickinson (Oct 16 2023 at 18:37):

Hi folks! I'm adding component model support for dylibso's observe-sdk and am running into #76 – in particular, the observe SDK adds a set of functions to the host interface (span-{enter,exit,tags}, log, etc) and I'd like to wrap them in a crate.

I have two options – one of which is implemented in a PR here.

  1. Provide an observe-api crate which links to the appropriate core-module-level functions. This effectively "puns" the canonical abi. This has some upsides and downsides. The main upside is that we can provide a higher-level abstraction over the generated WIT interface. Right now that looks like being able to gracefully map log::Level and other enums to our WIT enums (which happen to be off-by-one.) I can see three downsides: users can still access the unwrapped, generated bindings through use bindings::dylibso::observe_sdk::api, the crate is effectively punning the ABI – which might change, and users have to represent this as two dependencies (one crate-level on observe-api, and one at the component.target level on the observe.wit bindings)

  2. Alternatively, we could hold off on making a crate for now & provide user access exclusively through the bindings:: api. This is workable, but pushes more work onto the observe api user – e.g., they have to cast log::Level to generated bindings::dylibso::observe_sdk::api::LogLevel` before calling, etc. We kind of lose a communication channel with folks using the API – in the sense that a crate would give us the usual affordances like release versioning, a CHANGELOG, etc.

Ideally, I'd like to go with the first approach, with a stretch goal of having the observe_api crate somehow _contribute_ WIT interface imports automatically to dependent worlds. I'm not quite sure what that would look like, though. Would y'all have any recommendations for approaching this problem? Are there other folks solving something similar?

This is a continuation of #75, which exposes the use case. Quoting @peterhuene here: For the feature request, I think it would be along the lines of: Allow component metadata in lib packages that a...
upgrade to wasmtime>=13, wasmtime_wasi>=13 the component model necessitated splitting the adapter setup into two parts: first creating the adapter so it can be associated with the state, then telli...
upgrade to wasmtime>=13, wasmtime_wasi>=13 the component model necessitated splitting the adapter setup into two parts: first creating the adapter so it can be associated with the state, then...

Last updated: Oct 23 2024 at 20:03 UTC