From 4aa5957ff86546ee6a78cc3782d928a52de40fef Mon Sep 17 00:00:00 2001 From: Sonny Scroggin Date: Fri, 12 Jul 2024 06:48:00 -0500 Subject: [PATCH] Remove macro_use for rustler; Import missing derived structs --- native/wasmex/Cargo.toml | 4 +--- native/wasmex/src/engine.rs | 2 +- native/wasmex/src/environment.rs | 14 ++++++-------- native/wasmex/src/instance.rs | 22 ++++++++++------------ native/wasmex/src/lib.rs | 5 +---- native/wasmex/src/memory.rs | 9 +++------ native/wasmex/src/module.rs | 15 ++++++--------- native/wasmex/src/pipe.rs | 14 ++++++-------- native/wasmex/src/printable_term_type.rs | 2 +- native/wasmex/src/store.rs | 13 ++++++------- 10 files changed, 41 insertions(+), 59 deletions(-) diff --git a/native/wasmex/Cargo.toml b/native/wasmex/Cargo.toml index 817cee42..8ebc89e4 100644 --- a/native/wasmex/Cargo.toml +++ b/native/wasmex/Cargo.toml @@ -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" diff --git a/native/wasmex/src/engine.rs b/native/wasmex/src/engine.rs index 37c3effc..4b9ef2ec 100644 --- a/native/wasmex/src/engine.rs +++ b/native/wasmex/src/engine.rs @@ -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}; diff --git a/native/wasmex/src/environment.rs b/native/wasmex/src/environment.rs index 0c9d4c74..a811a3bf 100644 --- a/native/wasmex/src/environment.rs +++ b/native/wasmex/src/environment.rs @@ -1,11 +1,3 @@ -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}, @@ -13,6 +5,12 @@ use crate::{ 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, diff --git a/native/wasmex/src/instance.rs b/native/wasmex/src/instance.rs index e147df03..7299483d 100644 --- a/native/wasmex/src/instance.rs +++ b/native/wasmex/src/instance.rs @@ -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}, @@ -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 { diff --git a/native/wasmex/src/lib.rs b/native/wasmex/src/lib.rs index d9a7a276..e4a9aec7 100644 --- a/native/wasmex/src/lib.rs +++ b/native/wasmex/src/lib.rs @@ -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"); diff --git a/native/wasmex/src/memory.rs b/native/wasmex/src/memory.rs index 53bf82b3..26d07925 100644 --- a/native/wasmex/src/memory.rs +++ b/native/wasmex/src/memory.rs @@ -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, } diff --git a/native/wasmex/src/module.rs b/native/wasmex/src/module.rs index 089804e2..81ded02a 100644 --- a/native/wasmex/src/module.rs +++ b/native/wasmex/src/module.rs @@ -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, } diff --git a/native/wasmex/src/pipe.rs b/native/wasmex/src/pipe.rs index 2817f1df..b1c5b952 100644 --- a/native/wasmex/src/pipe.rs +++ b/native/wasmex/src/pipe.rs @@ -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; diff --git a/native/wasmex/src/printable_term_type.rs b/native/wasmex/src/printable_term_type.rs index 400a686b..794ac1e9 100644 --- a/native/wasmex/src/printable_term_type.rs +++ b/native/wasmex/src/printable_term_type.rs @@ -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 { diff --git a/native/wasmex/src/store.rs b/native/wasmex/src/store.rs index 0bc8ea85..afee3780 100644 --- a/native/wasmex/src/store.rs +++ b/native/wasmex/src/store.rs @@ -3,7 +3,12 @@ // 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::{ @@ -11,12 +16,6 @@ use wasmtime::{ 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 {