Skip to content

Commit

Permalink
Docs updates (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejressel authored Aug 15, 2024
1 parent 640be0d commit acef35e
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 139 deletions.
12 changes: 0 additions & 12 deletions docs/Internal/Data passing.md

This file was deleted.

26 changes: 15 additions & 11 deletions docs/Internal/Output.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@

## Types of Output

Pulumi WASM has 4 types of outputs:
Pulumi WASM has 5 types of outputs (represented as `EngineNode` in `engine.rs`):
1. Done
2. Mapped
3. Func
4. Unknown
2. NativeFunction
3. RegisterResource
4. ExtractField
5. CombineOutputs

### Done

This is output for which value is known. Internally it's represented as MessagePack's `Value`.
This is output for which value is known. Internally it's represented as JSON's `Value`.

### Mapped
### NativeFunction

This is output which wait to be mapped by host. More details are in [Mapping](#Mapping) section. Internally it's represented as tuple of function name and output which will values will be it's argument.

### Func
### RegisterResource

This is output that is a function. As opposed to `Mapped` this function in executed internally in Pulumi WASM. Currently these are
functions that creates resources. Internally it's tuple of list of outputs and function that handles their values.
Output that will eventually be sent to Pulumi as register resource instruction. This is internal to pulumi-wasm and is not exposed to user

### Unknown
### ExtractField

This is output for which value will never be known. This is used in Pulumi's preview stage.
Step 2 of RegisterResource. This output will take response of register resource and extract one field.

### CombineOutputs

Output that combines N outputs and returns array (in user facing code it should be a tuple)

## Mapping

Expand Down
2 changes: 1 addition & 1 deletion docs/Internal/Serialization formats.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Protobuf - used by Pulumi
- MessagePack - used in internal communication
- JSON - used in internal communication
11 changes: 11 additions & 0 deletions docs/Internal/Supporting new language.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Checklist for new language

New language should have the following features:

- `component:pulumi-wasm/pulumi-main.main` [Entrypoint](WIT.md#pulumi-main)
- Abstration over `Output<T>` (mapping, combining)
- Function map loop described in [Output](Output.md/#mapping)
- Generating glue code for providers

`pulumi_wasm_rust` and `pulumi_wasm_macro` should be used as an example - combined they have about 100 LOC and they
only create abstration over WASM calls.
47 changes: 47 additions & 0 deletions docs/Internal/WIT.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# WIT

``` title="world.wit"
--8<-- "pulumi_wasm_wit/wit/world.wit"
```

## Interfaces

### Output

Allow working with Outputs (so maybe not yet set values managed by Pulumi). Interface allows creating, mapping and cloning (to be removed in the future).
It also allows to combine list of outputs into output of list

### Stack

(Name to be changed). Currently, this interface allows adding output as export ([Pulumi docs](https://www.pulumi.com/tutorials/building-with-pulumi/stack-outputs/)).
And invoking `finish` function - explained in [Output](Output.md/#mapping).

### Pulumi main

Entrypoint to program that will be invoked by `pulumi-wasm-runner`.
In Rust case it is created by `pulumi_wasm` macro.

### Log

Allows logging from within provider (used mostly for main pulumi-wasm component)

### Register

Interface that allows registering of Pulumi resources. Used only by providers.

### External world

Interface used as a substitute until WASM gets proper GRPC client support.
It is used by main `pulumi-wasm` component binary and is implemented by `pulumi-wasm-runner`.

## Worlds

### client world

World used by client languages. Imports output and stack interfaces and exports pulumi-main interface.

### pulumi-wasm world

World used by main pulumi-wasm component. A

### logger world

World that only contains `log` interface.
26 changes: 3 additions & 23 deletions docs/crates.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

### Pulumi WASM

Main WASM component. Currently implements Output handling, send and handles requests to Pulumi.
Main WASM component. Currently, implements Output handling, send and handles requests to Pulumi.

### Pulumi WASM runner

x64 application that runs the WASM component.
Implements `component:[email protected]/external-world` and `component:[email protected]/log` interfaces.
x64 application that combines and executes Pulumi WASM components.

### Pulumi WASM Rust

Expand All @@ -18,25 +17,6 @@ Also provides `pulumi_main` macro via `pub use` from `Pulumi WASM Rust Macro`.

Rust library with `pulumi_main` macro. Addon to `Pulumi WASM Rust`

### WASM Common
### Pulumi WASM Common

Library used in WASM components of Pulumi providers. Currently provides logging facilities.

### Pulumi WASM Provider Random

WASM component for Pulumi's Random provider. Currently handwritten -
after [#5](https://github.com/andrzejressel/pulumi-wasm/issues/5) generated.

### Pulumi WASM Provider Random Rust

Rust library that provides a high-level and typesafe API for `Pulumi WASM Provider Random` WASM component.
Currently handwritten - after [#5](https://github.com/andrzejressel/pulumi-wasm/issues/5) generated.

### cargo pulumi

Cargo subcommands that compile and combine Pulumi WASM components into a single WASM file.

### examples/simple

Currently the only example. It's a simple Pulumi program that uses `Pulumi WASM Provider Random Rust` to generate random numbers.
In future will be one of integration tests.
3 changes: 2 additions & 1 deletion examples/dependencies/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ local-test:
$PSNativeCommandUseErrorActionPreference = $true

cargo build -p pulumi_wasm_runner
cargo component build -p pulumi_wasm_example_multiple_providers -p pulumi_wasm_random_provider
cargo component build -p pulumi_wasm_example_multiple_providers
cargo component build -p pulumi_wasm_random_provider
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
3 changes: 2 additions & 1 deletion examples/docker/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ local-test:
$PSNativeCommandUseErrorActionPreference = $true

cargo build -p pulumi_wasm_runner
cargo component build -p pulumi_wasm_example_multiple_providers -p pulumi_wasm_random_provider
cargo component build -p pulumi_wasm_example_multiple_providers
cargo component build -p pulumi_wasm_random_provider
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
4 changes: 3 additions & 1 deletion examples/multiple_providers/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ local-test:
$PSNativeCommandUseErrorActionPreference = $true

cargo build -p pulumi_wasm_runner
cargo component build -p pulumi_wasm_example_multiple_providers -p pulumi_wasm_docker_provider -p pulumi_wasm_random_provider
cargo component build -p pulumi_wasm_example_multiple_providers
cargo component build -p pulumi_wasm_docker_provider
cargo component build -p pulumi_wasm_random_provider
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
3 changes: 2 additions & 1 deletion examples/simple/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ local-test:
$PSNativeCommandUseErrorActionPreference = $true

cargo build -p pulumi_wasm_runner
cargo component build -p pulumi_wasm_example_multiple_providers -p pulumi_wasm_random_provider
cargo component build -p pulumi_wasm_example_multiple_providers
cargo component build -p pulumi_wasm_random_provider
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ nav:
- crates.md
- rustdoc: "/pulumi-wasm/rust-docs/pulumi_wasm_rust/index.html"
- Internal:
- Internal/Data passing.md
- Internal/Output.md
- Internal/Serialization formats.md
- Internal/WIT.md
- Internal/Supporting new language.md


extra:
Expand All @@ -40,3 +40,4 @@ markdown_extensions:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format
- pymdownx.snippets
2 changes: 1 addition & 1 deletion pulumi_wasm_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ log4rs.workspace = true
clap.workspace = true
wac-graph.workspace = true
pulumi_wasm_proto = { workspace = true, features = ["connectivity"] }
pulumi_wasm_wit = { workspace = true, features = ["server"] }
pulumi_wasm_wit = { workspace = true, features = ["runner"] }
directories.workspace = true
reqwest.workspace = true
4 changes: 4 additions & 0 deletions pulumi_wasm_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ async fn main() -> Result<(), Error> {
} => {
let providers: HashMap<String, &PathBuf> =
providers.iter().map(|(k, v)| (k.clone(), v)).collect();
log::info!("Creating final component");
let component =
create_final_component::create(&providers, pulumi_wasm, program).await?;
log::info!("Created final component");
let wasm = component;

let pulumi_engine_url = std::env::var("PULUMI_ENGINE")?;
Expand All @@ -102,7 +104,9 @@ async fn main() -> Result<(), Error> {
pulumi_project,
)
.await?;
log::info!("Creating root stack");
pulumi.create_root_stack().await?;
log::info!("Created root stack. Invoking main");
pulumi.start().await?;
}
}
Expand Down
35 changes: 19 additions & 16 deletions pulumi_wasm_runner/src/pulumi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use crate::grpc::{
GetRootResourceRequest, RegisterResourceOutputsRequest, RegisterResourceRequest,
RegisterResourceResponse, SetRootResourceRequest,
};
use crate::pulumi::server::component::pulumi_wasm::external_world;
use crate::pulumi::server::component::pulumi_wasm::external_world::Host;
use crate::pulumi::server::component::pulumi_wasm::external_world::RegisteredResource;
use crate::pulumi::server::Main;
use crate::pulumi::runner::component::pulumi_wasm::external_world;
use crate::pulumi::runner::component::pulumi_wasm::external_world::Host;
use crate::pulumi::runner::component::pulumi_wasm::external_world::RegisteredResource;
use crate::pulumi::runner::Runner;
use crate::pulumi_state::PulumiState;
use pulumi_wasm_wit::bindings_server as server;
use pulumi_wasm_wit::bindings_runner as runner;

pub struct Pulumi {
plugin: Main,
plugin: Runner,
store: Store<SimplePluginCtx>,
}

Expand Down Expand Up @@ -79,21 +79,21 @@ impl Host for MyState {
}

#[async_trait]
impl server::component::pulumi_wasm::log::Host for MyState {
impl runner::component::pulumi_wasm::log::Host for MyState {
async fn log(
&mut self,
content: server::component::pulumi_wasm::log::Content,
content: runner::component::pulumi_wasm::log::Content,
) -> wasmtime::Result<()> {
log::logger().log(
&log::Record::builder()
.metadata(
log::Metadata::builder()
.level(match content.level {
server::component::pulumi_wasm::log::Level::Trace => log::Level::Trace,
server::component::pulumi_wasm::log::Level::Debug => log::Level::Debug,
server::component::pulumi_wasm::log::Level::Info => log::Level::Info,
server::component::pulumi_wasm::log::Level::Error => log::Level::Error,
server::component::pulumi_wasm::log::Level::Warn => log::Level::Warn,
runner::component::pulumi_wasm::log::Level::Trace => log::Level::Trace,
runner::component::pulumi_wasm::log::Level::Debug => log::Level::Debug,
runner::component::pulumi_wasm::log::Level::Info => log::Level::Info,
runner::component::pulumi_wasm::log::Level::Error => log::Level::Error,
runner::component::pulumi_wasm::log::Level::Warn => log::Level::Warn,
})
.target(&content.target)
.build(),
Expand Down Expand Up @@ -196,7 +196,7 @@ impl Pulumi {
let engine = wasmtime::Engine::new(&engine_config)?;

let mut linker: Linker<SimplePluginCtx> = Linker::new(&engine);
Main::add_to_linker(&mut linker, |state: &mut SimplePluginCtx| {
Runner::add_to_linker(&mut linker, |state: &mut SimplePluginCtx| {
&mut state.my_state
})?;

Expand Down Expand Up @@ -225,8 +225,11 @@ impl Pulumi {
},
);

info!("Creating WASM component");
let component = Component::from_binary(&engine, &pulumi_wasm_file)?;
let plugin = Main::instantiate_async(&mut store, &component, &linker).await?;
info!("Instantiating WASM component");
let plugin = Runner::instantiate_async(&mut store, &component, &linker).await?;
info!("WASM component instantiated");

Ok(Pulumi { plugin, store })
}
Expand All @@ -241,7 +244,7 @@ impl Pulumi {
let engine = wasmtime::Engine::new(&engine_config).unwrap();

let mut linker: Linker<SimplePluginCtx> = Linker::new(&engine);
Main::add_to_linker(&mut linker, |state: &mut SimplePluginCtx| {
Runner::add_to_linker(&mut linker, |state: &mut SimplePluginCtx| {
&mut state.my_state
})?;

Expand Down
2 changes: 1 addition & 1 deletion pulumi_wasm_rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ lazy_static.workspace = true
log.workspace = true
pulumi_wasm_rust_macro.workspace = true
pulumi_wasm_common.workspace = true
pulumi_wasm_wit = { workspace = true, features = ["pulumi-wasm-rust"] }
pulumi_wasm_wit = { workspace = true, features = ["client"] }
1 change: 0 additions & 1 deletion pulumi_wasm_rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub use pulumi_wasm_rust_macro::pulumi_main;
mod output;
pub use output::Output;
use pulumi_wasm_wit::bindings;

pub mod runner;

Expand Down
5 changes: 3 additions & 2 deletions pulumi_wasm_rust/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::bindings::component::pulumi_wasm::output_interface;
use anyhow::Error;
use lazy_static::lazy_static;
use log::info;
use pulumi_wasm_wit::client_bindings::component::pulumi_wasm::output_interface;
use pulumi_wasm_wit::client_bindings::component::pulumi_wasm::stack_interface::add_export;
use std::collections::HashMap;
use std::fmt::Debug;
use std::marker::PhantomData;
Expand Down Expand Up @@ -84,7 +85,7 @@ impl<T> Output<T> {
}

pub(crate) fn add_to_export(&self, name: &str) {
crate::bindings::component::pulumi_wasm::stack_interface::add_export(name, &self.future);
add_export(name, &self.future);
}
}

Expand Down
6 changes: 3 additions & 3 deletions pulumi_wasm_rust/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::bindings::component::pulumi_wasm::stack_interface::{
finish, FunctionInvocationRequest, FunctionInvocationResult,
};
use crate::output::HASHMAP;
use anyhow::{Context, Error, Result};
use log::{error, info};
use pulumi_wasm_wit::client_bindings::component::pulumi_wasm::stack_interface::{
finish, FunctionInvocationRequest, FunctionInvocationResult,
};

pub fn run<F>(f: F) -> Result<(), Error>
where
Expand Down
Loading

0 comments on commit acef35e

Please sign in to comment.