Building Spin components in other languages
This document is continuously evolving as we improve language SDKs and add more examples on how to build Spin components in various programming languages.
WebAssembly is becoming a popular compilation target for programming languages, and as language toolchains add support for the WebAssembly component model, building Spin components will also become supported.
As a general rule:
- if your language supports the
WebAssembly component model,
building Spin components is supported either through an official Spin SDK
(such as the Spin SDK for Rust), or through using
bindings generators like
wit-bindgen(for languages such as C and C++)
- if your language compiles to WASI, but doesn’t have support for the component model, you can build Spin HTTP components that use the Wagi executor — for example in languages such as Grain, AssemblyScript, or Python.
- if your language doesn’t currently compile to WASI, there is no way to build and run Spin components in that programming language
Make sure to check out a more complex Spin application with components built in multiple programming languages.
AssemblyScript is a TypeScript-based language that compiles directly to WebAssembly. AssemblyScript has WASI/Wagi support, and so can be used with Spin.
- The AssemblyScript entry in the Wasm Language Guide includes a full example
- The Spin Kitchen Sink repo has an AssemblyScript demo
- An example AssemblyScript app designed for Wagi runs on Spin
C and C++ are both broadly supported in the WebAssembly ecosystem. WASI/Wagi support means that both can be used to write Spin apps.
- The C entry in the Wasm Language Guide has examples.
- The C++ entry in the Wasm Language Guide has specific caveats for writing C++ (like exception handling)
- The yo-wasm project makes setting up C easier.
C# and .NET languages
.NET has experimental support for WASI, so many (if not all) .NET languages, including C# and F#, can be used to write Spin applications.
- The C# entry in the Wasm Language Guide has a full example.
- The Spin Kitchen Sink repo has two C# examples and one F# example.
Grain, a new functional programming language, has WASI/Wagi support and can be used to write Spin apps.
- The Grain entry in the Wasm Language Guide has details
- A simple Hello World example shows how to use Grain
- For a production-quality example. the Wagi Fileserver is written in Grain
Python’s interpreter can be compiled to WebAssembly, and it has WASI support. It is known to work for Spin.
- The Spin Kitchen Sink repo includes a Python example
- The Python entry in the Wasm Language Guide lists two implementations
- There is a Fermyon blog post about using Python with WAGI
- The Python docs have a page on WebAssembly
- SingleStore also has a Python build that uses mainline Python
Upstream Ruby officially supports WebAssembly and WASI, and we here at Fermyon have successfully run Ruby apps in Spin.
- The Ruby entry in the Wasm Language Guide has the latest information
- Ruby’s 3.2.0 Preview 1 release notes detail WASI support
Zig is a low-level systems language that has support for Wasm and WASI, and can be used to write Spin apps.