From 574339afa12162859d2c5550357788943c973ceb Mon Sep 17 00:00:00 2001 From: Andrzej Ressel Date: Sun, 17 Mar 2024 19:31:16 +0100 Subject: [PATCH] Fix linter warnings --- .../src/random.rs | 1 - pulumi_wasm/src/output.rs | 12 ++------ pulumi_wasm_runner/src/main.rs | 6 ++-- pulumi_wasm_runner/src/pulumi.rs | 28 +++++++------------ pulumi_wasm_rust/src/lib.rs | 4 ++- pulumi_wasm_rust/src/output.rs | 9 ++++++ 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/providers/pulumi_wasm_provider_random_rust/src/random.rs b/providers/pulumi_wasm_provider_random_rust/src/random.rs index e9c034694..8eb2ada4b 100644 --- a/providers/pulumi_wasm_provider_random_rust/src/random.rs +++ b/providers/pulumi_wasm_provider_random_rust/src/random.rs @@ -23,7 +23,6 @@ fn random_to_domain_mapper(random: pulumi_provider_random_i unsafe { let inner = random.take_handle(); Output::::new_from_handle(inner) - // output_interface::Output::from_handle(inner) } } diff --git a/pulumi_wasm/src/output.rs b/pulumi_wasm/src/output.rs index cd7e3ec09..00465f501 100644 --- a/pulumi_wasm/src/output.rs +++ b/pulumi_wasm/src/output.rs @@ -11,9 +11,6 @@ impl FunctionId { pub(crate) fn from_string(s: &String) -> FunctionId { FunctionId(s.to_string()) } - pub(crate) fn from_str(s: &str) -> FunctionId { - FunctionId(s.to_string()) - } pub(crate) fn get(&self) -> String { self.0.clone() } @@ -40,9 +37,9 @@ impl FunctionSource { static mut GLOBAL_MAP: Option> = None; pub(crate) fn access_map() -> &'static mut Vec { - let maybeMap = unsafe { &mut GLOBAL_MAP }; + let maybe_map = unsafe { &mut GLOBAL_MAP }; - match maybeMap { + match maybe_map { None => { unsafe { GLOBAL_MAP = Some(Vec::new()); @@ -55,11 +52,6 @@ pub(crate) fn access_map() -> &'static mut Vec { // unsafe { &mut GLOBAL_MAP } } -struct Output { - content: OutputContent, - tags: Vec, -} - pub(crate) enum OutputContent { Done(Value), Mapped(FunctionId, FunctionSource, OutputContentRefCell), diff --git a/pulumi_wasm_runner/src/main.rs b/pulumi_wasm_runner/src/main.rs index e3bd79aaa..58ca68d4d 100644 --- a/pulumi_wasm_runner/src/main.rs +++ b/pulumi_wasm_runner/src/main.rs @@ -81,8 +81,8 @@ async fn main() -> Result<(), Error> { eprintln!("Cannot specify both wasm and cwasm"); std::process::exit(1); } - (Some(wasm), None) => WasmFile::WASM(wasm.clone()), - (None, Some(cwasm)) => WasmFile::CWASM(cwasm.clone()), + (Some(wasm), None) => WasmFile::Wasm(wasm.clone()), + (None, Some(cwasm)) => WasmFile::CompiledWasm(cwasm.clone()), (None, None) => { eprintln!("Must specify either wasm or cwasm"); std::process::exit(1); @@ -92,7 +92,7 @@ async fn main() -> Result<(), Error> { let _pulumi_engine_url = std::env::var("PULUMI_ENGINE")?; let pulumi_monitor_url = std::env::var("PULUMI_MONITOR")?; - let pulumi = Pulumi::create(&wasm, &Some(pulumi_monitor_url)).await?; + let mut pulumi = Pulumi::create(&wasm, &Some(pulumi_monitor_url)).await?; pulumi.start().await?; } Command::Compile { wasm, output } => { diff --git a/pulumi_wasm_runner/src/pulumi.rs b/pulumi_wasm_runner/src/pulumi.rs index ef7e982ed..a5479645d 100644 --- a/pulumi_wasm_runner/src/pulumi.rs +++ b/pulumi_wasm_runner/src/pulumi.rs @@ -1,7 +1,3 @@ -use std::cell::RefCell; -use std::ops::DerefMut; -use std::rc::Rc; - use anyhow::Error; use async_trait::async_trait; use prost::Message; @@ -16,7 +12,7 @@ use crate::pulumi::server::Main; pub struct Pulumi { plugin: Main, _instance: Instance, - store: RefCell>, + store: Store, } pub(crate) mod server { @@ -101,15 +97,15 @@ impl WasiView for SimplePluginCtx { } pub enum WasmFile { - WASM(String), - CWASM(String), + Wasm(String), + CompiledWasm(String), } impl Pulumi { pub async fn create( pulumi_wasm_file: &WasmFile, pulumi_monitor_url: &Option, - ) -> Result, Error> { + ) -> Result { let mut engine_config = wasmtime::Config::new(); engine_config.wasm_component_model(true); engine_config.async_support(true); @@ -145,8 +141,8 @@ impl Pulumi { ); let component = match pulumi_wasm_file { - WasmFile::WASM(file) => Component::from_file(&engine, file), - WasmFile::CWASM(file) => { + WasmFile::Wasm(file) => Component::from_file(&engine, file), + WasmFile::CompiledWasm(file) => { unsafe { Component::deserialize_file(&engine, file) } @@ -155,13 +151,11 @@ impl Pulumi { let (plugin, instance) = Main::instantiate_async(&mut store, &component, &linker).await?; - let store = RefCell::new(store); - - Ok(Rc::new(Pulumi { + Ok(Pulumi { plugin, _instance: instance, store, - })) + }) } pub fn compile(pulumi_wasm_file: &String) -> Result, Error> { @@ -185,12 +179,10 @@ impl Pulumi { component.serialize() } - pub async fn start(&self) -> Result<(), Error> { - let mut binding = self.store.borrow_mut(); - let store = binding.deref_mut(); + pub async fn start(&mut self) -> Result<(), Error> { self.plugin .component_pulumi_wasm_pulumi_main() - .call_main(store) + .call_main(&mut self.store) .await?; Ok(()) diff --git a/pulumi_wasm_rust/src/lib.rs b/pulumi_wasm_rust/src/lib.rs index a95b3a0c0..49800a8c0 100644 --- a/pulumi_wasm_rust/src/lib.rs +++ b/pulumi_wasm_rust/src/lib.rs @@ -110,8 +110,10 @@ fn run_all_function( pub mod output; +type Function = Box) -> Result, Error> + Send>; + lazy_static! { - pub static ref HASHMAP: Mutex) -> Result, anyhow::Error> + Send>>> = { + pub static ref HASHMAP: Mutex> = { let m = HashMap::new(); Mutex::new(m) }; diff --git a/pulumi_wasm_rust/src/output.rs b/pulumi_wasm_rust/src/output.rs index 11d3e8058..4af3a5c7d 100644 --- a/pulumi_wasm_rust/src/output.rs +++ b/pulumi_wasm_rust/src/output.rs @@ -17,10 +17,19 @@ impl From for Output { impl Output { + /// + /// # Safety + /// + /// Returns handle to inner output representation. Only needed in provider glue code. pub unsafe fn get_inner(&self) -> &output_interface::Output { &self.future } + /// + /// # Safety + /// + /// Underlying output type must the same as `F` and this Output will take ownership of the handle. + /// This means that the handle must not be deallocated by something else. pub unsafe fn new_from_handle(handle: u32) -> Output { let output = output_interface::Output::from_handle(handle); Output {