Stream: C#/.net-collaboration

Topic: handling exports in SDK packages


view this post on Zulip Joel Dice (Jul 31 2024 at 14:07):

Hi all. I've been working on creating a new Spin .NET SDK that includes pre-generated bindings for one or more Spin WIT worlds, plus some hand-written helper code on top of those bindings to make the API more ergonomic to use.

One question that's come up (both with this SDK and the SDKs we've made for other languages) is how to handle exports. The SDK itself shouldn't export anything -- even if the world it is targeting has exports; the application using the SDK is the one that should implement any exports.

You could argue that the SDK could implement the exports and then, when the host calls an export, the SDK could call a callback registered by the application, but that won't work because the application never has a chance to register such a callback -- no guest code is run until the first export is called. Possibly this could be done via a core Wasm start function provided by the application, but I'm not sure how to tell the NativeAOT-LLVM ILC to emit such a function. I'll ask around about that if nobody here knows.

Assuming we can't use a start function to handle this, I think the next best option is to add an option to wit-bindgen telling it to split binding generation into two parts: one that generates all the types and imports, and another that generates the exports, reusing the types generated earlier. That way, we can put the types and imports in the SDK package, but leave it to the application to provide the exports. Once we've added such a feature to wit-bindgen, we'll also want to expose it somehow in componentize-dotnet.

Does that sound reasonable? Or are there other ways to tackle this that I haven't thought of?

Spin is the open source developer tool for building and running serverless applications powered by WebAssembly. - fermyon/spin

view this post on Zulip Joel Dice (Jul 31 2024 at 15:01):

Someone on Discord suggested using a ModuleInitializer to register callbacks. I'll try that.

This feature specification describes how to declare module initializers, which are methods called by the runtime when a module, or assembly, is loaded.

view this post on Zulip Scott Waye (Jul 31 2024 at 17:56):

does wasm_ld support the start function ? I seem to remember looking into this before

view this post on Zulip Joel Dice (Jul 31 2024 at 21:26):

Per the discussion starting here, we decided to use the split bindings approach.

Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.

Last updated: Dec 13 2025 at 20:04 UTC