diff --git a/.dockerignore b/.dockerignore index f3a80fee3e4..e00bd2dd304 100644 --- a/.dockerignore +++ b/.dockerignore @@ -51,7 +51,7 @@ build/ **/node_modules ui/litellm-dashboard/.next ui/litellm-dashboard/out -litellm-rust/target/ +target/ litellm/rust_bridge/_native*.so *.log .env diff --git a/.github/actions/cache-cargo-build/action.yml b/.github/actions/cache-cargo-build/action.yml index c3b8ce22c68..cd32954e228 100644 --- a/.github/actions/cache-cargo-build/action.yml +++ b/.github/actions/cache-cargo-build/action.yml @@ -24,7 +24,7 @@ runs: path: | ~/.cargo/registry ~/.cargo/git - litellm-rust/target - key: ${{ runner.os }}-maturin-dev-${{ hashFiles('litellm-rust/Cargo.lock') }} + target + key: ${{ runner.os }}-maturin-dev-${{ hashFiles('Cargo.lock') }} restore-keys: | ${{ runner.os }}-maturin-dev- diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index 17b6481a2bf..954f0067879 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -21,6 +21,9 @@ on: - "pyproject.toml" - "uv.lock" - "rust-toolchain.toml" + - "rustfmt.toml" + - "Cargo.toml" + - "Cargo.lock" - ".github/actions/setup-uv-with-retries/**" - ".github/scripts/smoke_test_native_wheel.py" - ".github/scripts/verify_linux_native_wheel.py" @@ -51,6 +54,9 @@ on: - "pyproject.toml" - "uv.lock" - "rust-toolchain.toml" + - "rustfmt.toml" + - "Cargo.toml" + - "Cargo.lock" - ".github/actions/setup-uv-with-retries/**" - ".github/scripts/smoke_test_native_wheel.py" - ".github/scripts/verify_linux_native_wheel.py" @@ -88,8 +94,8 @@ jobs: path: | ~/.cargo/registry ~/.cargo/git - litellm-rust/target - key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('rust-toolchain.toml', '.cargo/**', 'litellm-rust/Cargo.lock') }} + target + key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('rust-toolchain.toml', '.cargo/**', 'Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-${{ github.job }}- @@ -123,8 +129,8 @@ jobs: path: | ~/.cargo/registry ~/.cargo/git - litellm-rust/target - key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('rust-toolchain.toml', '.cargo/**', 'litellm-rust/Cargo.lock') }} + target + key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('rust-toolchain.toml', '.cargo/**', 'Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo-${{ github.job }}- diff --git a/.gitignore b/.gitignore index 7da917ce450..0996f52c076 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ __pycache__/ # Rust bridge build artifacts (compiled, platform-specific; regenerated by maturin/cargo) litellm/rust_bridge/_native*.so litellm/rust_bridge/_native*.pyd -litellm-rust/target/ +/target/ # Python package build output dist/ diff --git a/litellm-rust/Cargo.lock b/Cargo.lock similarity index 100% rename from litellm-rust/Cargo.lock rename to Cargo.lock diff --git a/litellm-rust/Cargo.toml b/Cargo.toml similarity index 73% rename from litellm-rust/Cargo.toml rename to Cargo.toml index 5c72c86d6ef..3cec1999e7b 100644 --- a/litellm-rust/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,16 @@ [workspace] members = [ - "crates/core", - "crates/token-counter", - "crates/config", - "crates/ai-gateway", - "crates/python-interop", - "crates/python-bridge", + "litellm-rust/crates/core", + "litellm-rust/crates/token-counter", + "litellm-rust/crates/config", + "litellm-rust/crates/ai-gateway", + "litellm-rust/crates/python-interop", + "litellm-rust/crates/python-bridge", ] resolver = "2" [workspace.package] edition = "2024" -rust-version = "1.88" license = "MIT" repository = "https://github.com/BerriAI/litellm" @@ -19,11 +18,11 @@ repository = "https://github.com/BerriAI/litellm" bytes = "1" tracing = "0.1" tracing-subscriber = { version = "0.3", default-features = false, features = ["registry", "std"] } -litellm-core = { path = "crates/core" } -litellm-token-counter = { path = "crates/token-counter" } -litellm-config = { path = "crates/config" } -litellm-ai-gateway = { path = "crates/ai-gateway", default-features = false } -litellm-python-interop = { path = "crates/python-interop" } +litellm-core = { path = "litellm-rust/crates/core" } +litellm-token-counter = { path = "litellm-rust/crates/token-counter" } +litellm-config = { path = "litellm-rust/crates/config" } +litellm-ai-gateway = { path = "litellm-rust/crates/ai-gateway", default-features = false } +litellm-python-interop = { path = "litellm-rust/crates/python-interop" } axum = "0.7" pyo3 = "0.29.2" pyo3-async-runtimes = { version = "0.29.0", features = ["tokio-runtime"] } diff --git a/litellm-rust/crates/ai-gateway/Dockerfile b/litellm-rust/crates/ai-gateway/Dockerfile index 72ac25ce1d6..a5363630a2d 100644 --- a/litellm-rust/crates/ai-gateway/Dockerfile +++ b/litellm-rust/crates/ai-gateway/Dockerfile @@ -2,8 +2,7 @@ # # Build context is the **repo root** so we can install `litellm` from this repo's # source (the gateway loads its model_list via litellm.proxy.read_model_list, -# which is not in any PyPI release yet) AND build the rust workspace under -# litellm-rust/. +# which is not in any PyPI release yet) AND build the Rust workspace. # # docker build -f litellm-rust/crates/ai-gateway/Dockerfile -t litellm-ai-gateway . # @@ -21,8 +20,8 @@ ENV PYO3_PYTHON=python3.11 # rustup reads rust-toolchain.toml from any parent of the working directory, so # copying it in is what keeps every cargo call below on the repo's pinned # channel rather than on whatever the base image happens to ship. -COPY rust-toolchain.toml /build/rust-toolchain.toml -WORKDIR /build/litellm-rust +COPY rust-toolchain.toml Cargo.toml Cargo.lock /build/ +WORKDIR /build RUN apt-get update \ && apt-get install -y --no-install-recommends \ python3 python3-dev python3-pip pkg-config libssl-dev clang \ @@ -30,9 +29,9 @@ RUN apt-get update \ && cargo install cargo-chef --locked --version 0.1.77 # ---- Planner ---------------------------------------------------------------- -# Produce the dependency recipe from the rust workspace manifests + Cargo.lock. +# Produce the dependency recipe from the Rust workspace manifests + Cargo.lock. FROM chef AS planner -COPY litellm-rust/ . +COPY litellm-rust/ /build/litellm-rust/ RUN cargo chef prepare --recipe-path recipe.json # ---- Builder ---------------------------------------------------------------- @@ -45,7 +44,7 @@ RUN cargo chef cook --locked --release \ --recipe-path recipe.json # Now copy the real sources and build the gateway binary. Deps are already cooked # above, so this step only recompiles the gateway crate. -COPY litellm-rust/ . +COPY litellm-rust/ /build/litellm-rust/ RUN cargo build --locked --release -p litellm-ai-gateway --bin litellm-ai-gateway --features server,python-config # The root pyproject builds with maturin against litellm-rust/crates/python-bridge, @@ -87,7 +86,7 @@ RUN wheel="$(ls /tmp/wheels/litellm-*.whl)" \ # The compiled gateway binary (pure-Rust realtime hot path; Python is load-time # only). -COPY --from=builder /build/litellm-rust/target/release/litellm-ai-gateway /usr/local/bin/litellm-ai-gateway +COPY --from=builder /build/target/release/litellm-ai-gateway /usr/local/bin/litellm-ai-gateway # Default config.yaml. A real deploy can override this (e.g. mount a Render # secret file at the same path) — never bake secrets into the image. diff --git a/litellm-rust/crates/ai-gateway/Dockerfile.dockerignore b/litellm-rust/crates/ai-gateway/Dockerfile.dockerignore index d1386ff684d..bef8549783f 100644 --- a/litellm-rust/crates/ai-gateway/Dockerfile.dockerignore +++ b/litellm-rust/crates/ai-gateway/Dockerfile.dockerignore @@ -8,10 +8,11 @@ # # Strategy: ignore everything, then re-include only what the build needs: # - litellm/ (pip install . needs the full package + proxy reader) -# - litellm-rust/ (the rust workspace; Cargo.lock + crate sources) +# - litellm-rust/ (the Rust crate sources) # - enterprise/ (litellm/proxy/enterprise symlinks into it; maturin walks it) # - litellm-proxy-extras/ (built into a wheel alongside enterprise/ for litellm[proxy]) # - pyproject.toml / README.md / LICENSE (packaging metadata for the wheel build) +# - Cargo.toml / Cargo.lock (the Rust workspace and dependency lock) # - rust-toolchain.toml (the pinned channel every cargo call in the build uses) * @@ -21,6 +22,8 @@ !enterprise/ !litellm-proxy-extras/ !pyproject.toml +!Cargo.toml +!Cargo.lock !rust-toolchain.toml !README.md !LICENSE diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000000..f3e454b618c --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +edition = "2024" +style_edition = "2024"