Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ serde_json.workspace = true
members = [
"axum",
"axum/macro",
"azure",
"macro",
"test-programs",
]
Expand All @@ -70,7 +71,10 @@ authors = [
[workspace.dependencies]
anyhow = "1"
async-task = "4.7"
async-trait = "0.1"
axum = { version = "0.8.6", default-features = false }
azure_core = { version = "0.29", default-features = false }
azure_storage_blob = { version = "0.6", default-features = false }
bytes = "1.10.1"
cargo_metadata = "0.22"
clap = { version = "4.5.26", features = ["derive"] }
Expand All @@ -93,11 +97,13 @@ syn = "2.0"
test-log = { version = "0.2", features = ["trace"] }
test-programs = { path = "test-programs" }
tower-service = "0.3.3"
typespec_client_core = { version = "0.8", default-features = false, features = ["http", "json"] }
ureq = { version = "3.1", default-features = false, features = ["json"] }
wasip2 = "1.0"
wstd = { path = ".", version = "=0.6.1" }
wstd-axum = { path = "./axum", version = "=0.6.1" }
wstd-axum-macro = { path = "./axum/macro", version = "=0.6.1" }
wstd-azure = { path = "./azure", version = "=0.6.1" }
wstd-macro = { path = "./macro", version = "=0.6.1" }

[package.metadata.docs.rs]
Expand Down
24 changes: 24 additions & 0 deletions azure/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "wstd-azure"
description = "wstd support for the Azure Rust SDK"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
keywords.workspace = true
categories.workspace = true
rust-version.workspace = true
authors.workspace = true

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
bytes.workspace = true
http.workspace = true
typespec_client_core = { workspace = true }
wstd.workspace = true

[dev-dependencies]
azure_core.workspace = true
azure_storage_blob.workspace = true
clap.workspace = true
68 changes: 68 additions & 0 deletions azure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# wstd-azure: wstd support for the Azure Rust SDK

This crate provides support for using the Azure Rust SDK for the `wasm32-wasip2`
target using the [`wstd`] crate.

In many wasi settings, it's necessary or desirable to use the wasi-http
interface to make http requests. Wasi-http interfaces provide an http
implementation, including the sockets layer and TLS, outside of the user's
component. `wstd` provides user-friendly async Rust interfaces to all of the
standardized wasi interfaces, including wasi-http.

The Azure Rust SDK, by default, depends on `tokio` and `reqwest`, and makes
http requests over sockets (which can be provided as wasi-sockets). Those
dependencies may not work correctly under `wasm32-wasip2`, and if they do,
they will not use the wasi-http interfaces. To avoid using http over sockets,
make sure to set the `default-features = false` setting when depending on any
`azure_*` crates in your project.

## Usage

To configure `wstd`'s async runtime for the Azure Rust SDK, call
`wstd_azure::set_wstd_runtime()` once at the start of your application.
You'll also need to provide the HTTP client when creating Azure SDK service clients:

```rust
use wstd_azure::{set_wstd_runtime, http_client};

#[wstd::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Set up wstd async runtime for Azure SDK
set_wstd_runtime()?;

// Get the HTTP client to use with Azure SDK clients
let client = http_client();

// Example: Create an Azure service client with the wstd HTTP client
// let blob_client = BlobServiceClient::new(...)
// .with_http_client(client);

Ok(())
}
```

Alternatively, you can get the runtime and HTTP client separately if you need
more control:

```rust
use wstd_azure::{async_runtime, http_client};

// Get the async runtime
let runtime = async_runtime();

// Get the HTTP client
let client = http_client();
```

## Example

An example Azure Blob Storage client is provided. See the `examples` directory
for a complete working example.

## Requirements

- Rust 1.89 or later
- `wasm32-wasip2` target installed
- `wasmtime` or another WASI runtime with wasi-http support

[`wstd`]: https://docs.rs/wstd/latest/wstd
50 changes: 50 additions & 0 deletions azure/examples/blob_storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Example Azure Blob Storage client running on `wstd` via `wstd_azure`
//!
//! This example demonstrates how to set up the wstd runtime for use with the
//! Azure Rust SDK. The actual Azure SDK client code will depend on which
//! version of the azure_storage_blob crate you are using.
//!
//! This example *must be compiled in release mode* - in debug mode, the azure
//! sdk's generated code will overflow the maximum permitted wasm locals in
//! a single function.
//!
//! Compile it with:
//!
//! ```sh
//! cargo build -p wstd-azure --target wasm32-wasip2 --release --examples
//! ```
//!
//! When running this example, you will need Azure credentials provided in environment
//! variables.
//!
//! Run it with:
//! ```sh
//! wasmtime run -Shttp \
//! --env AZURE_STORAGE_ACCOUNT_NAME \
//! --env AZURE_STORAGE_ACCESS_KEY \
//! --dir .::. \
//! target/wasm32-wasip2/release/examples/blob_storage.wasm
//! ```

use anyhow::Result;

#[wstd::main]
async fn main() -> Result<()> {
// Set up wstd runtime for Azure SDK
// This configures the Azure SDK to use wstd's async runtime and HTTP client
wstd_azure::set_wstd_runtime()?;

println!("wstd runtime configured for Azure SDK");
println!("");
println!("To use the Azure SDK:");
println!("1. Import the Azure SDK crates you need (e.g., azure_storage_blob)");
println!("2. Make sure to use default-features = false for Azure crates");
println!("3. Create your Azure SDK clients as normal");
println!("4. The SDK will use wstd's wasi-http implementation automatically");

// Example placeholder - actual Azure SDK usage will depend on your version
// and which services you're using. See the Azure SDK documentation at:
// https://github.com/Azure/azure-sdk-for-rust

Ok(())
}
Loading