diff --git a/Cargo.lock b/Cargo.lock index c86b42a9b..5454aadd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,7 +144,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -155,7 +155,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -420,7 +420,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -564,7 +564,7 @@ dependencies = [ "itertools 0.10.5", "log", "smallvec", - "wasmparser", + "wasmparser 0.121.0", "wasmtime-types", ] @@ -831,7 +831,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -966,6 +966,9 @@ name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "hermit-abi" @@ -1497,7 +1500,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1531,14 +1534,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" dependencies = [ "proc-macro2", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1570,7 +1573,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.48", + "syn 2.0.52", "tempfile", "which", ] @@ -1585,7 +1588,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -1610,22 +1613,6 @@ dependencies = [ name = "pulumi-wasm-parent" version = "0.1.0" -[[package]] -name = "pulumi_rust_wasm" -version = "0.1.0" -dependencies = [ - "anyhow", - "bitflags 2.4.2", - "futures", - "lazy_static", - "log", - "rmp-serde", - "serde", - "serde_json", - "uuid", - "wit-bindgen-rt", -] - [[package]] name = "pulumi_wasm" version = "0.1.0" @@ -1664,7 +1651,8 @@ dependencies = [ "once_cell", "prost", "prost-types", - "pulumi_rust_wasm", + "pulumi_wasm_provider_random_rust", + "pulumi_wasm_rust", "rmp", "rmp-serde", "rmpv", @@ -1703,6 +1691,18 @@ dependencies = [ "wit-bindgen-rt", ] +[[package]] +name = "pulumi_wasm_provider_random_rust" +version = "0.1.0" +dependencies = [ + "anyhow", + "log", + "pulumi_wasm_rust", + "serde", + "wasm_common", + "wit-bindgen", +] + [[package]] name = "pulumi_wasm_runner" version = "0.1.0" @@ -1729,6 +1729,34 @@ dependencies = [ "wasmtime-wasi", ] +[[package]] +name = "pulumi_wasm_rust" +version = "0.1.0" +dependencies = [ + "anyhow", + "bitflags 2.4.2", + "futures", + "lazy_static", + "log", + "pulumi_wasm_rust_macro", + "rmp-serde", + "rmpv", + "serde", + "serde_json", + "uuid", + "wasm_common", + "wit-bindgen", +] + +[[package]] +name = "pulumi_wasm_rust_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "quote" version = "1.0.35" @@ -1960,7 +1988,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2047,6 +2075,15 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spdx" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ef1a0fa1e39ac22972c8db23ff89aea700ab96aa87114e1fb55937a631a0c9" +dependencies = [ + "smallvec", +] + [[package]] name = "sptr" version = "0.3.2" @@ -2078,9 +2115,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" dependencies = [ "proc-macro2", "quote", @@ -2145,7 +2182,7 @@ checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2218,7 +2255,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2292,7 +2329,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2384,7 +2421,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2464,6 +2501,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + [[package]] name = "unicode-width" version = "0.1.11" @@ -2592,7 +2635,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wasm-bindgen-shared", ] @@ -2614,7 +2657,7 @@ checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2634,13 +2677,38 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-encoder" +version = "0.201.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9c7d2731df60006819b013f64ccc2019691deccf6e11a1804bc850cd6748f1a" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.201.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fd83062c17b9f4985d438603cde0a5e8c5c8198201a6937f778b607924c7da2" +dependencies = [ + "anyhow", + "indexmap 2.1.0", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder 0.201.0", + "wasmparser 0.201.0", +] + [[package]] name = "wasm_common" version = "0.1.0" dependencies = [ "log", "uuid", - "wit-bindgen-rt", + "wit-bindgen", ] [[package]] @@ -2654,6 +2722,17 @@ dependencies = [ "semver", ] +[[package]] +name = "wasmparser" +version = "0.201.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84e5df6dba6c0d7fafc63a450f1738451ed7a0b52295d83e868218fa286bf708" +dependencies = [ + "bitflags 2.4.2", + "indexmap 2.1.0", + "semver", +] + [[package]] name = "wasmprinter" version = "0.2.78" @@ -2661,7 +2740,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05e32c13c59fdc64d3f6998a1d52eb1d362b6904a88b754190ccb85661ad577a" dependencies = [ "anyhow", - "wasmparser", + "wasmparser 0.121.0", ] [[package]] @@ -2692,8 +2771,8 @@ dependencies = [ "serde_derive", "serde_json", "target-lexicon", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.41.0", + "wasmparser 0.121.0", "wasmtime-cache", "wasmtime-component-macro", "wasmtime-component-util", @@ -2746,10 +2825,10 @@ dependencies = [ "anyhow", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wasmtime-component-util", "wasmtime-wit-bindgen", - "wit-parser", + "wit-parser 0.13.1", ] [[package]] @@ -2777,7 +2856,7 @@ dependencies = [ "object", "target-lexicon", "thiserror", - "wasmparser", + "wasmparser 0.121.0", "wasmtime-cranelift-shared", "wasmtime-environ", "wasmtime-versioned-export-macros", @@ -2818,8 +2897,8 @@ dependencies = [ "serde_derive", "target-lexicon", "thiserror", - "wasm-encoder", - "wasmparser", + "wasm-encoder 0.41.0", + "wasmparser 0.121.0", "wasmprinter", "wasmtime-component-util", "wasmtime-types", @@ -2883,7 +2962,7 @@ dependencies = [ "psm", "rustix", "sptr", - "wasm-encoder", + "wasm-encoder 0.41.0", "wasmtime-asm-macros", "wasmtime-environ", "wasmtime-fiber", @@ -2903,7 +2982,7 @@ dependencies = [ "serde", "serde_derive", "thiserror", - "wasmparser", + "wasmparser 0.121.0", ] [[package]] @@ -2914,7 +2993,7 @@ checksum = "8ef32eea9fc7035a55159a679d1e89b43ece5ae45d24eed4808e6a92c99a0da4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] @@ -2961,7 +3040,7 @@ dependencies = [ "gimli", "object", "target-lexicon", - "wasmparser", + "wasmparser 0.121.0", "wasmtime-cranelift-shared", "wasmtime-environ", "winch-codegen", @@ -2976,7 +3055,7 @@ dependencies = [ "anyhow", "heck", "indexmap 2.1.0", - "wit-parser", + "wit-parser 0.13.1", ] [[package]] @@ -3004,7 +3083,7 @@ dependencies = [ "leb128", "memchr", "unicode-width", - "wasm-encoder", + "wasm-encoder 0.41.0", ] [[package]] @@ -3054,7 +3133,7 @@ dependencies = [ "proc-macro2", "quote", "shellexpand", - "syn 2.0.48", + "syn 2.0.52", "witx", ] @@ -3066,7 +3145,7 @@ checksum = "9498ef53a12cf25dc6de9baef6ccd8b58d159202c412a19f4d72b218393086c5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", "wiggle-generate", ] @@ -3104,7 +3183,7 @@ dependencies = [ "regalloc2", "smallvec", "target-lexicon", - "wasmparser", + "wasmparser 0.121.0", "wasmtime-environ", ] @@ -3259,12 +3338,80 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "wit-bindgen" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbdedb8dd38c89c2cfa71e7450515f1c17f94cc2853881652d005b10f3f2559c" +dependencies = [ + "bitflags 2.4.2", + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebcbf07363368a9e6e8b89c18bff176c4f35ed2dd2f2f5f9c473bb56813369b" +dependencies = [ + "anyhow", + "wit-parser 0.201.0", +] + [[package]] name = "wit-bindgen-rt" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "026d24a27f6712541fa534f2954bd9e0eb66172f033c2157c0f31d106255c497" +[[package]] +name = "wit-bindgen-rust" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2a4d36bf13b5ef534599d24dae792b1ae2b40fe1248c2754fd3f7343fb2ca70" +dependencies = [ + "anyhow", + "heck", + "indexmap 2.1.0", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4bf1b15b5227d1ca9ba7fc6a7850c72f9df0fbac3c46a0855763cc454ff11a" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.52", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.201.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "421c0c848a0660a8c22e2fd217929a0191f14476b68962afd2af89fd22e39825" +dependencies = [ + "anyhow", + "bitflags 2.4.2", + "indexmap 2.1.0", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.201.0", + "wasm-metadata", + "wasmparser 0.201.0", + "wit-parser 0.201.0", +] + [[package]] name = "wit-parser" version = "0.13.1" @@ -3282,6 +3429,24 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "wit-parser" +version = "0.201.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196d3ecfc4b759a8573bf86a9b3f8996b304b3732e4c7de81655f875f6efdca6" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 2.1.0", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.201.0", +] + [[package]] name = "witx" version = "0.9.1" @@ -3311,7 +3476,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.52", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 01aab0d2d..c240e15a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,22 +1,25 @@ [package] name = "pulumi-wasm-parent" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] - [workspace] members = [ "pulumi_wasm_runner", "pulumi_wasm", "providers/pulumi_wasm_provider_random", + "pulumi_wasm_rust_macro", "pulumi_wasm_rust", "wasm_common", "examples/simple" ] +[workspace.package] +version = "0.1.0" +edition = "2021" + [workspace.dependencies] anyhow = "1.0.80" prost = "0.12.3" @@ -26,6 +29,7 @@ futures = "0.3.30" lazy_static = "1.4.0" once_cell = "1.19.0" bitflags = "2.4.2" +wit-bindgen = "0.21.0" wit-bindgen-rt = "0.21.0" rmp = "0.8.12" rmp-serde = "1.1.2" @@ -44,3 +48,10 @@ log4rs = "1.3.0" tokio = { version = "1.36.0", features = ["sync", "macros", "io-util", "rt", "time"] } clap = { version = "4.5.2", features = ["derive"] } regex = "1.10.3" +syn = { version = "2.0.52", features = ["full"] } +quote = "1.0.35" +proc-macro2 = "1.0.78" +pulumi_wasm_rust = { path = "pulumi_wasm_rust" } +pulumi_wasm_rust_macro = { path = "pulumi_wasm_rust_macro" } +wasm_common = { path = "wasm_common" } +pulumi_wasm_provider_random_rust = { path = "providers/pulumi_wasm_provider_random_rust" } \ No newline at end of file diff --git a/build.bat b/build.bat index 47610a242..d702ff830 100644 --- a/build.bat +++ b/build.bat @@ -1,4 +1,3 @@ -cargo component build -p wasm_common || exit /b 1 cargo component build -p pulumi_wasm || exit /b 1 cargo component build -p pulumi_wasm_provider_random || exit /b 1 cargo component build -p pulumi_wasm_example_simple || exit /b 1 diff --git a/build.sh b/build.sh index 6f30af147..8d68373b8 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,6 @@ set -e -cargo component build -p wasm_common cargo component build -p pulumi_wasm cargo component build -p pulumi_wasm_provider_random cargo component build -p pulumi_wasm_example_simple diff --git a/examples/simple/Cargo.toml b/examples/simple/Cargo.toml index 9e5e6ff01..ed12a2aa5 100644 --- a/examples/simple/Cargo.toml +++ b/examples/simple/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pulumi_wasm_example_simple" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -24,17 +24,11 @@ rmpv.workspace = true serde.workspace = true tonic.workspace = true serde_json.workspace = true -pulumi_rust_wasm = { path = "../../pulumi_wasm_rust" } +pulumi_wasm_rust.workspace = true log.workspace = true -wasm_common = { path = "../../wasm_common" } +wasm_common.workspace = true +pulumi_wasm_provider_random_rust.workspace = true [dev-dependencies] wasmtime.workspace = true wasmtime-wasi.workspace = true - -[package.metadata.component] -package = "component:pulumi-wasm-main" - -[package.metadata.component.target] -path = "../../wits/world.wit" -world = "new-main" diff --git a/examples/simple/src/bindings.rs b/examples/simple/src/bindings.rs index 17f2c975a..894729c29 100644 --- a/examples/simple/src/bindings.rs +++ b/examples/simple/src/bindings.rs @@ -1,1021 +1,14 @@ // Generated by `wit-bindgen` 0.20.0. DO NOT EDIT! // Options used: -pub mod component { - pub mod pulumi_wasm { - - #[allow(clippy::all)] - pub mod output_interface { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = - super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - - #[derive(Debug)] - #[repr(transparent)] - pub struct Output { - handle: _rt::Resource, - } - - impl Output { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: _rt::Resource::from_handle(handle), - } - } - - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - - unsafe impl _rt::WasmResource for Output { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(not(target_arch = "wasm32"))] - unreachable!(); - - #[cfg(target_arch = "wasm32")] - { - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[resource-drop]output"] - fn drop(_: u32); - } - - drop(_handle); - } - } - } - - #[allow(unused_unsafe, clippy::all)] - pub fn describe_outputs() -> _rt::String { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "describe-outputs"] - fn wit_import(_: *mut u8); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: *mut u8) { - unreachable!() - } - wit_import(ptr0); - let l1 = *ptr0.add(0).cast::<*mut u8>(); - let l2 = *ptr0.add(4).cast::(); - let len3 = l2; - let bytes3 = _rt::Vec::from_raw_parts(l1.cast(), len3, len3); - _rt::string_lift(bytes3) - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn non_done_exists() -> bool { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "non-done-exists"] - fn wit_import() -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import() -> i32 { - unreachable!() - } - let ret = wit_import(); - _rt::bool_lift(ret as u8) - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn combine_outputs() -> bool { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "combine-outputs"] - fn wit_import() -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import() -> i32 { - unreachable!() - } - let ret = wit_import(); - _rt::bool_lift(ret as u8) - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn new(value: &[u8]) -> Self { - unsafe { - let vec0 = value; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[constructor]output"] - fn wit_import(_: *mut u8, _: usize) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: *mut u8, _: usize) -> i32 { - unreachable!() - } - let ret = wit_import(ptr0.cast_mut(), len0); - Output::from_handle(ret as u32) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn map(&self, function_name: &str) -> Output { - unsafe { - let vec0 = function_name; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.map"] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 { - unreachable!() - } - let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0); - Output::from_handle(ret as u32) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn get(&self) -> Option<_rt::Vec> { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 12]); - let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.get"] - fn wit_import(_: i32, _: *mut u8); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8) { - unreachable!() - } - wit_import((self).handle() as i32, ptr0); - let l1 = i32::from(*ptr0.add(0).cast::()); - match l1 { - 0 => None, - 1 => { - let e = { - let l2 = *ptr0.add(4).cast::<*mut u8>(); - let l3 = *ptr0.add(8).cast::(); - let len4 = l3; - - _rt::Vec::from_raw_parts(l2.cast(), len4, len4) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn get_field(&self, field: &str) -> Output { - unsafe { - let vec0 = field; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.get-field"] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 { - unreachable!() - } - let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0); - Output::from_handle(ret as u32) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn get_type(&self) -> _rt::String { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.get-type"] - fn wit_import(_: i32, _: *mut u8); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8) { - unreachable!() - } - wit_import((self).handle() as i32, ptr0); - let l1 = *ptr0.add(0).cast::<*mut u8>(); - let l2 = *ptr0.add(4).cast::(); - let len3 = l2; - let bytes3 = _rt::Vec::from_raw_parts(l1.cast(), len3, len3); - _rt::string_lift(bytes3) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn duplicate(&self) -> Output { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.duplicate"] - fn wit_import(_: i32) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import((self).handle() as i32); - Output::from_handle(ret as u32) - } - } - } - } - - #[allow(clippy::all)] - pub mod pulumi_provider_random_interface { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = - super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - pub type Output = super::super::super::component::pulumi_wasm::output_interface::Output; - pub struct RandomStringArgs<'a> { - pub name: _rt::String, - pub length: &'a Output, - } - impl<'a> ::core::fmt::Debug for RandomStringArgs<'a> { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("RandomStringArgs") - .field("name", &self.name) - .field("length", &self.length) - .finish() - } - } - pub struct RandomStringResult { - pub result: Output, - } - impl ::core::fmt::Debug for RandomStringResult { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("RandomStringResult") - .field("result", &self.result) - .finish() - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn create_random_string(args: &RandomStringArgs<'_>) -> RandomStringResult { - unsafe { - let RandomStringArgs { - name: name0, - length: length0, - } = args; - let vec1 = name0; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - - #[cfg(target_arch = "wasm32")] - #[link( - wasm_import_module = "component:pulumi-wasm/pulumi-provider-random-interface@0.1.0" - )] - extern "C" { - #[link_name = "create-random-string"] - fn wit_import(_: *mut u8, _: usize, _: i32) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: *mut u8, _: usize, _: i32) -> i32 { - unreachable!() - } - let ret = wit_import(ptr1.cast_mut(), len1, (length0).handle() as i32); - RandomStringResult{ - result: super::super::super::component::pulumi_wasm::output_interface::Output::from_handle(ret as u32), - } - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn handle_functions() { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link( - wasm_import_module = "component:pulumi-wasm/pulumi-provider-random-interface@0.1.0" - )] - extern "C" { - #[link_name = "handle-functions"] - fn wit_import(); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import() { - unreachable!() - } - wit_import(); - } - } - } - - #[allow(clippy::all)] - pub mod function_reverse_callback { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = - super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - pub type Output = super::super::super::component::pulumi_wasm::output_interface::Output; - pub struct FunctionInvocationRequest { - pub id: Output, - pub function_id: _rt::String, - pub value: _rt::Vec, - } - impl ::core::fmt::Debug for FunctionInvocationRequest { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("FunctionInvocationRequest") - .field("id", &self.id) - .field("function-id", &self.function_id) - .field("value", &self.value) - .finish() - } - } - pub struct FunctionInvocationResult<'a> { - pub id: &'a Output, - pub value: _rt::Vec, - } - impl<'a> ::core::fmt::Debug for FunctionInvocationResult<'a> { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("FunctionInvocationResult") - .field("id", &self.id) - .field("value", &self.value) - .finish() - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn get_functions(source: &str) -> _rt::Vec { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); - let vec0 = source; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - let ptr1 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link( - wasm_import_module = "component:pulumi-wasm/function-reverse-callback@0.1.0" - )] - extern "C" { - #[link_name = "get-functions"] - fn wit_import(_: *mut u8, _: usize, _: *mut u8); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: *mut u8, _: usize, _: *mut u8) { - unreachable!() - } - wit_import(ptr0.cast_mut(), len0, ptr1); - let l2 = *ptr1.add(0).cast::<*mut u8>(); - let l3 = *ptr1.add(4).cast::(); - let base11 = l2; - let len11 = l3; - let mut result11 = _rt::Vec::with_capacity(len11); - for i in 0..len11 { - let base = base11.add(i * 20); - let e11 = { - let l4 = *base.add(0).cast::(); - let l5 = *base.add(4).cast::<*mut u8>(); - let l6 = *base.add(8).cast::(); - let len7 = l6; - let bytes7 = _rt::Vec::from_raw_parts(l5.cast(), len7, len7); - let l8 = *base.add(12).cast::<*mut u8>(); - let l9 = *base.add(16).cast::(); - let len10 = l9; - - FunctionInvocationRequest{ - id: super::super::super::component::pulumi_wasm::output_interface::Output::from_handle(l4 as u32), - function_id: _rt::string_lift(bytes7), - value: _rt::Vec::from_raw_parts(l8.cast(), len10, len10), - } - }; - result11.push(e11); - } - _rt::cabi_dealloc(base11, len11 * 20, 4); - result11 - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn set_functions(results: &[FunctionInvocationResult<'_>]) { - unsafe { - let vec2 = results; - 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::(); - 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 FunctionInvocationResult { - id: id0, - value: value0, - } = e; - *base.add(0).cast::() = (id0).handle() as i32; - let vec1 = value0; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - *base.add(8).cast::() = len1; - *base.add(4).cast::<*mut u8>() = ptr1.cast_mut(); - } - } - - #[cfg(target_arch = "wasm32")] - #[link( - wasm_import_module = "component:pulumi-wasm/function-reverse-callback@0.1.0" - )] - extern "C" { - #[link_name = "set-functions"] - fn wit_import(_: *mut u8, _: usize); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: *mut u8, _: usize) { - unreachable!() - } - wit_import(result2, len2); - if layout2.size() != 0 { - _rt::alloc::dealloc(result2.cast(), layout2); - } - } - } - } - - #[allow(clippy::all)] - pub mod log { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = - super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - #[repr(u8)] - #[derive(Clone, Copy, Eq, PartialEq)] - pub enum Level { - Trace, - Debug, - Info, - Warn, - Error, - } - impl ::core::fmt::Debug for Level { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - Level::Trace => f.debug_tuple("Level::Trace").finish(), - Level::Debug => f.debug_tuple("Level::Debug").finish(), - Level::Info => f.debug_tuple("Level::Info").finish(), - Level::Warn => f.debug_tuple("Level::Warn").finish(), - Level::Error => f.debug_tuple("Level::Error").finish(), - } - } - } - - impl Level { - pub(crate) unsafe fn _lift(val: u8) -> Level { - if !cfg!(debug_assertions) { - return ::core::mem::transmute(val); - } - - match val { - 0 => Level::Trace, - 1 => Level::Debug, - 2 => Level::Info, - 3 => Level::Warn, - 4 => Level::Error, - - _ => panic!("invalid enum discriminant"), - } - } - } - - #[derive(Clone)] - pub struct Content { - pub level: Level, - pub target: _rt::String, - pub args: _rt::String, - pub module_path: Option<_rt::String>, - pub file: Option<_rt::String>, - pub line: Option, - pub key_values: _rt::Vec<(_rt::String, _rt::String)>, - } - impl ::core::fmt::Debug for Content { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("Content") - .field("level", &self.level) - .field("target", &self.target) - .field("args", &self.args) - .field("module-path", &self.module_path) - .field("file", &self.file) - .field("line", &self.line) - .field("key-values", &self.key_values) - .finish() - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn log(content: &Content) { - unsafe { - let Content { - level: level0, - target: target0, - args: args0, - module_path: module_path0, - file: file0, - line: line0, - key_values: key_values0, - } = content; - let vec1 = target0; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - let vec2 = args0; - let ptr2 = vec2.as_ptr().cast::(); - let len2 = vec2.len(); - let (result4_0, result4_1, result4_2) = match module_path0 { - Some(e) => { - let vec3 = e; - let ptr3 = vec3.as_ptr().cast::(); - let len3 = vec3.len(); - - (1i32, ptr3.cast_mut(), len3) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result6_0, result6_1, result6_2) = match file0 { - Some(e) => { - let vec5 = e; - let ptr5 = vec5.as_ptr().cast::(); - let len5 = vec5.len(); - - (1i32, ptr5.cast_mut(), len5) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result7_0, result7_1) = match line0 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - let vec11 = key_values0; - let len11 = vec11.len(); - let layout11 = - _rt::alloc::Layout::from_size_align_unchecked(vec11.len() * 16, 4); - let result11 = if layout11.size() != 0 { - let ptr = _rt::alloc::alloc(layout11).cast::(); - if ptr.is_null() { - _rt::alloc::handle_alloc_error(layout11); - } - ptr - } else { - { - ::core::ptr::null_mut() - } - }; - for (i, e) in vec11.into_iter().enumerate() { - let base = result11.add(i * 16); - { - let (t8_0, t8_1) = e; - let vec9 = t8_0; - let ptr9 = vec9.as_ptr().cast::(); - let len9 = vec9.len(); - *base.add(4).cast::() = len9; - *base.add(0).cast::<*mut u8>() = ptr9.cast_mut(); - let vec10 = t8_1; - let ptr10 = vec10.as_ptr().cast::(); - let len10 = vec10.len(); - *base.add(12).cast::() = len10; - *base.add(8).cast::<*mut u8>() = ptr10.cast_mut(); - } - } - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/log@0.1.0")] - extern "C" { - #[link_name = "log"] - fn wit_import( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: i32, - _: *mut u8, - _: usize, - ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: i32, - _: *mut u8, - _: usize, - ) { - unreachable!() - } - wit_import( - level0.clone() as i32, - ptr1.cast_mut(), - len1, - ptr2.cast_mut(), - len2, - result4_0, - result4_1, - result4_2, - result6_0, - result6_1, - result6_2, - result7_0, - result7_1, - result11, - len11, - ); - if layout11.size() != 0 { - _rt::alloc::dealloc(result11.cast(), layout11); - } - } - } - } - } -} -pub mod exports { - pub mod component { - pub mod pulumi_wasm { - - #[allow(clippy::all)] - pub mod pulumi_main { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = - super::super::super::super::__link_custom_section_describing_imports; - - #[doc(hidden)] - #[allow(non_snake_case)] - pub unsafe fn _export_main_cabi() { - T::main(); - } - pub trait Guest { - fn main(); - } - #[doc(hidden)] - - macro_rules! __export_component_pulumi_wasm_pulumi_main_0_1_0_cabi{ - ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { - - - #[export_name = "component:pulumi-wasm/pulumi-main@0.1.0#main"] - unsafe extern "C" fn export_main() { - $($path_to_types)*::_export_main_cabi::<$ty>() - } - };); - } - #[doc(hidden)] - pub(crate) use __export_component_pulumi_wasm_pulumi_main_0_1_0_cabi; - } - } - } -} -mod _rt { - - use core::fmt; - use core::marker; - use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; - - /// A type which represents a component model resource, either imported or - /// exported into this component. - /// - /// This is a low-level wrapper which handles the lifetime of the resource - /// (namely this has a destructor). The `T` provided defines the component model - /// intrinsics that this wrapper uses. - /// - /// One of the chief purposes of this type is to provide `Deref` implementations - /// to access the underlying data when it is owned. - /// - /// This type is primarily used in generated code for exported and imported - /// resources. - #[repr(transparent)] - pub struct Resource { - // NB: This would ideally be `u32` but it is not. The fact that this has - // interior mutability is not exposed in the API of this type except for the - // `take_handle` method which is supposed to in theory be private. - // - // This represents, almost all the time, a valid handle value. When it's - // invalid it's stored as `u32::MAX`. - handle: AtomicU32, - _marker: marker::PhantomData, - } - - /// A trait which all wasm resources implement, namely providing the ability to - /// drop a resource. - /// - /// This generally is implemented by generated code, not user-facing code. - pub unsafe trait WasmResource { - /// Invokes the `[resource-drop]...` intrinsic. - unsafe fn drop(handle: u32); - } - - impl Resource { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - debug_assert!(handle != u32::MAX); - Self { - handle: AtomicU32::new(handle), - _marker: marker::PhantomData, - } - } - - /// Takes ownership of the handle owned by `resource`. - /// - /// Note that this ideally would be `into_handle` taking `Resource` by - /// ownership. The code generator does not enable that in all situations, - /// unfortunately, so this is provided instead. - /// - /// Also note that `take_handle` is in theory only ever called on values - /// owned by a generated function. For example a generated function might - /// take `Resource` as an argument but then call `take_handle` on a - /// reference to that argument. In that sense the dynamic nature of - /// `take_handle` should only be exposed internally to generated code, not - /// to user code. - #[doc(hidden)] - pub fn take_handle(resource: &Resource) -> u32 { - resource.handle.swap(u32::MAX, Relaxed) - } - - #[doc(hidden)] - pub fn handle(resource: &Resource) -> u32 { - resource.handle.load(Relaxed) - } - } - - impl fmt::Debug for Resource { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Resource") - .field("handle", &self.handle) - .finish() - } - } - - impl Drop for Resource { - fn drop(&mut self) { - unsafe { - match self.handle.load(Relaxed) { - // If this handle was "taken" then don't do anything in the - // destructor. - u32::MAX => {} - - // ... but otherwise do actually destroy it with the imported - // component model intrinsic as defined through `T`. - other => T::drop(other), - } - } - } - } - pub use alloc_crate::string::String; - pub use alloc_crate::vec::Vec; - pub unsafe fn string_lift(bytes: Vec) -> String { - if cfg!(debug_assertions) { - String::from_utf8(bytes).unwrap() - } else { - String::from_utf8_unchecked(bytes) - } - } - pub unsafe fn bool_lift(val: u8) -> bool { - if cfg!(debug_assertions) { - match val { - 0 => false, - 1 => true, - _ => panic!("invalid bool discriminant"), - } - } else { - ::core::mem::transmute::(val) - } - } - pub unsafe fn invalid_enum_discriminant() -> T { - if cfg!(debug_assertions) { - panic!("invalid enum discriminant") - } else { - core::hint::unreachable_unchecked() - } - } - pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { - if size == 0 { - return; - } - let layout = alloc::Layout::from_size_align_unchecked(size, align); - alloc::dealloc(ptr as *mut u8, layout); - } - pub use alloc_crate::alloc; - - pub fn as_i32(t: T) -> i32 { - t.as_i32() - } - - pub trait AsI32 { - fn as_i32(self) -> i32; - } - - impl<'a, T: Copy + AsI32> AsI32 for &'a T { - fn as_i32(self) -> i32 { - (*self).as_i32() - } - } - - impl AsI32 for i32 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for u32 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for i16 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for u16 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for i8 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for u8 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for char { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for usize { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - extern crate alloc as alloc_crate; -} - -/// Generates `#[no_mangle]` functions to export the specified type as the -/// root implementation of all generated traits. -/// -/// For more information see the documentation of `wit_bindgen::generate!`. -/// -/// ```rust -/// # macro_rules! export{ ($($t:tt)*) => (); } -/// # trait Guest {} -/// struct MyType; -/// -/// impl Guest for MyType { -/// // ... -/// } -/// -/// export!(MyType); -/// ``` -#[allow(unused_macros)] -#[doc(hidden)] - -macro_rules! __export_new_main_impl { - ($ty:ident) => (self::export!($ty with_types_in self);); - ($ty:ident with_types_in $($path_to_types_root:tt)*) => ( - $($path_to_types_root)*::exports::component::pulumi_wasm::pulumi_main::__export_component_pulumi_wasm_pulumi_main_0_1_0_cabi!($ty with_types_in $($path_to_types_root)*::exports::component::pulumi_wasm::pulumi_main); - ) -} -#[doc(inline)] -pub(crate) use __export_new_main_impl as export; #[cfg(target_arch = "wasm32")] -#[link_section = "component-type:wit-bindgen:0.20.0:new-main:encoded world"] +#[link_section = "component-type:wit-bindgen:0.20.0:pulumi_wasm_example_simple:encoded world"] #[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1364] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xd5\x09\x01A\x02\x01\ -A\x0b\x01B\x16\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@\x02\x04self\x04\x05fields\0\x02\x04\0\x18[\ -method]output.get-field\x01\x08\x01@\x01\x04self\x04\0s\x04\0\x17[method]output.\ -get-type\x01\x09\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]output.duplicate\x01\ -\x0a\x01@\0\0s\x04\0\x10describe-outputs\x01\x0b\x01@\0\0\x7f\x04\0\x0fnon-done-\ -exists\x01\x0c\x04\0\x0fcombine-outputs\x01\x0c\x03\x01,component:pulumi-wasm/ou\ -tput-interface@0.1.0\x05\0\x02\x03\0\0\x06output\x01B\x10\x02\x03\x02\x01\x01\x04\ -\0\x06output\x03\0\0\x01ky\x01h\x01\x01k\x03\x01q\x02\x07literal\x01\x02\0\x03re\ -s\x01\x04\0\x04\0\x0aeither-u32\x03\0\x05\x01r\x02\x04names\x06length\x03\x04\0\x12\ -random-string-args\x03\0\x07\x01i\x01\x01r\x01\x06result\x09\x04\0\x14random-str\ -ing-result\x03\0\x0a\x01@\x01\x04args\x08\0\x0b\x04\0\x14create-random-string\x01\ -\x0c\x01@\0\x01\0\x04\0\x10handle-functions\x01\x0d\x03\x01 Result<(), Error> { + wasm_common::setup_logger(); -mod random; + let length: Output = Output::new(&12).map(|i: i32| i * 3); -struct Component {} + let _ = create_random_string(RandomStringArgs { + name: "test", + length, + }); -impl Guest for Component { - fn main() { - wasm_common::setup_logger(); - - let length: Output = Output::new(&1).map(|i: i32| i * 3); - - let _v = create_random_string(RandomStringArgs { - name: "test123456", - length, - }); - - // let new_length = v.map(|s| s.len() as i32); - // - // let v = create_random_string(RandomStringArgs { - // name: "test123_2", - // length: new_length, - // }); - - run_loop().unwrap(); - - info!("{}", describe_outputs()); - - if non_done_exists() { - error!("Non done exists"); - panic!("Non done exists"); - } - } -} - -fn run_loop() -> Result<(), Error> { - loop { - if !run_all_function()? && !combine_outputs() { - return Ok(()); - } - } + Ok(()) } - -fn run_all_function( - // store: &mut Store, - // plugin: &PulumiWasm, -) -> Result { - let functions = get_functions("source"); - - if functions.is_empty() { - info!("Functions are empty"); - return Ok(false) - } - - info!("Functions are not empty"); - - let functions_map = HASHMAP.lock().unwrap(); - - let mapped: Result, _> = functions - .iter() - .map( - |FunctionInvocationRequest { - id, - function_id, - value, - }| { - info!("Invoking function [{function_id}] with value [{value:?}]"); - let v = rmpv::decode::read_value(&mut value.clone().as_slice())?; - info!("Invoking function [{function_id}] with value [{v:?}]"); - let f = functions_map.get(function_id).context(format!("Function with id {function_id} not found"))?; - Ok(FunctionInvocationResult { - id, - value: f(value.to_vec())?, - }) - }, - ) - .collect(); - - // mapped - - let mapped = match mapped { - Ok(mapped) => mapped, - Err(e) => { - error!("Failed to invoke functions due to [{e}]"); - return Err(e); - } - }; - - info!("Setting functions"); - set_functions(&mapped); - info!("run_all_function completed"); - - Ok(true) -} - diff --git a/providers/pulumi_wasm_provider_random/Cargo.toml b/providers/pulumi_wasm_provider_random/Cargo.toml index 501c2d33f..42528d791 100644 --- a/providers/pulumi_wasm_provider_random/Cargo.toml +++ b/providers/pulumi_wasm_provider_random/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pulumi_wasm_provider_random" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -25,7 +25,7 @@ serde.workspace = true tonic.workspace = true serde_json.workspace = true log.workspace = true -wasm_common = { path = "../../wasm_common" } +wasm_common.workspace = true [dev-dependencies] wasmtime.workspace = true diff --git a/providers/pulumi_wasm_provider_random_rust/Cargo.toml b/providers/pulumi_wasm_provider_random_rust/Cargo.toml new file mode 100644 index 000000000..f438cba84 --- /dev/null +++ b/providers/pulumi_wasm_provider_random_rust/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "pulumi_wasm_provider_random_rust" +version.workspace = true +edition.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow.workspace = true +wit-bindgen.workspace = true +serde.workspace = true +pulumi_wasm_rust.workspace = true +log.workspace = true +wasm_common.workspace = true diff --git a/providers/pulumi_wasm_provider_random_rust/src/bindings.rs b/providers/pulumi_wasm_provider_random_rust/src/bindings.rs new file mode 100644 index 000000000..17f2c975a --- /dev/null +++ b/providers/pulumi_wasm_provider_random_rust/src/bindings.rs @@ -0,0 +1,1025 @@ +// Generated by `wit-bindgen` 0.20.0. DO NOT EDIT! +// Options used: +pub mod component { + pub mod pulumi_wasm { + + #[allow(clippy::all)] + pub mod output_interface { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + + #[derive(Debug)] + #[repr(transparent)] + pub struct Output { + handle: _rt::Resource, + } + + impl Output { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + + unsafe impl _rt::WasmResource for Output { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "[resource-drop]output"] + fn drop(_: u32); + } + + drop(_handle); + } + } + } + + #[allow(unused_unsafe, clippy::all)] + pub fn describe_outputs() -> _rt::String { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "describe-outputs"] + fn wit_import(_: *mut u8); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8) { + unreachable!() + } + wit_import(ptr0); + let l1 = *ptr0.add(0).cast::<*mut u8>(); + let l2 = *ptr0.add(4).cast::(); + let len3 = l2; + let bytes3 = _rt::Vec::from_raw_parts(l1.cast(), len3, len3); + _rt::string_lift(bytes3) + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn non_done_exists() -> bool { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "non-done-exists"] + fn wit_import() -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> i32 { + unreachable!() + } + let ret = wit_import(); + _rt::bool_lift(ret as u8) + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn combine_outputs() -> bool { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "combine-outputs"] + fn wit_import() -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> i32 { + unreachable!() + } + let ret = wit_import(); + _rt::bool_lift(ret as u8) + } + } + impl Output { + #[allow(unused_unsafe, clippy::all)] + pub fn new(value: &[u8]) -> Self { + unsafe { + let vec0 = value; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "[constructor]output"] + fn wit_import(_: *mut u8, _: usize) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = wit_import(ptr0.cast_mut(), len0); + Output::from_handle(ret as u32) + } + } + } + impl Output { + #[allow(unused_unsafe, clippy::all)] + pub fn map(&self, function_name: &str) -> Output { + unsafe { + let vec0 = function_name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "[method]output.map"] + fn wit_import(_: i32, _: *mut u8, _: usize) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0); + Output::from_handle(ret as u32) + } + } + } + impl Output { + #[allow(unused_unsafe, clippy::all)] + pub fn get(&self) -> Option<_rt::Vec> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "[method]output.get"] + fn wit_import(_: i32, _: *mut u8); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + + _rt::Vec::from_raw_parts(l2.cast(), len4, len4) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl Output { + #[allow(unused_unsafe, clippy::all)] + pub fn get_field(&self, field: &str) -> Output { + unsafe { + let vec0 = field; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "[method]output.get-field"] + fn wit_import(_: i32, _: *mut u8, _: usize) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0); + Output::from_handle(ret as u32) + } + } + } + impl Output { + #[allow(unused_unsafe, clippy::all)] + pub fn get_type(&self) -> _rt::String { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "[method]output.get-type"] + fn wit_import(_: i32, _: *mut u8); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = *ptr0.add(0).cast::<*mut u8>(); + let l2 = *ptr0.add(4).cast::(); + let len3 = l2; + let bytes3 = _rt::Vec::from_raw_parts(l1.cast(), len3, len3); + _rt::string_lift(bytes3) + } + } + } + impl Output { + #[allow(unused_unsafe, clippy::all)] + pub fn duplicate(&self) -> Output { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] + extern "C" { + #[link_name = "[method]output.duplicate"] + fn wit_import(_: i32) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + Output::from_handle(ret as u32) + } + } + } + } + + #[allow(clippy::all)] + pub mod pulumi_provider_random_interface { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type Output = super::super::super::component::pulumi_wasm::output_interface::Output; + pub struct RandomStringArgs<'a> { + pub name: _rt::String, + pub length: &'a Output, + } + impl<'a> ::core::fmt::Debug for RandomStringArgs<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("RandomStringArgs") + .field("name", &self.name) + .field("length", &self.length) + .finish() + } + } + pub struct RandomStringResult { + pub result: Output, + } + impl ::core::fmt::Debug for RandomStringResult { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("RandomStringResult") + .field("result", &self.result) + .finish() + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn create_random_string(args: &RandomStringArgs<'_>) -> RandomStringResult { + unsafe { + let RandomStringArgs { + name: name0, + length: length0, + } = args; + let vec1 = name0; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "component:pulumi-wasm/pulumi-provider-random-interface@0.1.0" + )] + extern "C" { + #[link_name = "create-random-string"] + fn wit_import(_: *mut u8, _: usize, _: i32) -> i32; + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize, _: i32) -> i32 { + unreachable!() + } + let ret = wit_import(ptr1.cast_mut(), len1, (length0).handle() as i32); + RandomStringResult{ + result: super::super::super::component::pulumi_wasm::output_interface::Output::from_handle(ret as u32), + } + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn handle_functions() { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "component:pulumi-wasm/pulumi-provider-random-interface@0.1.0" + )] + extern "C" { + #[link_name = "handle-functions"] + fn wit_import(); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() { + unreachable!() + } + wit_import(); + } + } + } + + #[allow(clippy::all)] + pub mod function_reverse_callback { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type Output = super::super::super::component::pulumi_wasm::output_interface::Output; + pub struct FunctionInvocationRequest { + pub id: Output, + pub function_id: _rt::String, + pub value: _rt::Vec, + } + impl ::core::fmt::Debug for FunctionInvocationRequest { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("FunctionInvocationRequest") + .field("id", &self.id) + .field("function-id", &self.function_id) + .field("value", &self.value) + .finish() + } + } + pub struct FunctionInvocationResult<'a> { + pub id: &'a Output, + pub value: _rt::Vec, + } + impl<'a> ::core::fmt::Debug for FunctionInvocationResult<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("FunctionInvocationResult") + .field("id", &self.id) + .field("value", &self.value) + .finish() + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn get_functions(source: &str) -> _rt::Vec { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let vec0 = source; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "component:pulumi-wasm/function-reverse-callback@0.1.0" + )] + extern "C" { + #[link_name = "get-functions"] + fn wit_import(_: *mut u8, _: usize, _: *mut u8); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import(ptr0.cast_mut(), len0, ptr1); + let l2 = *ptr1.add(0).cast::<*mut u8>(); + let l3 = *ptr1.add(4).cast::(); + let base11 = l2; + let len11 = l3; + let mut result11 = _rt::Vec::with_capacity(len11); + for i in 0..len11 { + let base = base11.add(i * 20); + let e11 = { + let l4 = *base.add(0).cast::(); + let l5 = *base.add(4).cast::<*mut u8>(); + let l6 = *base.add(8).cast::(); + let len7 = l6; + let bytes7 = _rt::Vec::from_raw_parts(l5.cast(), len7, len7); + let l8 = *base.add(12).cast::<*mut u8>(); + let l9 = *base.add(16).cast::(); + let len10 = l9; + + FunctionInvocationRequest{ + id: super::super::super::component::pulumi_wasm::output_interface::Output::from_handle(l4 as u32), + function_id: _rt::string_lift(bytes7), + value: _rt::Vec::from_raw_parts(l8.cast(), len10, len10), + } + }; + result11.push(e11); + } + _rt::cabi_dealloc(base11, len11 * 20, 4); + result11 + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn set_functions(results: &[FunctionInvocationResult<'_>]) { + unsafe { + let vec2 = results; + 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::(); + 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 FunctionInvocationResult { + id: id0, + value: value0, + } = e; + *base.add(0).cast::() = (id0).handle() as i32; + let vec1 = value0; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + *base.add(8).cast::() = len1; + *base.add(4).cast::<*mut u8>() = ptr1.cast_mut(); + } + } + + #[cfg(target_arch = "wasm32")] + #[link( + wasm_import_module = "component:pulumi-wasm/function-reverse-callback@0.1.0" + )] + extern "C" { + #[link_name = "set-functions"] + fn wit_import(_: *mut u8, _: usize); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize) { + unreachable!() + } + wit_import(result2, len2); + if layout2.size() != 0 { + _rt::alloc::dealloc(result2.cast(), layout2); + } + } + } + } + + #[allow(clippy::all)] + pub mod log { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + #[repr(u8)] + #[derive(Clone, Copy, Eq, PartialEq)] + pub enum Level { + Trace, + Debug, + Info, + Warn, + Error, + } + impl ::core::fmt::Debug for Level { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + Level::Trace => f.debug_tuple("Level::Trace").finish(), + Level::Debug => f.debug_tuple("Level::Debug").finish(), + Level::Info => f.debug_tuple("Level::Info").finish(), + Level::Warn => f.debug_tuple("Level::Warn").finish(), + Level::Error => f.debug_tuple("Level::Error").finish(), + } + } + } + + impl Level { + pub(crate) unsafe fn _lift(val: u8) -> Level { + if !cfg!(debug_assertions) { + return ::core::mem::transmute(val); + } + + match val { + 0 => Level::Trace, + 1 => Level::Debug, + 2 => Level::Info, + 3 => Level::Warn, + 4 => Level::Error, + + _ => panic!("invalid enum discriminant"), + } + } + } + + #[derive(Clone)] + pub struct Content { + pub level: Level, + pub target: _rt::String, + pub args: _rt::String, + pub module_path: Option<_rt::String>, + pub file: Option<_rt::String>, + pub line: Option, + pub key_values: _rt::Vec<(_rt::String, _rt::String)>, + } + impl ::core::fmt::Debug for Content { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("Content") + .field("level", &self.level) + .field("target", &self.target) + .field("args", &self.args) + .field("module-path", &self.module_path) + .field("file", &self.file) + .field("line", &self.line) + .field("key-values", &self.key_values) + .finish() + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn log(content: &Content) { + unsafe { + let Content { + level: level0, + target: target0, + args: args0, + module_path: module_path0, + file: file0, + line: line0, + key_values: key_values0, + } = content; + let vec1 = target0; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + let vec2 = args0; + let ptr2 = vec2.as_ptr().cast::(); + let len2 = vec2.len(); + let (result4_0, result4_1, result4_2) = match module_path0 { + Some(e) => { + let vec3 = e; + let ptr3 = vec3.as_ptr().cast::(); + let len3 = vec3.len(); + + (1i32, ptr3.cast_mut(), len3) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result6_0, result6_1, result6_2) = match file0 { + Some(e) => { + let vec5 = e; + let ptr5 = vec5.as_ptr().cast::(); + let len5 = vec5.len(); + + (1i32, ptr5.cast_mut(), len5) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result7_0, result7_1) = match line0 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + let vec11 = key_values0; + let len11 = vec11.len(); + let layout11 = + _rt::alloc::Layout::from_size_align_unchecked(vec11.len() * 16, 4); + let result11 = if layout11.size() != 0 { + let ptr = _rt::alloc::alloc(layout11).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout11); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec11.into_iter().enumerate() { + let base = result11.add(i * 16); + { + let (t8_0, t8_1) = e; + let vec9 = t8_0; + let ptr9 = vec9.as_ptr().cast::(); + let len9 = vec9.len(); + *base.add(4).cast::() = len9; + *base.add(0).cast::<*mut u8>() = ptr9.cast_mut(); + let vec10 = t8_1; + let ptr10 = vec10.as_ptr().cast::(); + let len10 = vec10.len(); + *base.add(12).cast::() = len10; + *base.add(8).cast::<*mut u8>() = ptr10.cast_mut(); + } + } + + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "component:pulumi-wasm/log@0.1.0")] + extern "C" { + #[link_name = "log"] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: i32, + _: *mut u8, + _: usize, + _: i32, + _: *mut u8, + _: usize, + _: i32, + _: i32, + _: *mut u8, + _: usize, + ); + } + + #[cfg(not(target_arch = "wasm32"))] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: i32, + _: *mut u8, + _: usize, + _: i32, + _: *mut u8, + _: usize, + _: i32, + _: i32, + _: *mut u8, + _: usize, + ) { + unreachable!() + } + wit_import( + level0.clone() as i32, + ptr1.cast_mut(), + len1, + ptr2.cast_mut(), + len2, + result4_0, + result4_1, + result4_2, + result6_0, + result6_1, + result6_2, + result7_0, + result7_1, + result11, + len11, + ); + if layout11.size() != 0 { + _rt::alloc::dealloc(result11.cast(), layout11); + } + } + } + } + } +} +pub mod exports { + pub mod component { + pub mod pulumi_wasm { + + #[allow(clippy::all)] + pub mod pulumi_main { + #[used] + #[doc(hidden)] + #[cfg(target_arch = "wasm32")] + static __FORCE_SECTION_REF: fn() = + super::super::super::super::__link_custom_section_describing_imports; + + #[doc(hidden)] + #[allow(non_snake_case)] + pub unsafe fn _export_main_cabi() { + T::main(); + } + pub trait Guest { + fn main(); + } + #[doc(hidden)] + + macro_rules! __export_component_pulumi_wasm_pulumi_main_0_1_0_cabi{ + ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = { + + + #[export_name = "component:pulumi-wasm/pulumi-main@0.1.0#main"] + unsafe extern "C" fn export_main() { + $($path_to_types)*::_export_main_cabi::<$ty>() + } + };); + } + #[doc(hidden)] + pub(crate) use __export_component_pulumi_wasm_pulumi_main_0_1_0_cabi; + } + } + } +} +mod _rt { + + use core::fmt; + use core::marker; + use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; + + /// A type which represents a component model resource, either imported or + /// exported into this component. + /// + /// This is a low-level wrapper which handles the lifetime of the resource + /// (namely this has a destructor). The `T` provided defines the component model + /// intrinsics that this wrapper uses. + /// + /// One of the chief purposes of this type is to provide `Deref` implementations + /// to access the underlying data when it is owned. + /// + /// This type is primarily used in generated code for exported and imported + /// resources. + #[repr(transparent)] + pub struct Resource { + // NB: This would ideally be `u32` but it is not. The fact that this has + // interior mutability is not exposed in the API of this type except for the + // `take_handle` method which is supposed to in theory be private. + // + // This represents, almost all the time, a valid handle value. When it's + // invalid it's stored as `u32::MAX`. + handle: AtomicU32, + _marker: marker::PhantomData, + } + + /// A trait which all wasm resources implement, namely providing the ability to + /// drop a resource. + /// + /// This generally is implemented by generated code, not user-facing code. + pub unsafe trait WasmResource { + /// Invokes the `[resource-drop]...` intrinsic. + unsafe fn drop(handle: u32); + } + + impl Resource { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + debug_assert!(handle != u32::MAX); + Self { + handle: AtomicU32::new(handle), + _marker: marker::PhantomData, + } + } + + /// Takes ownership of the handle owned by `resource`. + /// + /// Note that this ideally would be `into_handle` taking `Resource` by + /// ownership. The code generator does not enable that in all situations, + /// unfortunately, so this is provided instead. + /// + /// Also note that `take_handle` is in theory only ever called on values + /// owned by a generated function. For example a generated function might + /// take `Resource` as an argument but then call `take_handle` on a + /// reference to that argument. In that sense the dynamic nature of + /// `take_handle` should only be exposed internally to generated code, not + /// to user code. + #[doc(hidden)] + pub fn take_handle(resource: &Resource) -> u32 { + resource.handle.swap(u32::MAX, Relaxed) + } + + #[doc(hidden)] + pub fn handle(resource: &Resource) -> u32 { + resource.handle.load(Relaxed) + } + } + + impl fmt::Debug for Resource { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Resource") + .field("handle", &self.handle) + .finish() + } + } + + impl Drop for Resource { + fn drop(&mut self) { + unsafe { + match self.handle.load(Relaxed) { + // If this handle was "taken" then don't do anything in the + // destructor. + u32::MAX => {} + + // ... but otherwise do actually destroy it with the imported + // component model intrinsic as defined through `T`. + other => T::drop(other), + } + } + } + } + pub use alloc_crate::string::String; + pub use alloc_crate::vec::Vec; + pub unsafe fn string_lift(bytes: Vec) -> String { + if cfg!(debug_assertions) { + String::from_utf8(bytes).unwrap() + } else { + String::from_utf8_unchecked(bytes) + } + } + pub unsafe fn bool_lift(val: u8) -> bool { + if cfg!(debug_assertions) { + match val { + 0 => false, + 1 => true, + _ => panic!("invalid bool discriminant"), + } + } else { + ::core::mem::transmute::(val) + } + } + pub unsafe fn invalid_enum_discriminant() -> T { + if cfg!(debug_assertions) { + panic!("invalid enum discriminant") + } else { + core::hint::unreachable_unchecked() + } + } + pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { + if size == 0 { + return; + } + let layout = alloc::Layout::from_size_align_unchecked(size, align); + alloc::dealloc(ptr as *mut u8, layout); + } + pub use alloc_crate::alloc; + + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + + pub trait AsI32 { + fn as_i32(self) -> i32; + } + + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + extern crate alloc as alloc_crate; +} + +/// Generates `#[no_mangle]` functions to export the specified type as the +/// root implementation of all generated traits. +/// +/// For more information see the documentation of `wit_bindgen::generate!`. +/// +/// ```rust +/// # macro_rules! export{ ($($t:tt)*) => (); } +/// # trait Guest {} +/// struct MyType; +/// +/// impl Guest for MyType { +/// // ... +/// } +/// +/// export!(MyType); +/// ``` +#[allow(unused_macros)] +#[doc(hidden)] + +macro_rules! __export_new_main_impl { + ($ty:ident) => (self::export!($ty with_types_in self);); + ($ty:ident with_types_in $($path_to_types_root:tt)*) => ( + $($path_to_types_root)*::exports::component::pulumi_wasm::pulumi_main::__export_component_pulumi_wasm_pulumi_main_0_1_0_cabi!($ty with_types_in $($path_to_types_root)*::exports::component::pulumi_wasm::pulumi_main); + ) +} +#[doc(inline)] +pub(crate) use __export_new_main_impl as export; + +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:wit-bindgen:0.20.0:new-main:encoded world"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1364] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xd5\x09\x01A\x02\x01\ +A\x0b\x01B\x16\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@\x02\x04self\x04\x05fields\0\x02\x04\0\x18[\ +method]output.get-field\x01\x08\x01@\x01\x04self\x04\0s\x04\0\x17[method]output.\ +get-type\x01\x09\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]output.duplicate\x01\ +\x0a\x01@\0\0s\x04\0\x10describe-outputs\x01\x0b\x01@\0\0\x7f\x04\0\x0fnon-done-\ +exists\x01\x0c\x04\0\x0fcombine-outputs\x01\x0c\x03\x01,component:pulumi-wasm/ou\ +tput-interface@0.1.0\x05\0\x02\x03\0\0\x06output\x01B\x10\x02\x03\x02\x01\x01\x04\ +\0\x06output\x03\0\0\x01ky\x01h\x01\x01k\x03\x01q\x02\x07literal\x01\x02\0\x03re\ +s\x01\x04\0\x04\0\x0aeither-u32\x03\0\x05\x01r\x02\x04names\x06length\x03\x04\0\x12\ +random-string-args\x03\0\x07\x01i\x01\x01r\x01\x06result\x09\x04\0\x14random-str\ +ing-result\x03\0\x0a\x01@\x01\x04args\x08\0\x0b\x04\0\x14create-random-string\x01\ +\x0c\x01@\0\x01\0\x04\0\x10handle-functions\x01\x0d\x03\x01 { - pub(crate) name: &'a str, - pub(crate) length: Output, + pub name: &'a str, + pub length: Output, } pub fn create_random_string( diff --git a/pulumi_wasm/Cargo.toml b/pulumi_wasm/Cargo.toml index cbea27853..e3482632e 100644 --- a/pulumi_wasm/Cargo.toml +++ b/pulumi_wasm/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pulumi_wasm" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -24,7 +24,7 @@ rmpv.workspace = true serde.workspace = true tonic.workspace = true serde_json.workspace = true -wasm_common = { path = "../wasm_common" } +wasm_common.workspace = true log.workspace = true [build-dependencies] diff --git a/pulumi_wasm_runner/Cargo.toml b/pulumi_wasm_runner/Cargo.toml index 15f31a942..f22556589 100644 --- a/pulumi_wasm_runner/Cargo.toml +++ b/pulumi_wasm_runner/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pulumi_wasm_runner" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/pulumi_wasm_rust/Cargo.toml b/pulumi_wasm_rust/Cargo.toml index 89b578158..b92b733b0 100644 --- a/pulumi_wasm_rust/Cargo.toml +++ b/pulumi_wasm_rust/Cargo.toml @@ -1,17 +1,13 @@ [package] -name = "pulumi_rust_wasm" -version = "0.1.0" -edition = "2021" +name = "pulumi_wasm_rust" +version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -crate-type = ["rlib", "cdylib"] - [dependencies] uuid.workspace = true bitflags.workspace = true -wit-bindgen-rt.workspace = true anyhow.workspace = true serde.workspace = true rmp-serde.workspace = true @@ -19,10 +15,7 @@ serde_json.workspace = true futures.workspace = true lazy_static.workspace = true log.workspace = true - -[package.metadata.component] -package = "component:pulumi-rust-wasm" - -[package.metadata.component.target] -path = "../wits/world.wit" -world = "pulumi-rust" +wit-bindgen.workspace = true +pulumi_wasm_rust_macro.workspace = true +wasm_common.workspace = true +rmpv.workspace = true \ No newline at end of file diff --git a/pulumi_wasm_rust/src/bindings.rs b/pulumi_wasm_rust/src/bindings.rs deleted file mode 100644 index 8ca0c375a..000000000 --- a/pulumi_wasm_rust/src/bindings.rs +++ /dev/null @@ -1,429 +0,0 @@ -// Generated by `wit-bindgen` 0.20.0. DO NOT EDIT! -// Options used: -pub mod component { - pub mod pulumi_wasm { - - #[allow(clippy::all)] - pub mod output_interface { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = - super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - - #[derive(Debug)] - #[repr(transparent)] - pub struct Output { - handle: _rt::Resource, - } - - impl Output { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: _rt::Resource::from_handle(handle), - } - } - - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - - unsafe impl _rt::WasmResource for Output { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(not(target_arch = "wasm32"))] - unreachable!(); - - #[cfg(target_arch = "wasm32")] - { - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[resource-drop]output"] - fn drop(_: u32); - } - - drop(_handle); - } - } - } - - #[allow(unused_unsafe, clippy::all)] - pub fn describe_outputs() -> _rt::String { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "describe-outputs"] - fn wit_import(_: *mut u8); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: *mut u8) { - unreachable!() - } - wit_import(ptr0); - let l1 = *ptr0.add(0).cast::<*mut u8>(); - let l2 = *ptr0.add(4).cast::(); - let len3 = l2; - let bytes3 = _rt::Vec::from_raw_parts(l1.cast(), len3, len3); - _rt::string_lift(bytes3) - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn non_done_exists() -> bool { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "non-done-exists"] - fn wit_import() -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import() -> i32 { - unreachable!() - } - let ret = wit_import(); - _rt::bool_lift(ret as u8) - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn combine_outputs() -> bool { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "combine-outputs"] - fn wit_import() -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import() -> i32 { - unreachable!() - } - let ret = wit_import(); - _rt::bool_lift(ret as u8) - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn new(value: &[u8]) -> Self { - unsafe { - let vec0 = value; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[constructor]output"] - fn wit_import(_: *mut u8, _: usize) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: *mut u8, _: usize) -> i32 { - unreachable!() - } - let ret = wit_import(ptr0.cast_mut(), len0); - Output::from_handle(ret as u32) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn map(&self, function_name: &str) -> Output { - unsafe { - let vec0 = function_name; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.map"] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 { - unreachable!() - } - let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0); - Output::from_handle(ret as u32) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn get(&self) -> Option<_rt::Vec> { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 12]); - let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.get"] - fn wit_import(_: i32, _: *mut u8); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8) { - unreachable!() - } - wit_import((self).handle() as i32, ptr0); - let l1 = i32::from(*ptr0.add(0).cast::()); - match l1 { - 0 => None, - 1 => { - let e = { - let l2 = *ptr0.add(4).cast::<*mut u8>(); - let l3 = *ptr0.add(8).cast::(); - let len4 = l3; - - _rt::Vec::from_raw_parts(l2.cast(), len4, len4) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn get_field(&self, field: &str) -> Output { - unsafe { - let vec0 = field; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.get-field"] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 { - unreachable!() - } - let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0); - Output::from_handle(ret as u32) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn get_type(&self) -> _rt::String { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.get-type"] - fn wit_import(_: i32, _: *mut u8); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32, _: *mut u8) { - unreachable!() - } - wit_import((self).handle() as i32, ptr0); - let l1 = *ptr0.add(0).cast::<*mut u8>(); - let l2 = *ptr0.add(4).cast::(); - let len3 = l2; - let bytes3 = _rt::Vec::from_raw_parts(l1.cast(), len3, len3); - _rt::string_lift(bytes3) - } - } - } - impl Output { - #[allow(unused_unsafe, clippy::all)] - pub fn duplicate(&self) -> Output { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/output-interface@0.1.0")] - extern "C" { - #[link_name = "[method]output.duplicate"] - fn wit_import(_: i32) -> i32; - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import((self).handle() as i32); - Output::from_handle(ret as u32) - } - } - } - } - } -} -mod _rt { - - use core::fmt; - use core::marker; - use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; - - /// A type which represents a component model resource, either imported or - /// exported into this component. - /// - /// This is a low-level wrapper which handles the lifetime of the resource - /// (namely this has a destructor). The `T` provided defines the component model - /// intrinsics that this wrapper uses. - /// - /// One of the chief purposes of this type is to provide `Deref` implementations - /// to access the underlying data when it is owned. - /// - /// This type is primarily used in generated code for exported and imported - /// resources. - #[repr(transparent)] - pub struct Resource { - // NB: This would ideally be `u32` but it is not. The fact that this has - // interior mutability is not exposed in the API of this type except for the - // `take_handle` method which is supposed to in theory be private. - // - // This represents, almost all the time, a valid handle value. When it's - // invalid it's stored as `u32::MAX`. - handle: AtomicU32, - _marker: marker::PhantomData, - } - - /// A trait which all wasm resources implement, namely providing the ability to - /// drop a resource. - /// - /// This generally is implemented by generated code, not user-facing code. - pub unsafe trait WasmResource { - /// Invokes the `[resource-drop]...` intrinsic. - unsafe fn drop(handle: u32); - } - - impl Resource { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - debug_assert!(handle != u32::MAX); - Self { - handle: AtomicU32::new(handle), - _marker: marker::PhantomData, - } - } - - /// Takes ownership of the handle owned by `resource`. - /// - /// Note that this ideally would be `into_handle` taking `Resource` by - /// ownership. The code generator does not enable that in all situations, - /// unfortunately, so this is provided instead. - /// - /// Also note that `take_handle` is in theory only ever called on values - /// owned by a generated function. For example a generated function might - /// take `Resource` as an argument but then call `take_handle` on a - /// reference to that argument. In that sense the dynamic nature of - /// `take_handle` should only be exposed internally to generated code, not - /// to user code. - #[doc(hidden)] - pub fn take_handle(resource: &Resource) -> u32 { - resource.handle.swap(u32::MAX, Relaxed) - } - - #[doc(hidden)] - pub fn handle(resource: &Resource) -> u32 { - resource.handle.load(Relaxed) - } - } - - impl fmt::Debug for Resource { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Resource") - .field("handle", &self.handle) - .finish() - } - } - - impl Drop for Resource { - fn drop(&mut self) { - unsafe { - match self.handle.load(Relaxed) { - // If this handle was "taken" then don't do anything in the - // destructor. - u32::MAX => {} - - // ... but otherwise do actually destroy it with the imported - // component model intrinsic as defined through `T`. - other => T::drop(other), - } - } - } - } - pub use alloc_crate::string::String; - pub use alloc_crate::vec::Vec; - pub unsafe fn string_lift(bytes: Vec) -> String { - if cfg!(debug_assertions) { - String::from_utf8(bytes).unwrap() - } else { - String::from_utf8_unchecked(bytes) - } - } - pub unsafe fn bool_lift(val: u8) -> bool { - if cfg!(debug_assertions) { - match val { - 0 => false, - 1 => true, - _ => panic!("invalid bool discriminant"), - } - } else { - ::core::mem::transmute::(val) - } - } - pub unsafe fn invalid_enum_discriminant() -> T { - if cfg!(debug_assertions) { - panic!("invalid enum discriminant") - } else { - core::hint::unreachable_unchecked() - } - } - extern crate alloc as alloc_crate; -} - -#[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; 571] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb9\x03\x01A\x02\x01\ -A\x02\x01B\x16\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@\x02\x04self\x04\x05fields\0\x02\x04\0\x18[\ -method]output.get-field\x01\x08\x01@\x01\x04self\x04\0s\x04\0\x17[method]output.\ -get-type\x01\x09\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]output.duplicate\x01\ -\x0a\x01@\0\0s\x04\0\x10describe-outputs\x01\x0b\x01@\0\0\x7f\x04\0\x0fnon-done-\ -exists\x01\x0c\x04\0\x0fcombine-outputs\x01\x0c\x03\x01,component:pulumi-wasm/ou\ -tput-interface@0.1.0\x05\0\x04\x01'component:pulumi-wasm/pulumi-rust@0.1.0\x04\0\ -\x0b\x11\x01\0\x0bpulumi-rust\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0d\ -wit-component\x070.201.0\x10wit-bindgen-rust\x060.20.0"; - -#[inline(never)] -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn __link_custom_section_describing_imports() { - wit_bindgen_rt::maybe_link_cabi_realloc(); -} diff --git a/pulumi_wasm_rust/src/lib.rs b/pulumi_wasm_rust/src/lib.rs index d918f9c8a..a95b3a0c0 100644 --- a/pulumi_wasm_rust/src/lib.rs +++ b/pulumi_wasm_rust/src/lib.rs @@ -1,12 +1,112 @@ use std::collections::HashMap; use std::sync::Mutex; +use anyhow::{Context, Error}; use lazy_static::lazy_static; +use log::{error, info}; + +pub use pulumi_wasm_rust_macro::pulumi_main; +use crate::bindings::component::pulumi_wasm::function_reverse_callback::{FunctionInvocationRequest, FunctionInvocationResult, get_functions, set_functions}; +use crate::bindings::component::pulumi_wasm::output_interface::combine_outputs; #[allow(clippy::all)] #[allow(dead_code)] #[allow(unused_variables)] #[allow(unused_unsafe)] -pub(crate) mod bindings; +mod bindings { + wit_bindgen::generate!({ + // the name of the world in the `*.wit` input file + world: "pulumi-wasm-rust", + path: "../wits/world.wit" + }); +} + +pub fn run(f: F) -> Result<(), Error> where F: Fn() -> Result<(), Error> { + let outer = || { + wasm_common::setup_logger(); + f()?; + run_loop()?; + Ok(()) + }; + + let result = outer(); + + match result { + Ok(()) => Ok(()), + Err(e) => { + error!("Error running pulumi wasm: [{e}]"); + Err(e) + } + } +} + +pub fn init() { + wasm_common::setup_logger(); +} + +pub fn close() -> Result<(), Error> { + run_loop() +} + +fn run_loop() -> Result<(), Error> { + loop { + if !run_all_function()? && !combine_outputs() { + return Ok(()); + } + } +} + +fn run_all_function( + // store: &mut Store, + // plugin: &PulumiWasm, +) -> Result { + let functions = get_functions("source"); + + if functions.is_empty() { + info!("Functions are empty"); + return Ok(false) + } + + info!("Functions are not empty"); + + let functions_map = HASHMAP.lock().unwrap(); + + let mapped: Result, _> = functions + .iter() + .map( + |FunctionInvocationRequest { + id, + function_id, + value, + }| { + info!("Invoking function [{function_id}] with value [{value:?}]"); + let v = rmpv::decode::read_value(&mut value.clone().as_slice())?; + info!("Invoking function [{function_id}] with value [{v:?}]"); + let f = functions_map.get(function_id).context(format!("Function with id {function_id} not found"))?; + Ok(FunctionInvocationResult { + id, + value: f(value.to_vec())?, + }) + }, + ) + .collect(); + + // mapped + + let mapped = match mapped { + Ok(mapped) => mapped, + Err(e) => { + error!("Failed to invoke functions due to [{e}]"); + return Err(e); + } + }; + + info!("Setting functions"); + set_functions(&mapped); + info!("run_all_function completed"); + + Ok(true) +} + pub mod output; diff --git a/pulumi_wasm_rust_macro/Cargo.toml b/pulumi_wasm_rust_macro/Cargo.toml new file mode 100644 index 000000000..d11420066 --- /dev/null +++ b/pulumi_wasm_rust_macro/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "pulumi_wasm_rust_macro" +version.workspace = true +edition.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +proc-macro = true + +[dependencies] +syn.workspace = true +quote.workspace = true +proc-macro2.workspace = true \ No newline at end of file diff --git a/pulumi_wasm_rust_macro/src/lib.rs b/pulumi_wasm_rust_macro/src/lib.rs new file mode 100644 index 000000000..89eb696e1 --- /dev/null +++ b/pulumi_wasm_rust_macro/src/lib.rs @@ -0,0 +1,30 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; +use quote::quote; +use syn::{parse_macro_input}; + +#[proc_macro_attribute] +pub fn pulumi_main(_attr: TokenStream, item: TokenStream) -> TokenStream { + let input_fn = parse_macro_input!(item as syn::ItemFn); + + let fn_name = &input_fn.sig.ident; + let fn_block = &input_fn.block; + let fn_output = &input_fn.sig.output; + + let expanded = quote! { + + fn #fn_name() #fn_output { + #fn_block + } + + #[export_name = "component:pulumi-wasm/pulumi-main@0.1.0#main"] + unsafe extern "C" fn __exported() { + pulumi_wasm_rust::run(|| { + #fn_name() + }).unwrap(); + } + }; + + TokenStream::from(expanded) +} diff --git a/wasm_common/Cargo.toml b/wasm_common/Cargo.toml index 3b76e802e..671cdc2ac 100644 --- a/wasm_common/Cargo.toml +++ b/wasm_common/Cargo.toml @@ -1,18 +1,11 @@ [package] name = "wasm_common" -version = "0.1.0" -edition = "2021" +version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] log.workspace = true uuid.workspace = true -wit-bindgen-rt.workspace = true - -[package.metadata.component] -package = "component:logger" - -[package.metadata.component.target] -path = "../wits/world.wit" -world = "logger" +wit-bindgen.workspace = true diff --git a/wasm_common/src/bindings.rs b/wasm_common/src/bindings.rs deleted file mode 100644 index 790982488..000000000 --- a/wasm_common/src/bindings.rs +++ /dev/null @@ -1,313 +0,0 @@ -// Generated by `wit-bindgen` 0.20.0. DO NOT EDIT! -// Options used: -pub mod component { - pub mod pulumi_wasm { - - #[allow(clippy::all)] - pub mod log { - #[used] - #[doc(hidden)] - #[cfg(target_arch = "wasm32")] - static __FORCE_SECTION_REF: fn() = - super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - #[repr(u8)] - #[derive(Clone, Copy, Eq, PartialEq)] - pub enum Level { - Trace, - Debug, - Info, - Warn, - Error, - } - impl ::core::fmt::Debug for Level { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - match self { - Level::Trace => f.debug_tuple("Level::Trace").finish(), - Level::Debug => f.debug_tuple("Level::Debug").finish(), - Level::Info => f.debug_tuple("Level::Info").finish(), - Level::Warn => f.debug_tuple("Level::Warn").finish(), - Level::Error => f.debug_tuple("Level::Error").finish(), - } - } - } - - impl Level { - pub(crate) unsafe fn _lift(val: u8) -> Level { - if !cfg!(debug_assertions) { - return ::core::mem::transmute(val); - } - - match val { - 0 => Level::Trace, - 1 => Level::Debug, - 2 => Level::Info, - 3 => Level::Warn, - 4 => Level::Error, - - _ => panic!("invalid enum discriminant"), - } - } - } - - #[derive(Clone)] - pub struct Content { - pub level: Level, - pub target: _rt::String, - pub args: _rt::String, - pub module_path: Option<_rt::String>, - pub file: Option<_rt::String>, - pub line: Option, - pub key_values: _rt::Vec<(_rt::String, _rt::String)>, - } - impl ::core::fmt::Debug for Content { - fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { - f.debug_struct("Content") - .field("level", &self.level) - .field("target", &self.target) - .field("args", &self.args) - .field("module-path", &self.module_path) - .field("file", &self.file) - .field("line", &self.line) - .field("key-values", &self.key_values) - .finish() - } - } - #[allow(unused_unsafe, clippy::all)] - pub fn log(content: &Content) { - unsafe { - let Content { - level: level0, - target: target0, - args: args0, - module_path: module_path0, - file: file0, - line: line0, - key_values: key_values0, - } = content; - let vec1 = target0; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - let vec2 = args0; - let ptr2 = vec2.as_ptr().cast::(); - let len2 = vec2.len(); - let (result4_0, result4_1, result4_2) = match module_path0 { - Some(e) => { - let vec3 = e; - let ptr3 = vec3.as_ptr().cast::(); - let len3 = vec3.len(); - - (1i32, ptr3.cast_mut(), len3) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result6_0, result6_1, result6_2) = match file0 { - Some(e) => { - let vec5 = e; - let ptr5 = vec5.as_ptr().cast::(); - let len5 = vec5.len(); - - (1i32, ptr5.cast_mut(), len5) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result7_0, result7_1) = match line0 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - let vec11 = key_values0; - let len11 = vec11.len(); - let layout11 = - _rt::alloc::Layout::from_size_align_unchecked(vec11.len() * 16, 4); - let result11 = if layout11.size() != 0 { - let ptr = _rt::alloc::alloc(layout11).cast::(); - if ptr.is_null() { - _rt::alloc::handle_alloc_error(layout11); - } - ptr - } else { - { - ::core::ptr::null_mut() - } - }; - for (i, e) in vec11.into_iter().enumerate() { - let base = result11.add(i * 16); - { - let (t8_0, t8_1) = e; - let vec9 = t8_0; - let ptr9 = vec9.as_ptr().cast::(); - let len9 = vec9.len(); - *base.add(4).cast::() = len9; - *base.add(0).cast::<*mut u8>() = ptr9.cast_mut(); - let vec10 = t8_1; - let ptr10 = vec10.as_ptr().cast::(); - let len10 = vec10.len(); - *base.add(12).cast::() = len10; - *base.add(8).cast::<*mut u8>() = ptr10.cast_mut(); - } - } - - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "component:pulumi-wasm/log@0.1.0")] - extern "C" { - #[link_name = "log"] - fn wit_import( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: i32, - _: *mut u8, - _: usize, - ); - } - - #[cfg(not(target_arch = "wasm32"))] - fn wit_import( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: *mut u8, - _: usize, - _: i32, - _: i32, - _: *mut u8, - _: usize, - ) { - unreachable!() - } - wit_import( - level0.clone() as i32, - ptr1.cast_mut(), - len1, - ptr2.cast_mut(), - len2, - result4_0, - result4_1, - result4_2, - result6_0, - result6_1, - result6_2, - result7_0, - result7_1, - result11, - len11, - ); - if layout11.size() != 0 { - _rt::alloc::dealloc(result11.cast(), layout11); - } - } - } - } - } -} -mod _rt { - pub use alloc_crate::string::String; - pub use alloc_crate::vec::Vec; - - pub fn as_i32(t: T) -> i32 { - t.as_i32() - } - - pub trait AsI32 { - fn as_i32(self) -> i32; - } - - impl<'a, T: Copy + AsI32> AsI32 for &'a T { - fn as_i32(self) -> i32 { - (*self).as_i32() - } - } - - impl AsI32 for i32 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for u32 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for i16 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for u16 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for i8 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for u8 { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for char { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - - impl AsI32 for usize { - #[inline] - fn as_i32(self) -> i32 { - self as i32 - } - } - pub use alloc_crate::alloc; - extern crate alloc as alloc_crate; -} - -#[cfg(target_arch = "wasm32")] -#[link_section = "component-type:wit-bindgen:0.20.0:logger:encoded world"] -#[doc(hidden)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 361] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xec\x01\x01A\x02\x01\ -A\x02\x01B\x0a\x01m\x05\x05TRACE\x05DEBUG\x04INFO\x04WARN\x05ERROR\x04\0\x05leve\ -l\x03\0\0\x01ks\x01ky\x01o\x02ss\x01p\x04\x01r\x07\x05level\x01\x06targets\x04ar\ -gss\x0bmodule-path\x02\x04file\x02\x04line\x03\x0akey-values\x05\x04\0\x07conten\ -t\x03\0\x06\x01@\x01\x07content\x07\x01\0\x04\0\x03log\x01\x08\x03\x01\x1fcompon\ -ent:pulumi-wasm/log@0.1.0\x05\0\x04\x01\"component:pulumi-wasm/logger@0.1.0\x04\0\ -\x0b\x0c\x01\0\x06logger\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-\ -component\x070.201.0\x10wit-bindgen-rust\x060.20.0"; - -#[inline(never)] -#[doc(hidden)] -#[cfg(target_arch = "wasm32")] -pub fn __link_custom_section_describing_imports() { - wit_bindgen_rt::maybe_link_cabi_realloc(); -} diff --git a/wasm_common/src/lib.rs b/wasm_common/src/lib.rs index 351909a8a..a46b3688d 100644 --- a/wasm_common/src/lib.rs +++ b/wasm_common/src/lib.rs @@ -7,7 +7,16 @@ use crate::logger::Logger; #[allow(dead_code)] #[allow(unused_variables)] #[allow(unused_unsafe)] -mod bindings; +mod bindings { + wit_bindgen::generate!({ + // the name of the world in the `*.wit` input file + world: "logger", + path: "../wits/world.wit" + }); +} + +pub use bindings::*; + mod logger; static IS_SET : AtomicBool = AtomicBool::new(false); diff --git a/wits/world.wit b/wits/world.wit index f74c81124..0dd7e4a42 100644 --- a/wits/world.wit +++ b/wits/world.wit @@ -4,22 +4,34 @@ world pulumi-wasm { export output-interface; export register-interface; export function-reverse-callback; - import log; + import log; import external-world; } +world pulumi-rust { + export register-interface; + export function-reverse-callback; + import output-interface; +} + world main { export pulumi-main; import external-world; import log; } -world new-main { - import pulumi-provider-random-interface; +world pulumi-wasm-rust { import output-interface; import function-reverse-callback; - import log; + export pulumi-main; // Used by macro +} + +world new-main { + export pulumi-main; +} + +world pulumi-main-world { export pulumi-main; } @@ -30,12 +42,18 @@ world pulumi-provider-random { export pulumi-provider-random-interface; } +world pulumi-provider-random-client { + import output-interface; + import register-interface; + import pulumi-provider-random-interface; +} + world logger { import log; } -world pulumi-rust { - import output-interface; +world pulumi-rust-macro { + import external-world; } interface log {