Skip to content

Commit

Permalink
Merge pull request #53 from andrzejressel/fix_linter_warnings
Browse files Browse the repository at this point in the history
Fix linter warnings
  • Loading branch information
mergify[bot] authored Mar 17, 2024
2 parents d6e987a + 574339a commit 5f896af
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
1 change: 0 additions & 1 deletion providers/pulumi_wasm_provider_random_rust/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fn random_to_domain_mapper<F: serde::Serialize>(random: pulumi_provider_random_i
unsafe {
let inner = random.take_handle();
Output::<F>::new_from_handle(inner)
// output_interface::Output::from_handle(inner)
}
}

Expand Down
12 changes: 2 additions & 10 deletions pulumi_wasm/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -40,9 +37,9 @@ impl FunctionSource {
static mut GLOBAL_MAP: Option<Vec<OutputContentRefCell>> = None;

pub(crate) fn access_map() -> &'static mut Vec<OutputContentRefCell> {
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());
Expand All @@ -55,11 +52,6 @@ pub(crate) fn access_map() -> &'static mut Vec<OutputContentRefCell> {
// unsafe { &mut GLOBAL_MAP }
}

struct Output {
content: OutputContent,
tags: Vec<String>,
}

pub(crate) enum OutputContent {
Done(Value),
Mapped(FunctionId, FunctionSource, OutputContentRefCell),
Expand Down
6 changes: 3 additions & 3 deletions pulumi_wasm_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 } => {
Expand Down
28 changes: 10 additions & 18 deletions pulumi_wasm_runner/src/pulumi.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,7 +12,7 @@ use crate::pulumi::server::Main;
pub struct Pulumi {
plugin: Main,
_instance: Instance,
store: RefCell<Store<SimplePluginCtx>>,
store: Store<SimplePluginCtx>,
}

pub(crate) mod server {
Expand Down Expand Up @@ -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<String>,
) -> Result<Rc<Pulumi>, Error> {
) -> Result<Pulumi, Error> {
let mut engine_config = wasmtime::Config::new();
engine_config.wasm_component_model(true);
engine_config.async_support(true);
Expand Down Expand Up @@ -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)
}
Expand All @@ -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<Vec<u8>, Error> {
Expand All @@ -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(())
Expand Down
4 changes: 3 additions & 1 deletion pulumi_wasm_rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ fn run_all_function(

pub mod output;

type Function = Box<dyn Fn(Vec<u8>) -> Result<Vec<u8>, Error> + Send>;

lazy_static! {
pub static ref HASHMAP: Mutex<HashMap<String, Box<dyn Fn(Vec<u8>) -> Result<Vec<u8>, anyhow::Error> + Send>>> = {
pub static ref HASHMAP: Mutex<HashMap<String, Function>> = {
let m = HashMap::new();
Mutex::new(m)
};
Expand Down
9 changes: 9 additions & 0 deletions pulumi_wasm_rust/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ impl <T: serde::Serialize> From<T> for Output<T> {

impl<T> Output<T> {

///
/// # 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<F: serde::Serialize>(handle: u32) -> Output<F> {
let output = output_interface::Output::from_handle(handle);
Output {
Expand Down

0 comments on commit 5f896af

Please sign in to comment.