Skip to content

Commit

Permalink
Rustler 0.30 & latest Elixir/Erlang (#511)
Browse files Browse the repository at this point in the history
* Update elixir/erlang

* Update rustler/precompiled

* Bump elixir/erlang in github action

* Update to latest TermType

* Check compatibility for Elixir 1.16

* Lock file changed

* Properly handle either integer/float term type

* Rust lint errors

* Bump elixir

* remove dialyzer

---------

Co-authored-by: Philipp Tessenow <philipp@tessenow.org>
  • Loading branch information
RoyalIcing and tessi authored Mar 6, 2024
1 parent 8c7e8d5 commit 5f3f2fe
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 100 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/compatibility-elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
strategy:
fail-fast: false
matrix:
otp: [24.3, 25.2, 26.1]
elixir: [1.13.4, 1.14.5, 1.15.6]
otp: [24.3, 25.2, 26.2]
elixir: [1.13.4, 1.14.5, 1.15.6, 1.16.1]
exclude:
- otp: 26.1
- otp: 26.2
elixir: 1.13.4
steps:
- uses: actions/checkout@v3
Expand Down
33 changes: 2 additions & 31 deletions .github/workflows/elixir-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- main

env:
ELIXIR_VERSION: 1.15.6
OTP_VERSION: 26.1
ELIXIR_VERSION: 1.16.1
OTP_VERSION: 26.2.1
MIX_ENV: test
WASMEX_BUILD: true

Expand Down Expand Up @@ -76,35 +76,6 @@ jobs:

- run: mix format --check-formatted

dialyzer:
needs: deps
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ env.OTP_VERSION }}
elixir-version: ${{ env.ELIXIR_VERSION }}

- uses: actions/cache@v2
id: cache-deps
with:
path: |
deps
_build
key: ${{ needs.deps.outputs.deps-cache-key }}

- uses: actions/cache@v2
id: plt-cache
with:
path: priv/plts
key: v2-plt-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}

- run: mix dialyzer --plt
if: steps.plt-cache.outputs.cache-hit != 'true'

- run: mix dialyzer

