Skip to content

Commit

Permalink
Remove macro_use for rustler; Import missing derived structs
Browse files Browse the repository at this point in the history
  • Loading branch information
scrogson committed Jul 12, 2024
1 parent 0dab3d1 commit 4aa5957
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 59 deletions.
4 changes: 1 addition & 3 deletions native/wasmex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ path = "src/lib.rs"
crate-type = ["dylib"]

[dependencies]
rustler = { version = "0.34", default-features = false, features = [
"nif_version_2_15", "big_integer"
] }
rustler = { version = "0.34", features = ["big_integer"] }
once_cell = "1.19.0"
rand = "0.8.5"
wasmtime = "22.0.0"
Expand Down
2 changes: 1 addition & 1 deletion native/wasmex/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// see: https://github.com/rust-lang/rust-clippy/issues/9778
#![allow(clippy::needless_borrow)]

use rustler::{types::Binary, Error, OwnedBinary, Resource, ResourceArc};
use rustler::{Binary, Error, NifStruct, OwnedBinary, Resource, ResourceArc};
use std::ops::Deref;
use std::sync::Mutex;
use wasmtime::{Config, Engine, WasmBacktraceDetails};
Expand Down
14 changes: 6 additions & 8 deletions native/wasmex/src/environment.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use std::sync::{Condvar, Mutex};

use rustler::{
types::tuple, Atom, Encoder, Error, ListIterator, MapIterator, OwnedEnv, ResourceArc, Term,
};
use wasmtime::{Caller, Engine, FuncType, Linker, Val, ValType};
use wiggle::anyhow::{self, anyhow};

use crate::{
atoms,
caller::{remove_caller, set_caller},
instance::{map_wasm_values_to_vals, LinkedModule, WasmValue},
memory::MemoryResource,
store::{StoreData, StoreOrCaller, StoreOrCallerResource},
};
use rustler::{
types::tuple, Atom, Encoder, Error, ListIterator, MapIterator, OwnedEnv, ResourceArc, Term,
};
use std::sync::{Condvar, Mutex};
use wasmtime::{Caller, Engine, FuncType, Linker, Val, ValType};
use wiggle::anyhow::{self, anyhow};

pub struct CallbackTokenResource {
pub token: CallbackToken,
Expand Down
22 changes: 10 additions & 12 deletions native/wasmex/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
use rustler::{
dynamic::TermType,
env::{OwnedEnv, SavedTerm},
types::{tuple::make_tuple, ListIterator},
Encoder, Env as RustlerEnv, Error, MapIterator, NifMap, NifResult, ResourceArc, Term,
};
use std::ops::Deref;
use std::sync::Mutex;
use std::thread;

use wasmtime::{Instance, Linker, Module, Val, ValType};

use crate::{
atoms,
environment::{link_imports, link_modules, CallbackTokenResource},
Expand All @@ -18,6 +6,16 @@ use crate::{
printable_term_type::PrintableTermType,
store::{StoreData, StoreOrCaller, StoreOrCallerResource},
};
use rustler::{
env::SavedTerm,
types::{tuple::make_tuple, ListIterator},
Encoder, Env as RustlerEnv, Error, MapIterator, NifMap, NifResult, OwnedEnv, ResourceArc, Term,
TermType,
};
use std::ops::Deref;
use std::sync::Mutex;
use std::thread;
use wasmtime::{Instance, Linker, Module, Val, ValType};

#[derive(NifMap)]
pub struct LinkedModule {
Expand Down
5 changes: 1 addition & 4 deletions native/wasmex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ pub mod pipe;
pub mod printable_term_type;
pub mod store;

#[macro_use]
extern crate rustler;

rustler::init! {"Elixir.Wasmex.Native"}
rustler::init!("Elixir.Wasmex.Native");
9 changes: 3 additions & 6 deletions native/wasmex/src/memory.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
//! Memory API of an WebAssembly instance.

use crate::store::{StoreOrCaller, StoreOrCallerResource};
use crate::{atoms, instance};
use rustler::{Atom, Binary, Error, NewBinary, NifResult, ResourceArc, Term};
use std::io::Write;
use std::sync::Mutex;

use rustler::{Atom, Binary, Error, NewBinary, NifResult, ResourceArc, Term};

use wasmtime::{Instance, Memory, Store};

use crate::store::{StoreOrCaller, StoreOrCallerResource};
use crate::{atoms, instance};

pub struct MemoryResource {
pub inner: Mutex<Memory>,
}
Expand Down
15 changes: 6 additions & 9 deletions native/wasmex/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
use crate::{
atoms,
engine::{unwrap_engine, EngineResource},
store::{StoreOrCaller, StoreOrCallerResource},
};
use rustler::{
types::{binary::Binary, tuple::make_tuple},
Encoder, Env, NifResult, OwnedBinary, ResourceArc, Term,
types::tuple::make_tuple, Binary, Encoder, Env, NifResult, OwnedBinary, ResourceArc, Term,
};
use std::{collections::HashMap, sync::Mutex};

use wasmtime::{
ExternType, FuncType, GlobalType, MemoryType, Module, Mutability, RefType, TableType, ValType,
};

use crate::{
atoms,
engine::{unwrap_engine, EngineResource},
store::{StoreOrCaller, StoreOrCallerResource},
};

pub struct ModuleResource {
pub inner: Mutex<Module>,
}
Expand Down
14 changes: 6 additions & 8 deletions native/wasmex/src/pipe.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
//! A Pipe is a file buffer hold in memory.
//! It can, for example, be used to replace stdin/stdout/stderr of a WASI module.

use rustler::{Encoder, ResourceArc, Term};
use std::any::Any;
use std::io::{self, Read, Seek};
use std::io::{Cursor, Write};
use std::io::{self, Cursor, Read, Seek, Write};
use std::sync::{Arc, Mutex, RwLock};

use rustler::{Encoder, ResourceArc, Term};

use wasi_common::file::{FdFlags, FileType};
use wasi_common::Error;
use wasi_common::WasiFile;
use wasi_common::{
file::{FdFlags, FileType},
Error, WasiFile,
};

use crate::atoms;

Expand Down
2 changes: 1 addition & 1 deletion native/wasmex/src/printable_term_type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustler::dynamic::TermType;
use rustler::TermType;

// PrintableTermType is a workaround for rustler::dynamic::TermType not having the Debug trait.
pub enum PrintableTermType {
Expand Down
13 changes: 6 additions & 7 deletions native/wasmex/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
// see: https://github.com/rust-lang/rust-clippy/issues/9778
#![allow(clippy::needless_borrow)]

use rustler::{Error, ResourceArc};
use crate::{
caller::{get_caller, get_caller_mut},
engine::{unwrap_engine, EngineResource},
pipe::{Pipe, PipeResource},
};
use rustler::{Error, NifStruct, ResourceArc};
use std::{collections::HashMap, sync::Mutex};
use wasi_common::{sync::WasiCtxBuilder, WasiCtx};
use wasmtime::{
AsContext, AsContextMut, Engine, Store, StoreContext, StoreContextMut, StoreLimits,
StoreLimitsBuilder,
};

use crate::{
caller::{get_caller, get_caller_mut},
engine::{unwrap_engine, EngineResource},
pipe::{Pipe, PipeResource},
};

#[derive(Debug, NifStruct)]
#[module = "Wasmex.Wasi.PreopenOptions"]
pub struct ExWasiPreopenOptions {
Expand Down

0 comments on commit 4aa5957

Please sign in to comment.