Skip to content

Commit

Permalink
Save
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel committed Mar 5, 2024
1 parent 2aba63e commit 0c477af
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 419 deletions.
59 changes: 4 additions & 55 deletions pulumi_rust_wasm/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,54 +56,6 @@ pub mod component {
}
}

#[allow(unused_unsafe, clippy::all)]
pub fn create_struct(fields: &[(_rt::String, &Output)]) -> Output {
unsafe {
let vec2 = fields;
let len2 = vec2.len();
let layout2 = _rt::alloc::Layout::from_size_align_unchecked(vec2.len() * 12, 4);
let result2 = if layout2.size() != 0 {
let ptr = _rt::alloc::alloc(layout2).cast::<u8>();
if ptr.is_null() {
_rt::alloc::handle_alloc_error(layout2);
}
ptr
} else {
{
::core::ptr::null_mut()
}
};
for (i, e) in vec2.into_iter().enumerate() {
let base = result2.add(i * 12);
{
let (t0_0, t0_1) = e;
let vec1 = t0_0;
let ptr1 = vec1.as_ptr().cast::<u8>();
let len1 = vec1.len();
*base.add(4).cast::<usize>() = len1;
*base.add(0).cast::<*mut u8>() = ptr1.cast_mut();
*base.add(8).cast::<i32>() = (t0_1).handle() as i32;
}
}

#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "component:pulumi-wasm/[email protected]")]
extern "C" {
#[link_name = "create-struct"]
fn wit_import(_: *mut u8, _: usize) -> i32;
}

#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: *mut u8, _: usize) -> i32 {
unreachable!()
}
let ret = wit_import(result2, len2);
if layout2.size() != 0 {
_rt::alloc::dealloc(result2.cast(), layout2);
}
Output::from_handle(ret as u32)
}
}
impl Output {
#[allow(unused_unsafe, clippy::all)]
pub fn new(value: &[u8]) -> Self {
Expand Down Expand Up @@ -308,8 +260,6 @@ mod _rt {
}
}
}
pub use alloc_crate::alloc;
pub use alloc_crate::string::String;
pub use alloc_crate::vec::Vec;
pub unsafe fn invalid_enum_discriminant<T>() -> T {
if cfg!(debug_assertions) {
Expand All @@ -324,14 +274,13 @@ mod _rt {
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.20.0:pulumi-rust:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 453] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc3\x02\x01A\x02\x01\
A\x02\x01B\x11\x04\0\x06output\x03\x01\x01p}\x01i\0\x01@\x01\x05value\x01\0\x02\x04\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 414] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x9c\x02\x01A\x02\x01\
A\x02\x01B\x0d\x04\0\x06output\x03\x01\x01p}\x01i\0\x01@\x01\x05value\x01\0\x02\x04\
\0\x13[constructor]output\x01\x03\x01h\0\x01@\x02\x04self\x04\x0dfunction-names\0\
\x02\x04\0\x12[method]output.map\x01\x05\x01k\x01\x01@\x01\x04self\x04\0\x06\x04\
\0\x12[method]output.get\x01\x07\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]out\
put.duplicate\x01\x08\x01o\x02s\x04\x01p\x09\x01@\x01\x06fields\x0a\0\x02\x04\0\x0d\
create-struct\x01\x0b\x03\x01,component:pulumi-wasm/[email protected]\x05\0\
put.duplicate\x01\x08\x03\x01,component:pulumi-wasm/[email protected]\x05\0\
\x04\x01'component:pulumi-wasm/[email protected]\x04\0\x0b\x11\x01\0\x0bpulumi-r\
ust\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.201.0\x10\
wit-bindgen-rust\x060.20.0";
Expand Down
27 changes: 0 additions & 27 deletions pulumi_rust_wasm/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ use uuid::Uuid;
pub struct Output<T> {
phantom: PhantomData<T>,
future: output_interface::Output,
// pulumi: Rc<Pulumi>,
}
//
// impl <T: serde::Serialize> Into<Output<T>> for (T,) {
// fn into(self) -> Output<T> {
// Output::new(&self)
// }
// }

