Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

build(wasi): adapt Nick DiZazzo's dependency split (#1127)

Alex Fournier37e090902a63
diff --git a/crates/libsy/Cargo.toml b/crates/libsy/Cargo.toml
index b3e65dbee..950553af3 100644
--- a/crates/libsy/Cargo.toml
+++ b/crates/libsy/Cargo.toml
@@ -34,12 +34,17 @@ regex.workspace = true
shlex = "2"
switchyard-protocol.workspace = true
thiserror.workspace = true
-tokio.workspace = true
tokio-stream = "0.1"
tracing.workspace = true
tracing-opentelemetry.workspace = true
uuid.workspace = true
+[target.'cfg(not(target_os = "wasi"))'.dependencies]
+tokio.workspace = true
+
+[target.'cfg(target_os = "wasi")'.dependencies]
+tokio = { version = "1", features = ["rt", "sync", "macros", "time"] }
+
[dev-dependencies]
# SDK + in-memory exporter to assert what the observability layer records.
opentelemetry_sdk = { version = "0.32", features = ["metrics", "testing", "trace"] }
diff --git a/crates/switchyard-ffi/Cargo.toml b/crates/switchyard-ffi/Cargo.toml
index 96e48d3b9..795eb1d78 100644
--- a/crates/switchyard-ffi/Cargo.toml
+++ b/crates/switchyard-ffi/Cargo.toml
@@ -21,5 +21,10 @@ switchyard-libsy.workspace = true
switchyard-protocol.workspace = true
switchyard-runner.workspace = true
switchyard-translation.workspace = true
-tokio.workspace = true
tokio-util = { version = "0.7", features = ["rt"] }
+
+[target.'cfg(not(target_os = "wasi"))'.dependencies]
+tokio.workspace = true
+
+[target.'cfg(target_os = "wasi")'.dependencies]
+tokio = { version = "1", features = ["rt", "sync", "macros", "time"] }
diff --git a/crates/switchyard-runner/Cargo.toml b/crates/switchyard-runner/Cargo.toml
index d55e60097..0d56841b0 100644
--- a/crates/switchyard-runner/Cargo.toml
+++ b/crates/switchyard-runner/Cargo.toml
@@ -19,16 +19,18 @@ prefill-router = ["dep:prefill-router"]
[dependencies]
libsy = { package = "switchyard-libsy", path = "../libsy", version = "0.3.0" }
prefill-router = { workspace = true, optional = true }
-reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
-switchyard-llm-client.workspace = true
switchyard-protocol.workspace = true
strum_macros.workspace = true
thiserror.workspace = true
toml = "1.1"
tracing.workspace = true
+[target.'cfg(not(target_os = "wasi"))'.dependencies]
+reqwest.workspace = true
+switchyard-llm-client.workspace = true
+
[dev-dependencies]
async-trait.workspace = true
futures-util.workspace = true
diff --git a/crates/switchyard-runner/src/algorithm.rs b/crates/switchyard-runner/src/algorithm.rs
index 6ac7ca66a..b7036bed5 100644
--- a/crates/switchyard-runner/src/algorithm.rs
+++ b/crates/switchyard-runner/src/algorithm.rs
@@ -755,6 +755,7 @@ impl StageClassifierConfig {
}
impl AlgorithmSpec {
+ #[cfg(not(target_os = "wasi"))]
pub(crate) fn decision_judge(&self) -> Option<(&str, &DecisionJudgeRouteConfig)> {
match self {
Self::LlmClassifier { config, .. } => config
@@ -1031,6 +1032,7 @@ impl AlgorithmSpec {
}
/// Response target and routing-only dependency for routers that answer while routing.
+ #[cfg(not(target_os = "wasi"))]
pub(crate) fn routing_response_and_dependency(&self) -> Option<(&str, &str)> {
match self {
Self::LlmClassifier { config, .. }
diff --git a/crates/switchyard-runner/src/lib.rs b/crates/switchyard-runner/src/lib.rs
index 0065333a7..90219e71b 100644
--- a/crates/switchyard-runner/src/lib.rs
+++ b/crates/switchyard-runner/src/lib.rs
@@ -2,14 +2,21 @@
// SPDX-License-Identifier: Apache-2.0
//! Shared configured routing for Switchyard serving surfaces.
+//!
+//! WASI builds omit HTTP-backed route execution.
mod algorithm;
+#[cfg(not(target_os = "wasi"))]
mod config;
+#[cfg(not(target_os = "wasi"))]
mod failure;
mod provider_key_redactor;
+#[cfg(not(target_os = "wasi"))]
mod route;
+#[cfg(not(target_os = "wasi"))]
mod runner;
+#[cfg(not(target_os = "wasi"))]
pub use config::{ConfiguredTarget, RouteTargets, TargetModel, api_key_variables, route_targets};
pub use algorithm::{
@@ -17,11 +24,14 @@ pub use algorithm::{
ClassifierPolicyConfig, DecisionJudgeRouteConfig, LlmClassifierRouteConfig,
StageClassifierConfig, SubagentRouteConfig, VgrModeConfig, VgrRouteConfig,
};
+#[cfg(not(target_os = "wasi"))]
pub use failure::{RouteErrorKind, RouteErrorPhase, RouteErrorSummary, stream_error_summary};
// Re-exported because `Route::new` takes it, so a host wiring routes does not need a libsy dep.
pub use libsy::{RoutingOutcome, RuntimeModels};
pub use provider_key_redactor::ProviderKeyRedactor;
+#[cfg(not(target_os = "wasi"))]
pub use route::{
AuxiliaryTarget, CallerAuthKind, ModelCapabilities, Route, RunOutput, RunnerError,
};
+#[cfg(not(target_os = "wasi"))]
pub use runner::{DecisionDescription, DecisionTarget, ModelInfo, Runner};