The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
ci(rust): split rust jobs, use nextest and Swatinem/rust-cache
Yujong Leeb70ddc2fd8ce
diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.ymlindex c4847aca20d..00c6fed8ae3 100644--- a/.github/workflows/test-rust.yml+++ b/.github/workflows/test-rust.yml@@ -68,9 +68,9 @@ env:CARGO_TERM_COLOR: alwaysjobs:- rust-lint:+ rust-fmt:runs-on: ubuntu-latest- timeout-minutes: 10+ timeout-minutes: 5defaults:run:working-directory: litellm-rust@@ -81,24 +81,67 @@ jobs:- run: rustup toolchain install --no-self-update- - run: cargo fmt --check+ - run: cargo fmt --all --check- - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0+ rust-clippy:+ runs-on: ubuntu-latest+ timeout-minutes: 15+ defaults:+ run:+ working-directory: litellm-rust+ steps:+ - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0+ with:+ persist-credentials: false++ - run: rustup toolchain install --no-self-update++ - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2with:- path: |- ~/.cargo/registry- ~/.cargo/git- litellm-rust/target- key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('rust-toolchain.toml', '.cargo/**', 'litellm-rust/Cargo.lock') }}- restore-keys: |- ${{ runner.os }}-cargo-${{ github.job }}-+ workspaces: litellm-rust+ cache-on-failure: true- run: cargo clippy --workspace --all-targets --locked -- -D warningsrust-test:runs-on: ubuntu-latest- timeout-minutes: 30+ timeout-minutes: 20+ defaults:+ run:+ working-directory: litellm-rust+ steps:+ - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0+ with:+ persist-credentials: false++ - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0+ with:+ python-version: "3.12"++ - run: rustup toolchain install --no-self-update++ - name: Install cargo-nextest 0.9.143+ working-directory: ${{ runner.temp }}+ run: |+ curl -fsSL --retry 3 -o cargo-nextest.tar.gz \+ https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-0.9.143/cargo-nextest-0.9.143-x86_64-unknown-linux-gnu.tar.gz+ echo "66786b9abe23920d022a182d1416b1bbc8130dd4872a9553d76985a1708dcd1e cargo-nextest.tar.gz" | sha256sum -c -+ mkdir -p bin+ tar xzf cargo-nextest.tar.gz -C bin cargo-nextest+ echo "$PWD/bin" >> "$GITHUB_PATH"++ - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2+ with:+ workspaces: litellm-rust+ cache-on-failure: true++ - run: cargo nextest run --workspace --locked+ - run: cargo test --workspace --doc --locked++ rust-wheel:+ runs-on: ubuntu-latest+ timeout-minutes: 30steps:- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0with:@@ -114,18 +157,10 @@ jobs:- run: rustup toolchain install --no-self-update- - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0+ - uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2with:- path: |- ~/.cargo/registry- ~/.cargo/git- litellm-rust/target- key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('rust-toolchain.toml', '.cargo/**', 'litellm-rust/Cargo.lock') }}- restore-keys: |- ${{ runner.os }}-cargo-${{ github.job }}--- - run: cargo test --workspace --locked- working-directory: litellm-rust+ workspaces: litellm-rust+ cache-on-failure: true- run: uv build --wheel --out-dir distdiff --git a/litellm-rust/crates/python-bridge/src/lifecycle/mod.rs b/litellm-rust/crates/python-bridge/src/lifecycle/mod.rsindex cf9f31c3c13..c4b8d8eaae0 100644--- a/litellm-rust/crates/python-bridge/src/lifecycle/mod.rs+++ b/litellm-rust/crates/python-bridge/src/lifecycle/mod.rs@@ -599,6 +599,34 @@ mod tests {static PYTHON_GLOBALS: Mutex<()> = Mutex::new(());+ fn install_lifecycle_module(py: Python<'_>) -> Bound<'_, PyModule> {+ py.run(+ pyo3::ffi::c_str!(+ r#"+import sys+import types++sys.modules.setdefault('litellm', types.ModuleType('litellm'))+sys.modules.setdefault('litellm.rust_bridge', types.ModuleType('litellm.rust_bridge'))+"#+ ),+ None,+ None,+ )+ .unwrap();+ let source = std::ffi::CString::new(include_str!(+ "../../../../../litellm/rust_bridge/lifecycle.py"+ ))+ .unwrap();+ PyModule::from_code(+ py,+ &source,+ pyo3::ffi::c_str!("lifecycle.py"),+ pyo3::ffi::c_str!("litellm.rust_bridge.lifecycle"),+ )+ .unwrap()+ }+fn install_logging_worker(py: Python<'_>, worker: &Bound<'_, PyAny>) -> PyResult<()> {py.import("litellm.litellm_core_utils.logging_worker")?.setattr("GLOBAL_LOGGING_WORKER", worker)@@ -773,17 +801,7 @@ mod tests {.unwrap_or_else(|error| error.into_inner());Python::initialize();Python::attach(|py| {- let source = std::ffi::CString::new(include_str!(- "../../../../../litellm/rust_bridge/lifecycle.py"- ))- .unwrap();- PyModule::from_code(- py,- &source,- pyo3::ffi::c_str!("lifecycle.py"),- pyo3::ffi::c_str!("litellm.rust_bridge.lifecycle"),- )- .unwrap();+ install_lifecycle_module(py);let route = SyntheticRoute(PythonCallState::new(py,@@ -819,17 +837,7 @@ mod tests {Python::initialize();Python::attach(|py| {py.import("asyncio").unwrap();- let source = std::ffi::CString::new(include_str!(- "../../../../../litellm/rust_bridge/lifecycle.py"- ))- .unwrap();- let module = PyModule::from_code(- py,- &source,- pyo3::ffi::c_str!("lifecycle.py"),- pyo3::ffi::c_str!("litellm.rust_bridge.lifecycle"),- )- .unwrap();+ let module = install_lifecycle_module(py);let locals = PyDict::new(py);locals.set_item("drive", module.getattr("drive").unwrap())diff --git a/litellm-rust/crates/python-bridge/src/marshal.rs b/litellm-rust/crates/python-bridge/src/marshal.rsindex 9038eb971b3..7f00298905f 100644--- a/litellm-rust/crates/python-bridge/src/marshal.rs+++ b/litellm-rust/crates/python-bridge/src/marshal.rs@@ -190,6 +190,7 @@ mod tests {#[test]fn required_shapes_preserve_nested_values_and_existing_errors() {+ Python::initialize();let nested = json!([{"role": "user", "content": [{"type": "text", "text": "hi"}]}]);assert_eq!(Value::Array(required_array("messages", nested.clone()).unwrap()),