mirror of
https://github.com/extism/extism.git
synced 2026-01-09 22:07:57 -05:00
feat: add overview on generating bindings (#789)
Primarily adds the Generating Bindings section, but also updates the PDK and SDK list to include more languages.
This commit is contained in:
72
README.md
72
README.md
@@ -61,11 +61,11 @@ started:
|
|||||||
|
|
||||||
# Compile WebAssembly to run in Extism Hosts
|
# Compile WebAssembly to run in Extism Hosts
|
||||||
|
|
||||||
Extism Hosts (running the SDK) must execute WebAssembly code that has a [PDK, or Plug-in Development Kit](https://extism.org/docs/concepts/pdk),
|
Extism Hosts (running the SDK) must execute WebAssembly code that has a
|
||||||
library compiled in to the `.wasm` binary. PDKs make it easy for plug-in /
|
[PDK, or Plug-in Development Kit](https://extism.org/docs/concepts/pdk), library
|
||||||
extension code authors to read input from the host and return data back, read
|
compiled in to the `.wasm` binary. PDKs make it easy for plug-in / extension
|
||||||
provided configuration, set/get variables, make outbound HTTP calls if allowed,
|
code authors to read input from the host and return data back, read provided
|
||||||
and more.
|
configuration, set/get variables, make outbound HTTP calls if allowed, and more.
|
||||||
|
|
||||||
Pick a PDK to import into your Wasm program, and refer to the documentation to
|
Pick a PDK to import into your Wasm program, and refer to the documentation to
|
||||||
get started:
|
get started:
|
||||||
@@ -74,13 +74,73 @@ get started:
|
|||||||
| ------------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------------- |
|
| ------------------ | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | --------------------------------------------------------- |
|
||||||
| Rust PDK | <img alt="Rust PDK" src="https://extism.org/img/sdk-languages/rust.svg" width="50px"/> | https://github.com/extism/rust-pdk | [Crates.io](https://crates.io/crates/extism-pdk) |
|
| Rust PDK | <img alt="Rust PDK" src="https://extism.org/img/sdk-languages/rust.svg" width="50px"/> | https://github.com/extism/rust-pdk | [Crates.io](https://crates.io/crates/extism-pdk) |
|
||||||
| JS PDK | <img alt="JS PDK" src="https://extism.org/img/sdk-languages/js.svg" width="50px"/> | https://github.com/extism/js-pdk | N/A |
|
| JS PDK | <img alt="JS PDK" src="https://extism.org/img/sdk-languages/js.svg" width="50px"/> | https://github.com/extism/js-pdk | N/A |
|
||||||
|
| Python PDK | <img alt="Python PDK" src="https://extism.org/img/sdk-languages/python.svg" width="50px"/> | https://github.com/extism/python-pdk | N/A |
|
||||||
| Go PDK | <img alt="Go PDK" src="https://extism.org/img/sdk-languages/go.svg" width="50px"/> | https://github.com/extism/go-pdk | [Go mod](https://pkg.go.dev/github.com/extism/go-pdk) |
|
| Go PDK | <img alt="Go PDK" src="https://extism.org/img/sdk-languages/go.svg" width="50px"/> | https://github.com/extism/go-pdk | [Go mod](https://pkg.go.dev/github.com/extism/go-pdk) |
|
||||||
| Haskell PDK | <img alt="Haskell PDK" src="https://extism.org/img/sdk-languages/haskell.svg" width="50px"/> | https://github.com/extism/haskell-pdk | [Hackage](https://hackage.haskell.org/package/extism-pdk) |
|
| Haskell PDK | <img alt="Haskell PDK" src="https://extism.org/img/sdk-languages/haskell.svg" width="50px"/> | https://github.com/extism/haskell-pdk | [Hackage](https://hackage.haskell.org/package/extism-pdk) |
|
||||||
| AssemblyScript PDK | <img alt="AssemblyScript PDK" src="https://extism.org/img/sdk-languages/assemblyscript.svg" width="50px"/> | https://github.com/extism/assemblyscript-pdk | [NPM](https://www.npmjs.com/package/@extism/as-pdk) |
|
| AssemblyScript PDK | <img alt="AssemblyScript PDK" src="https://extism.org/img/sdk-languages/assemblyscript.svg" width="50px"/> | https://github.com/extism/assemblyscript-pdk | [NPM](https://www.npmjs.com/package/@extism/as-pdk) |
|
||||||
| .NET PDK | <img alt=".NET PDK" src="https://extism.org/img/sdk-languages/dotnet.svg" width="50px"/> | https://github.com/extism/dotnet-pdk <br/>(supports C# & F#!) | https://www.nuget.org/packages/Extism.Pdk |
|
| .NET PDK | <img alt=".NET PDK" src="https://extism.org/img/sdk-languages/dotnet.svg" width="50px"/> | https://github.com/extism/dotnet-pdk <br/>(supports C# & F#!) | [Nuget](https://www.nuget.org/packages/Extism.Pdk) |
|
||||||
| C PDK | <img alt="C PDK" src="https://extism.org/img/sdk-languages/c.svg" width="50px"/> | https://github.com/extism/c-pdk | N/A |
|
| C PDK | <img alt="C PDK" src="https://extism.org/img/sdk-languages/c.svg" width="50px"/> | https://github.com/extism/c-pdk | N/A |
|
||||||
|
| C++ PDK | <img alt="C++ PDK" src="https://extism.org/img/sdk-languages/cpp.svg" width="50px"/> | https://github.com/extism/cpp-pdk | N/A |
|
||||||
| Zig PDK | <img alt="Zig PDK" src="https://extism.org/img/sdk-languages/zig.svg" width="50px"/> | https://github.com/extism/zig-pdk | N/A |
|
| Zig PDK | <img alt="Zig PDK" src="https://extism.org/img/sdk-languages/zig.svg" width="50px"/> | https://github.com/extism/zig-pdk | N/A |
|
||||||
|
|
||||||
|
# Generating Bindings
|
||||||
|
|
||||||
|
It's often very useful to define a schema to describe the function signatures
|
||||||
|
and types you want to use between Extism SDK and PDK languages.
|
||||||
|
|
||||||
|
[XTP Bindgen](https://github.com/dylibso/xtp-bindgen) is an open source
|
||||||
|
framework to generate PDK bindings for Extism plug-ins. It's used by the
|
||||||
|
[XTP Platform](https://www.getxtp.com/), but can be used outside of the platform
|
||||||
|
to define any Extism compatible plug-in system.
|
||||||
|
|
||||||
|
## 1. Install the `xtp` CLI.
|
||||||
|
|
||||||
|
See installation instructions
|
||||||
|
[here](https://docs.xtp.dylibso.com/docs/cli#installation).
|
||||||
|
|
||||||
|
## 2. Create a schema using our OpenAPI-inspired IDL:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: v1-draft
|
||||||
|
exports:
|
||||||
|
CountVowels:
|
||||||
|
input:
|
||||||
|
type: string
|
||||||
|
contentType: text/plain; charset=utf-8
|
||||||
|
output:
|
||||||
|
$ref: "#/components/schemas/VowelReport"
|
||||||
|
contentType: application/json
|
||||||
|
# components.schemas defined in example-schema.yaml...
|
||||||
|
```
|
||||||
|
|
||||||
|
> See an example in [example-schema.yaml](./example-schema.yaml), or a full
|
||||||
|
> "kitchen sink" example on
|
||||||
|
> [the docs page](https://docs.xtp.dylibso.com/docs/concepts/xtp-schema/).
|
||||||
|
|
||||||
|
## 3. Generate bindings to use from your plugins:
|
||||||
|
|
||||||
|
```
|
||||||
|
xtp plugin init --schema-file ./example-schema.yaml
|
||||||
|
> 1. TypeScript
|
||||||
|
2. Go
|
||||||
|
3. Rust
|
||||||
|
4. Python
|
||||||
|
5. C#
|
||||||
|
6. Zig
|
||||||
|
7. C++
|
||||||
|
8. GitHub Template
|
||||||
|
9. Local Template
|
||||||
|
```
|
||||||
|
|
||||||
|
This will create an entire boilerplate plugin project for you to get started
|
||||||
|
with. Implement the empty function(s), and run `xtp plugin build` to compile
|
||||||
|
your plugin.
|
||||||
|
|
||||||
|
> For more information about XTP Bindgen, see the
|
||||||
|
> [dylibso/xtp-bindgen](https://github.com/dylibso/xtp-bindgen) repository and
|
||||||
|
> the official
|
||||||
|
> [XTP Schema documentation](https://docs.xtp.dylibso.com/docs/concepts/xtp-schema).
|
||||||
|
|
||||||
# Support
|
# Support
|
||||||
|
|
||||||
## Discord
|
## Discord
|
||||||
|
|||||||
28
example-schema.yaml
Normal file
28
example-schema.yaml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# yaml-language-server: $schema=https://xtp.dylibso.com/assets/wasm/schema.json
|
||||||
|
# Learn more at https://docs.xtp.dylibso.com/docs/concepts/xtp-schema
|
||||||
|
version: v1-draft
|
||||||
|
exports:
|
||||||
|
CountVowels:
|
||||||
|
input:
|
||||||
|
type: string
|
||||||
|
contentType: text/plain; charset=utf-8
|
||||||
|
output:
|
||||||
|
$ref: "#/components/schemas/VowelReport"
|
||||||
|
contentType: application/json
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
VowelReport:
|
||||||
|
description: The result of counting vowels on the Vowels input.
|
||||||
|
properties:
|
||||||
|
count:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
description: The count of vowels for input string.
|
||||||
|
total:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
description: The cumulative amount of vowels counted, if this keeps state across multiple function calls.
|
||||||
|
nullable: true
|
||||||
|
vowels:
|
||||||
|
type: string
|
||||||
|
description: The set of vowels used to get the count, e.g. "aAeEiIoOuU"
|
||||||
Reference in New Issue
Block a user