impl <T: serde::Serialize> From<T> for Output<T> {
fn from(value: T) -> Output<T> {
Expand All @@ -30,7 +23,6 @@ impl<T> Output<T> {
let binding = rmp_serde::to_vec(value).unwrap();
let arg = binding.as_slice();
let resource = output_interface::Output::new(arg);
// let resource = create_output(value).unwrap();
Output {
phantom: PhantomData,
future: resource,
Expand Down Expand Up @@ -60,24 +52,5 @@ impl<T> Output<T> {
phantom: PhantomData,
future: new_output,
}

// crate::bindings::component::pulumi_wasm::output_interface::Output::

// let resource = self.pulumi.map(self.future, f).unwrap();
// Output {
// phantom: PhantomData,
// future: resource,
// pulumi: self.pulumi.clone(),
// }
}
//
// pub fn get_value(&self) -> Option<T>
// where
// T: serde::de::DeserializeOwned,
// {
// self.pulumi
// .get_output(self.future)
// .unwrap()
// .map(|output| rmp_serde::decode::from_slice(&*output).unwrap())
// }
}
47 changes: 5 additions & 42 deletions pulumi_wasm/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,6 @@ pub mod exports {
}
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn _export_create_struct_cabi<T: Guest>(
arg0: *mut u8,
arg1: usize,
) -> i32 {
let base4 = arg0;
let len4 = arg1;
let mut result4 = _rt::Vec::with_capacity(len4);
for i in 0..len4 {
let base = base4.add(i * 12);
let e4 = {
let l0 = *base.add(0).cast::<*mut u8>();
let l1 = *base.add(4).cast::<usize>();
let len2 = l1;
let bytes2 = _rt::Vec::from_raw_parts(l0.cast(), len2, len2);
let l3 = *base.add(8).cast::<i32>();

(
_rt::string_lift(bytes2),
OutputBorrow::lift(l3 as u32 as usize),
)
};
result4.push(e4);
}
_rt::cabi_dealloc(base4, len4 * 12, 4);
let result5 = T::create_struct(result4);
(result5).take_handle() as i32
}

#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn _export_constructor_output_cabi<T: GuestOutput>(
Expand Down Expand Up @@ -297,7 +267,6 @@ pub mod exports {
}
pub trait Guest {
type Output: GuestOutput;
fn create_struct(fields: _rt::Vec<(_rt::String, OutputBorrow<'_>)>) -> Output;
}
pub trait GuestOutput: 'static {
#[doc(hidden)]
Expand Down Expand Up @@ -353,11 +322,6 @@ pub mod exports {
($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = {


#[export_name = "component:pulumi-wasm/[email protected]#create-struct"]
unsafe extern "C" fn export_create_struct(arg0: *mut u8,arg1: usize,) -> i32 {
$($path_to_types)*::_export_create_struct_cabi::<$ty>(arg0, arg1)
}

#[export_name = "component:pulumi-wasm/[email protected]#[constructor]output"]
unsafe extern "C" fn export_constructor_output(arg0: *mut u8,arg1: usize,) -> i32 {
$($path_to_types)*::_export_constructor_output_cabi::<<$ty as $($path_to_types)*::Guest>::Output>(arg0, arg1)
Expand Down Expand Up @@ -779,6 +743,7 @@ mod _rt {
String::from_utf8_unchecked(bytes)
}
}
pub use alloc_crate::string::String;
pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) {
if size == 0 {
return;
Expand All @@ -787,7 +752,6 @@ mod _rt {
alloc::dealloc(ptr as *mut u8, layout);
}
pub use alloc_crate::alloc;
pub use alloc_crate::string::String;
extern crate alloc as alloc_crate;
}

Expand Down Expand Up @@ -824,15 +788,14 @@ pub(crate) use __export_pulumi_wasm_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.20.0:pulumi-wasm:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1019] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xf9\x06\x01A\x02\x01\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 980] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xd2\x06\x01A\x02\x01\
A\x09\x01B\x03\x01p}\x01@\x01\x07request\0\0\0\x04\0\x11register-resource\x01\x01\
\x03\x01*component:pulumi-wasm/[email protected]\x05\0\x01B\x11\x04\0\x06outp\
\x03\x01*component:pulumi-wasm/[email protected]\x05\0\x01B\x0d\x04\0\x06outp\
ut\x03\x01\x01p}\x01i\0\x01@\x01\x05value\x01\0\x02\x04\0\x13[constructor]output\
\x01\x03\x01h\0\x01@\x02\x04self\x04\x0dfunction-names\0\x02\x04\0\x12[method]ou\
tput.map\x01\x05\x01k\x01\x01@\x01\x04self\x04\0\x06\x04\0\x12[method]output.get\
\x01\x07\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]output.duplicate\x01\x08\x01\
o\x02s\x04\x01p\x09\x01@\x01\x06fields\x0a\0\x02\x04\0\x0dcreate-struct\x01\x0b\x04\
\x01\x07\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]output.duplicate\x01\x08\x04\
\x01,component:pulumi-wasm/[email protected]\x05\x01\x02\x03\0\x01\x06outpu\
t\x01B\x0b\x02\x03\x02\x01\x02\x04\0\x06output\x03\0\0\x01h\x01\x01r\x01\x06obje\
ct\x02\x04\0\x0cobject-field\x03\0\x03\x01ps\x01p\x04\x01r\x04\x04types\x04names\
Expand Down
118 changes: 9 additions & 109 deletions pulumi_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use bindings::component::pulumi_wasm::external_world;
use crate::bindings::exports::component::pulumi_wasm::function_reverse_callback::{
FunctionInvocationRequest, FunctionInvocationResult,
};
use crate::bindings::exports::component::pulumi_wasm::output_interface::Output as WasmOutput;
use crate::bindings::exports::component::pulumi_wasm::output_interface::OutputBorrow as WasmOutputBorrow;
use crate::bindings::exports::component::pulumi_wasm::output_interface::{GuestOutput};
use crate::bindings::exports::component::pulumi_wasm::register_interface::{RegisterResourceRequest};
use crate::bindings::exports::component::pulumi_wasm::{
Expand All @@ -25,53 +27,6 @@ struct Component;

impl output_interface::Guest for Component {
type Output = Output;

fn create_struct(_fields: Vec<(String, output_interface::OutputBorrow<'_>)>) -> output_interface::Output {
//FIXME
let cell = output::create_nothing();
output_interface::Output::new(Output { output: cell, tags: vec![] })
// todo!()
// let mut field_names = vec![];
// let mut field_values = vec![];
//
// for (string, output) in fields {
// field_names.push(string);
// field_values.push(output.output.future.clone())
// }
//
// let all_futures = join_all(field_values);
//
// let f = all_futures.map(move |vec_of_vecs| {
// let mut map = vec![];
// let mut all_known = true;
//
// // let mut object = rmpv::Value::Map();
// for (value, name) in vec_of_vecs.iter().zip(field_names.clone()) {
// let name_field = Value::String(name.into());
// let value_field = value.deref().clone();
//
// match value_field {
// OutputValue::Known(known) => map.push((name_field, known)),
// OutputValue::Unknown() => {
// return Arc::new(OutputValue::Unknown());
// }
// }
// }
//
// Arc::new(OutputValue::Known(Value::Map(map)))
// });
//
// let f2: Pin<Box<dyn Future<Output = Arc<OutputValue>>>> = Box::pin(f);
//
// let output_wrapper = OutputWrapper {
// future: f2.shared(),
// tags: vec![],
// };
//
// OwnOutput::new(Output {
// output: output_wrapper,
// })
}
}

pub struct Output {
Expand All @@ -92,11 +47,11 @@ impl GuestOutput for Output {
Output { output: cell, tags: vec![] }
}

fn map(&self, function_name: String) -> output_interface::Output {
fn map(&self, function_name: String) -> WasmOutput {
let function_id = FunctionId::from_string(&function_name);
let function_source = FunctionSource::from_str("source");
let output = output::map_external(function_id, function_source, self.output.clone());
output_interface::Output::new(Output { output, tags: vec![] })
WasmOutput::new(Output { output, tags: vec![] })
}

fn get(&self) -> Option<Vec<u8>> {
Expand All @@ -115,64 +70,12 @@ impl GuestOutput for Output {
}
}

fn duplicate(&self) -> output_interface::Output {
output_interface::Output::new(Output {
fn duplicate(&self) -> WasmOutput {
WasmOutput::new(Output {
output: self.output.clone(),
tags: self.tags.clone(),
})
// self.output
}
// fn new(value: Vec<u8>) -> Self {
// let value = rmpv::decode::read_value(&mut value.as_slice()).unwrap();
// let output = create_output(value);
// return Self { output };
// }
//
// fn map(&self, function_name: String) -> OwnOutput {
// let future = self.output.future.clone();
//
// let new_future = map_to_future(future.map(move |f| {
// let f = f.deref();
// Arc::new(match f {
// OutputValue::Known(v) => {
// let mut vec = vec![];
// rmpv::encode::write_value(&mut vec, v).unwrap();
// let mut vec = invoke_function(
// function_name.as_str(),
// &*vec,
// );
// let value = rmpv::decode::read_value(&mut vec.as_slice()).unwrap();
// OutputValue::Known(value)
// }
// OutputValue::Unknown() => OutputValue::Unknown(),
// })
// }))
// .shared();
//
// let new_output = OutputWrapper {
// future: new_future,
// tags: self.output.tags.clone(),
// };
//
// OwnOutput::new(Output { output: new_output })
// }
//
// fn get(&self) -> Option<Vec<u8>> {
// let future = self.output.future.clone();
//
// let result = block_on(future);
//
// let result = &*result;
//
// match result {
// OutputValue::Known(v) => {
// let mut vec = vec![];
// rmpv::encode::write_value(&mut vec, v).unwrap();
// Some(vec)
// }
// OutputValue::Unknown() => None,
// }
// }
}

impl function_reverse_callback::Guest for Component {
Expand All @@ -190,7 +93,7 @@ impl function_reverse_callback::Guest for Component {
let mut vec = vec![];
rmpv::encode::write_value(&mut vec, v).unwrap();
Some(FunctionInvocationRequest {
id: output_interface::Output::new(Output { output: f.clone(), tags: vec![] }),
id: WasmOutput::new(Output { output: f.clone(), tags: vec![] }),
function_id: id.get(),
value: vec,
})
Expand Down Expand Up @@ -232,18 +135,15 @@ impl register_interface::Guest for Component {

let pairs = request.object_names.iter().zip(request.object.iter());

let pairs= pairs.map(|(_name, object )| {
let s: String = "length".to_string();
// let s: String = String::from_utf8(name.clone()).unwrap();

let pairs= pairs.map(|(name, object )| {
let v = match &*object.object.get::<Output>().output.borrow() {
OutputContent::Done(vec) => messagepack_to_protoc(&vec),
OutputContent::Mapped(_, _, _) => todo!(),
OutputContent::Func(_, _) => todo!(),
OutputContent::Nothing => todo!()
};

(s, v)
(name.clone(), v)
});


Expand Down
Loading

0 comments on commit 0c477af

Please sign in to comment.