Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Elixir into 'Language Support' #5582

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ Hello, world!
## Language Support

You can use Wasmtime from a variety of different languages through embeddings of
the implementation:
the implementation.

Languages supported by the Bytecode Alliance:

* **[Rust]** - the [`wasmtime` crate]
* **[C]** - the [`wasm.h`, `wasi.h`, and `wasmtime.h` headers][c-headers], [CMake](crates/c-api/CMakeLists.txt) or [`wasmtime` Conan package]
Expand All @@ -118,6 +120,10 @@ the implementation:
* **[Go]** - the [`wasmtime-go` repository]
* **[Ruby]** - the [`wasmtime` gem]

Languages supported by the community:

* **[Elixir]** - the [`wasmex` hex package]

[Rust]: https://bytecodealliance.github.io/wasmtime/lang-rust.html
[C]: https://bytecodealliance.github.io/wasmtime/examples-c-embed.html
[`wasmtime` crate]: https://crates.io/crates/wasmtime
Expand All @@ -133,6 +139,8 @@ the implementation:
[`wasmtime-cpp` Conan package]: https://conan.io/center/wasmtime-cpp
[Ruby]: https://bytecodealliance.github.io/wasmtime/lang-ruby.html
[`wasmtime` gem]: https://rubygems.org/gems/wasmtime
[Elixir]: https://docs.wasmtime.dev/lang-elixir.html
[`wasmex` hex package]: https://hex.pm/packages/wasmex

## Documentation

Expand Down
43 changes: 43 additions & 0 deletions docs/lang-elixir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Using WebAssembly from Elixir

Wasmtime [is available on Hex](https://hex.pm/packages/wasmex) and can
be used programmatically to interact with Wasm modules. This guide will go over
installing the wasmex package and running a simple Wasm module from Elixir.

## Getting started and simple example

First, copy this example WebAssembly text module into the current directory. It exports
a function for calculating the greatest common denominator of two numbers.

```wat
{{#include ../examples/gcd.wat}}
```

The library has a Rust-based native extension, but thanks to `rustler_precompiled`, you
should not have to compile anything. It'll just work!

This WAT file can be executed in `iex`:

```elixir
Mix.install([:wasmex])
bytes = File.read!("gcd.wat")
{:ok, pid} = Wasmex.start_link(%{bytes: bytes}) # starts a GenServer running a WASM instance
Wasmex.call_function(pid, "gcd", [27, 6])
```

The last command should output:

```elixir
iex(5)> Wasmex.call_function(pid, "gcd", [27, 6])
{:ok, [3]}
```

If this is the output you see, congrats! You've successfully ran your first
WebAssembly code in Elixir!

## More examples and contributing

To learn more, check out an [another example](https://github.com/tessi/wasmex#example)
and the [API documentation](https://hexdocs.pm/wasmex/Wasmex.html).
If you have any questions, do not hesitate to open an issue on the
[GitHub repository](https://github.com/tessi/wasmex).
1 change: 1 addition & 0 deletions docs/lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ through a C API for a number of other languages too:
* [Go](lang-go.md)
* [Bash](lang-bash.md)
* [Ruby](lang-ruby.md)
* [Elixir](lang-elixir.md)