docs:
needs: deps
runs-on: ubuntu-latest
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ test/wasm_source/target/*
wapm_packages/*
wapm.lock

# The PLT files for `dialyzer`
/priv/plts/*.plt
/priv/plts/*.plt.hash

# ignore local builds
checksum-Elixir.Wasmex.Native.exs
*.so
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 26.1
elixir 1.15.6
erlang 26.2.1
elixir 1.16.1-otp-26
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ If you plan to change something on the Rust part of this project, set the follow
I´m looking forward to your contributions. Please open a PR containing the motivation of your change. If it is a bigger change or refactoring, consider creating an issue first. We can discuss changes there first which might safe us time down the road :)

Any changes should be covered by tests, they can be run with `mix test`.
In addition to tests, we expect the formatters and linters (`cargo fmt`, `cargo clippy`, `mix format`, `mix dialyzer`, `mix credo`) to pass.
In addition to tests, we expect the formatters and linters (`cargo fmt`, `cargo clippy`, `mix format`, `mix credo`) to pass.

### Release

Expand Down
10 changes: 3 additions & 7 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ defmodule Wasmex.MixProject do
name: "wasmex",
description: description(),
package: package(),
deps: deps(),
dialyzer: [
plt_file: {:no_warn, "priv/plts/dialyzer.plt"}
]
deps: deps()
]
end

Expand All @@ -29,10 +26,9 @@ defmodule Wasmex.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:rustler_precompiled, "~> 0.6.3"},
{:rustler, "~> 0.29.1"},
{:rustler_precompiled, "~> 0.7.1"},
{:rustler, "~> 0.30.0"},
{:ex_doc, "~> 0.30.2", only: [:dev, :test]},
{:dialyxir, "~> 1.4.1", only: [:dev, :test], runtime: false},
{:credo, "~> 1.6", only: [:dev, :test], runtime: false}
]
end
Expand Down
7 changes: 3 additions & 4 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
%{
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
"castore": {:hex, :castore, "1.0.3", "7130ba6d24c8424014194676d608cb989f62ef8039efd50ff4b3f33286d06db8", [:mix], [], "hexpm", "680ab01ef5d15b161ed6a95449fac5c6b8f60055677a8e79acf01b27baa4390b"},
"castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
"credo": {:hex, :credo, "1.7.0", "6119bee47272e85995598ee04f2ebbed3e947678dee048d10b5feca139435f75", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "6839fcf63d1f0d1c0f450abc8564a57c43d644077ab96f2934563e68b8a769d7"},
"dialyxir": {:hex, :dialyxir, "1.4.1", "a22ed1e7bd3a3e3f197b68d806ef66acb61ee8f57b3ac85fc5d57354c5482a93", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "84b795d6d7796297cca5a3118444b80c7d94f7ce247d49886e7c291e1ae49801"},
"earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.30.9", "d691453495c47434c0f2052b08dd91cc32bc4e1a218f86884563448ee2502dd2", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d7aaaf21e95dc5cddabf89063327e96867d00013963eadf2c6ad135506a8bc10"},
Expand All @@ -12,7 +11,7 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"},
"rustler": {:hex, :rustler, "0.29.1", "880f20ae3027bd7945def6cea767f5257bc926f33ff50c0d5d5a5315883c084d", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "109497d701861bfcd26eb8f5801fe327a8eef304f56a5b63ef61151ff44ac9b6"},
"rustler_precompiled": {:hex, :rustler_precompiled, "0.6.3", "f838d94bc35e1844973ee7266127b156fdc962e9e8b7ff666c8fb4fed7964d23", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "e18ecca3669a7454b3a2be75ae6c3ef01d550bc9a8cf5fbddcfff843b881d7c6"},
"rustler": {:hex, :rustler, "0.30.0", "cefc49922132b072853fa9b0ca4dc2ffcb452f68fb73b779042b02d545e097fb", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "9ef1abb6a7dda35c47cfc649e6a5a61663af6cf842a55814a554a84607dee389"},
"rustler_precompiled": {:hex, :rustler_precompiled, "0.7.1", "ecadf02cc59a0eccbaed6c1937303a5827fbcf60010c541595e6d3747d3d0f9f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "b9e4657b99a1483ea31502e1d58c464bedebe9028808eda45c3a429af4550c66"},
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
}
8 changes: 4 additions & 4 deletions native/wasmex/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion native/wasmex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ path = "src/lib.rs"
crate-type = ["dylib"]

[dependencies]
rustler = { version = "0.29", default-features = false, features = ["derive", "nif_version_2_15"] }
rustler = { version = "0.30", default-features = false, features = [
"derive",
"nif_version_2_15",
] }
once_cell = "1.19.0"
rand = "0.8.5"
wasmtime = "12.0.2"
Expand Down
6 changes: 4 additions & 2 deletions native/wasmex/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn link_import(
let import_tuple = tuple::get_tuple(definition)?;

let import_type = import_tuple
.get(0)
.first()
.ok_or(Error::Atom("missing_import_type"))?;
let import_type =
Atom::from_term(*import_type).map_err(|_| Error::Atom("import type must be an atom"))?;
Expand Down Expand Up @@ -126,7 +126,7 @@ fn link_imported_function(
let caller_token = set_caller(caller);

let mut msg_env = OwnedEnv::new();
msg_env.send_and_clear(&pid.clone(), |env| {
let result = msg_env.send_and_clear(&pid.clone(), |env| {
let mut callback_params: Vec<Term> = Vec::with_capacity(params.len());
for value in params {
callback_params.push(match value {
Expand Down Expand Up @@ -183,6 +183,8 @@ fn link_imported_function(
.encode(env)
});

result.expect("expect no send error");

// Wait for the thread to start up - `receive_callback_result` is responsible for that.
let mut result = callback_token.token.return_values.lock().unwrap();
while result.is_none() {
Expand Down
85 changes: 47 additions & 38 deletions native/wasmex/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,55 +244,64 @@ pub fn decode_function_param_terms(
.enumerate()
{
let value = match (param, given_param.get_type()) {
(ValType::I32, TermType::Number) => match given_param.decode::<i32>() {
Ok(value) => WasmValue::I32(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i32 value.",
nth + 1
));
(ValType::I32, TermType::Integer | TermType::Float) => {
match given_param.decode::<i32>() {
Ok(value) => WasmValue::I32(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i32 value.",
nth + 1
));
}
}
},
(ValType::I64, TermType::Number) => match given_param.decode::<i64>() {
Ok(value) => WasmValue::I64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i64 value.",
nth + 1
));
}
(ValType::I64, TermType::Integer | TermType::Float) => {
match given_param.decode::<i64>() {
Ok(value) => WasmValue::I64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i64 value.",
nth + 1
));
}
}
},
(ValType::F32, TermType::Number) => match given_param.decode::<f32>() {
Ok(value) => {
if value.is_finite() {
WasmValue::F32(value)
} else {
}
(ValType::F32, TermType::Integer | TermType::Float) => {
match given_param.decode::<f32>() {
Ok(value) => {
if value.is_finite() {
WasmValue::F32(value)
} else {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f32 value.",
nth + 1
));
}
}
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f32 value.",
nth + 1
));
}
}
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f32 value.",
nth + 1
));
}
},
(ValType::F64, TermType::Number) => match given_param.decode::<f64>() {
Ok(value) => WasmValue::F64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f64 value.",
nth + 1
));
}
(ValType::F64, TermType::Integer | TermType::Float) => {
match given_param.decode::<f64>() {
Ok(value) => WasmValue::F64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f64 value.",
nth + 1
));
}
}
},
(_, term_type) => {
}
(val_type, term_type) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly value. Given `{:?}`.",
"Cannot convert argument #{} to a WebAssembly {:?} value. Given `{:?}`.",
nth + 1,
val_type,
PrintableTermType::PrintTerm(term_type)
));
}
Expand Down
5 changes: 2 additions & 3 deletions native/wasmex/src/printable_term_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ impl fmt::Debug for PrintableTermType {
match self {
PrintTerm(TermType::Atom) => write!(f, "Atom"),
PrintTerm(TermType::Binary) => write!(f, "Binary"),
PrintTerm(TermType::EmptyList) => write!(f, "EmptyList"),
PrintTerm(TermType::Exception) => write!(f, "Exception"),
PrintTerm(TermType::Fun) => write!(f, "Fun"),
PrintTerm(TermType::List) => write!(f, "List"),
PrintTerm(TermType::Map) => write!(f, "Map"),
PrintTerm(TermType::Number) => write!(f, "Number"),
PrintTerm(TermType::Integer) => write!(f, "Integer"),
PrintTerm(TermType::Float) => write!(f, "Float"),
PrintTerm(TermType::Pid) => write!(f, "Pid"),
PrintTerm(TermType::Port) => write!(f, "Port"),
PrintTerm(TermType::Ref) => write!(f, "Ref"),
Expand Down

0 comments on commit 5f3f2fe

Please sign in to comment.