From c89d692cb5fa430ddca06a9e16682977a18b55dc Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Tue, 18 Aug 2026 16:37:37 +1000 Subject: [PATCH] [Build] Propagate vLLM version to Rust binaries (#52593) Signed-off-by: Bugen Zhao Co-authored-by: Nick Hill Co-authored-by: Andreas Karatzas --- .buildkite/scripts/ci-bake-rocm.sh | 8 ++--- .buildkite/test-amd.yaml | 2 +- .buildkite/test_areas/rust_frontend.yaml | 2 +- docker/Dockerfile | 5 +++ docker/Dockerfile.cpu | 5 +++ docker/Dockerfile.rocm | 35 ++++++++++++------- docker/Dockerfile.rocm_gfx1250 | 35 ++++++++++++------- docker/Dockerfile.xpu | 5 +++ requirements/build/rust.txt | 1 + rust/Cargo.lock | 7 ++++ rust/Cargo.toml | 2 ++ rust/src/bench/Cargo.toml | 1 + rust/src/bench/src/main.rs | 2 +- rust/src/build-info/Cargo.toml | 8 +++++ rust/src/build-info/src/lib.rs | 10 ++++++ rust/src/cmd/Cargo.toml | 1 + rust/src/cmd/src/cli.rs | 3 +- rust/src/server/Cargo.toml | 1 + rust/src/server/src/routes/tests.rs | 2 +- rust/src/server/src/routes/version.rs | 2 +- setup.py | 7 +++- tests/entrypoints/openai/test_uds.py | 7 ++-- .../serve/instrumentator/test_basic.py | 7 ++-- tools/build_rust.py | 16 +++++++++ 24 files changed, 135 insertions(+), 39 deletions(-) create mode 100644 rust/src/build-info/Cargo.toml create mode 100644 rust/src/build-info/src/lib.rs diff --git a/.buildkite/scripts/ci-bake-rocm.sh b/.buildkite/scripts/ci-bake-rocm.sh index 1e14311314..e3681e214a 100644 --- a/.buildkite/scripts/ci-bake-rocm.sh +++ b/.buildkite/scripts/ci-bake-rocm.sh @@ -23,8 +23,8 @@ DEFAULT_CI_BASE_METADATA_VERSION="3" # local-source stages rather than unreachable remote-fetch alternatives. DEFAULT_ROCM_CSRC_CONTENT_FILES=".dockerignore requirements/common.txt requirements/rocm.txt pyproject.toml setup.py CMakeLists.txt cmake csrc vllm/envs.py vllm/__init__.py tools/build_rust.py" DEFAULT_ROCM_CSRC_DOCKERFILE_STAGES="base fetch_vllm_0 fetch_vllm build_vllm_dependencies rocm-triton-kernels csrc-build" -DEFAULT_ROCM_RUST_CONTENT_FILES=".dockerignore requirements/build/rust.txt rust/Cargo.lock rust/Cargo.toml rust/proto rust/src rust-toolchain.toml tools/build_rust.py tools/install_protoc.sh build_rust.sh" -DEFAULT_ROCM_RUST_DOCKERFILE_STAGES="base rust_toolchain_input_0 rust-toolchain-input rust_input_0 rust-input rust-toolchain rust-build" +DEFAULT_ROCM_RUST_CONTENT_FILES=".dockerignore .git_archival.txt pyproject.toml requirements/build/rust.txt rust/Cargo.lock rust/Cargo.toml rust/proto rust/src rust-toolchain.toml tools/build_rust.py tools/install_protoc.sh build_rust.sh" +DEFAULT_ROCM_RUST_DOCKERFILE_STAGES="base fetch_vllm_0 fetch_vllm vllm-version rust_toolchain_input_0 rust-toolchain-input rust_input_0 rust-input rust-toolchain rust-build" # Docker's 128-character tag limit minus the longest cache prefix # ("csrc-rocm-branch-" and "rust-rocm-branch-", both 17 characters). ROCM_CACHE_BRANCH_TAG_MAX_LEN=111 @@ -523,8 +523,8 @@ prepare_ci_build_context() { return 1 fi - # setuptools-scm understands Git's stable archive format, so full-source - # wheels retain their exact version without copying mutable Git history. + # setuptools-scm understands Git's stable archive format, so wheels and + # Rust artifacts retain their exact version without copying Git history. if ! is_ci_base_target; then write_ci_git_archival_metadata "${source_root}" "${context_root}" \ || return $? diff --git a/.buildkite/test-amd.yaml b/.buildkite/test-amd.yaml index e9726f73ff..41dbd629bc 100644 --- a/.buildkite/test-amd.yaml +++ b/.buildkite/test-amd.yaml @@ -2356,7 +2356,7 @@ steps: - export VLLM_USE_RUST_FRONTEND=1 - export VLLM_WORKER_MULTIPROC_METHOD=spawn - PYTHONPATH=/vllm-workspace pytest -v -s entrypoints/serve/dev/rpc/test_collective_rpc.py - - pytest -v -s entrypoints/serve/instrumentator/test_basic.py -k "not show_version and not server_load" + - pytest -v -s entrypoints/serve/instrumentator/test_basic.py -k "not server_load" - pytest -v -s entrypoints/scale_out/token_in_token_out/test_serving_tokens.py -k "not stream and not lora and not test_generate_logprobs and not stop_string_workflow" - pytest -v -s entrypoints/serve/instrumentator/test_metrics.py -k "text and not show and not run_batch and not test_metrics_counts and not test_metrics_exist" - pytest -v -s entrypoints/serve/tokenize/test_tokenization.py -k "not tokenizer_info" diff --git a/.buildkite/test_areas/rust_frontend.yaml b/.buildkite/test_areas/rust_frontend.yaml index e9e66c46c0..6486df1c00 100644 --- a/.buildkite/test_areas/rust_frontend.yaml +++ b/.buildkite/test_areas/rust_frontend.yaml @@ -58,7 +58,7 @@ steps: - export VLLM_WORKER_MULTIPROC_METHOD=spawn - PYTHONPATH=/vllm-workspace pytest -v -s entrypoints/serve/dev/rpc/test_collective_rpc.py # server_load can be flaky under the Rust frontend; keep it excluded for now. - - pytest -v -s entrypoints/serve/instrumentator/test_basic.py -k "not show_version and not server_load" + - pytest -v -s entrypoints/serve/instrumentator/test_basic.py -k "not server_load" # test_generate_logprobs expects Python-style top_logprobs truncation (dedup sampled + cap at max(k, 1)). - pytest -v -s entrypoints/scale_out/token_in_token_out/test_serving_tokens.py -k "not stream and not lora and not test_generate_logprobs and not stop_string_workflow" - pytest -v -s entrypoints/serve/instrumentator/test_metrics.py -k "text and not show and not run_batch and not test_metrics_counts and not test_metrics_exist" diff --git a/docker/Dockerfile b/docker/Dockerfile index 804a3a4bb3..b2c949d2d1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -279,11 +279,16 @@ ENV CARGO_BUILD_JOBS=4 # separate local sccache daemon while sharing the same remote cache backend. ENV SCCACHE_SERVER_PORT=4227 +# Only Rust inputs are present, so suppress the artificial dirty state caused +# by other tracked files being absent from this build stage. +ENV SETUPTOOLS_SCM_PRETEND_METADATA={dirty=false} + # Build the release artifacts. Cache cargo registry/git, but not target/, # because stale target metadata can outlive source updates across BuildKit # cache reuse. RUN --mount=type=cache,target=/root/.cargo/registry,sharing=locked \ --mount=type=cache,target=/root/.cargo/git,sharing=locked \ + --mount=type=bind,source=.git,target=.git \ --mount=type=secret,id=aws-credentials,target=/root/.aws/credentials,required=false \ if [ "$USE_SCCACHE" = "1" ]; then \ if [ -n "${SCCACHE_ENDPOINT}" ]; then export SCCACHE_ENDPOINT="${SCCACHE_ENDPOINT}"; fi; \ diff --git a/docker/Dockerfile.cpu b/docker/Dockerfile.cpu index 69abab3b77..43fab4bccb 100644 --- a/docker/Dockerfile.cpu +++ b/docker/Dockerfile.cpu @@ -166,11 +166,16 @@ COPY build_rust.sh build_rust.sh # (rustc spawns enough concurrent processes to hit RLIMIT_NOFILE otherwise). ENV CARGO_BUILD_JOBS=4 +# Only Rust inputs are present, so suppress the artificial dirty state caused +# by other tracked files being absent from this build stage. +ENV SETUPTOOLS_SCM_PRETEND_METADATA={dirty=false} + # Build the release artifacts. Cache cargo registry/git, but not target/, # because stale target metadata can outlive source updates across BuildKit # cache reuse. RUN --mount=type=cache,target=/root/.cargo/registry,sharing=locked \ --mount=type=cache,target=/root/.cargo/git,sharing=locked \ + --mount=type=bind,source=.git,target=.git \ --mount=type=secret,id=aws-credentials,target=/root/.aws/credentials,required=false \ if [ "$USE_SCCACHE" = "1" ]; then \ export RUSTC_WRAPPER=sccache; \ diff --git a/docker/Dockerfile.rocm b/docker/Dockerfile.rocm index 0487c0c916..0b02b9ec21 100644 --- a/docker/Dockerfile.rocm +++ b/docker/Dockerfile.rocm @@ -125,6 +125,18 @@ ONBUILD RUN git clone ${VLLM_REPO} \ && git fetch upstream ; fi FROM fetch_vllm_${REMOTE_VLLM} AS fetch_vllm +# Resolve the device-independent source version once for every downstream +# artifact. setuptools-scm reads Git metadata for local/remote sources and the +# archive metadata generated for canonical CI contexts. +FROM fetch_vllm AS vllm-version +ARG COMMON_WORKDIR +RUN --mount=type=cache,id=vllm-rocm-uv,target=/root/.cache/uv \ + cd ${COMMON_WORKDIR}/vllm \ + && uv pip install --system -r requirements/build/rust.txt \ + && python3 -c \ + "from setuptools_scm import get_version; print(get_version())" \ + > /vllm-version.txt + # ----------------------- # Rust/protoc toolchain inputs # @@ -238,6 +250,7 @@ COPY --from=rust-input /rust-input/vllm/rust rust COPY --from=rust-input /rust-input/vllm/rust-toolchain.toml rust-toolchain.toml COPY --from=rust-input /rust-input/vllm/tools/build_rust.py tools/build_rust.py COPY --from=rust-input /rust-input/vllm/build_rust.sh build_rust.sh +COPY --from=vllm-version /vllm-version.txt /tmp/vllm-version.txt # Build the release binary. Cargo's registry/git caches can be written by # concurrent BuildKit jobs on shared workers, so lock those cache mounts while @@ -249,6 +262,7 @@ RUN --mount=type=cache,id=vllm-rocm-cargo-registry,target=/root/.cargo/registry, export RUSTC_WRAPPER=sccache \ && sccache --show-stats; \ fi \ + && export SETUPTOOLS_SCM_PRETEND_VERSION="$(cat /tmp/vllm-version.txt)" \ && bash build_rust.sh \ && test -x vllm/vllm-rs \ && if [ "$USE_SCCACHE" = "1" ]; then \ @@ -334,6 +348,7 @@ RUN --mount=type=bind,source=pyproject.toml,target=${COMMON_WORKDIR}/vllm/pyproj FROM build_vllm_dependencies AS build_vllm COPY --from=fetch_vllm ${COMMON_WORKDIR}/vllm ${COMMON_WORKDIR}/vllm COPY --from=csrc-build ${COMMON_WORKDIR}/vllm/dist /precompiled-wheels +COPY --from=vllm-version /vllm-version.txt /tmp/vllm-version.txt # Drop the pre-built Rust artifacts into the source tree. setup.py detects # them and ships them as-is, skipping the local Rust build. @@ -341,6 +356,7 @@ COPY --from=rust-build ${COMMON_WORKDIR}/vllm/vllm/vllm-rs ${COMMON_WORKDIR}/vll COPY --from=rust-build ${COMMON_WORKDIR}/vllm/vllm/_rust_*.so ${COMMON_WORKDIR}/vllm/vllm/ RUN cd "${COMMON_WORKDIR}/vllm" \ + && export SETUPTOOLS_SCM_PRETEND_VERSION="$(cat /tmp/vllm-version.txt)" \ && export VLLM_USE_PRECOMPILED=1 \ && export VLLM_PRECOMPILED_WHEEL_LOCATION="$(ls /precompiled-wheels/*.whl)" \ && export VLLM_DOCKER_BUILD_CONTEXT=1 \ @@ -640,6 +656,7 @@ FROM fetch_vllm AS build_vllm_wheel_release ARG COMMON_WORKDIR ARG ROCM_TRITON_KERNELS_COMMIT +COPY --from=vllm-version /vllm-version.txt /tmp/vllm-version.txt COPY --from=rocm-triton-kernels \ /opt/rocm-triton-kernels /opt/rocm-triton-kernels ENV TRITON_KERNELS_SRC_DIR=/opt/rocm-triton-kernels @@ -678,17 +695,12 @@ RUN if [ "$GIT_REPO_CHECK" != "0" ]; then \ cd vllm && bash tools/check_repo.sh; \ fi -# Extract version from git BEFORE any modifications (pin_rocm_dependencies.py modifies requirements/rocm.txt) -# This ensures setuptools_scm sees clean repo state for version detection -RUN --mount=type=bind,source=.git,target=vllm/.git \ - --mount=type=cache,target=/root/.cache/uv \ +# Install the packaging helpers before modifying requirements/rocm.txt. +RUN --mount=type=cache,target=/root/.cache/uv \ grep -Fq "set(TRITON_KERNELS_TAG \"${ROCM_TRITON_KERNELS_COMMIT}\")" \ vllm/cmake/external_projects/triton_kernels.cmake \ && cd vllm \ - && uv pip install --system setuptools_scm regex \ - && VLLM_VERSION=$(python3 -c "import setuptools_scm; print(setuptools_scm.get_version())") \ - && echo "Detected vLLM version: ${VLLM_VERSION}" \ - && echo "${VLLM_VERSION}" > /tmp/vllm_version.txt + && uv pip install --system setuptools_scm regex # Fail if git-based package dependencies are found in requirements files # (uv doesn't handle git+ URLs well, and packages should be distributed on PyPI) @@ -726,13 +738,12 @@ RUN --mount=type=cache,target=/root/.cache/uv \ && echo "Building vLLM with custom wheels from /install" \ && uv pip install --system --find-links /install -r requirements/rocm.txt -# Build wheel using pre-extracted version to avoid dirty state from modified requirements/rocm.txt +# Build wheel using the shared source version to avoid dirty state from modified requirements/rocm.txt # (setup.py auto-detects ccache/sccache in PATH) -RUN --mount=type=bind,source=.git,target=vllm/.git \ - --mount=type=cache,id=vllm-rocm-ccache,target=/root/.cache/ccache \ +RUN --mount=type=cache,id=vllm-rocm-ccache,target=/root/.cache/ccache \ cd vllm \ && export CCACHE_BASEDIR="$PWD" \ - && export SETUPTOOLS_SCM_PRETEND_VERSION=$(cat /tmp/vllm_version.txt) \ + && export SETUPTOOLS_SCM_PRETEND_VERSION="$(cat /tmp/vllm-version.txt)" \ && echo "Building wheel with version: ${SETUPTOOLS_SCM_PRETEND_VERSION}" \ && MAX_JOBS="${MAX_JOBS:-$(nproc)}" python3 setup.py bdist_wheel --dist-dir=dist diff --git a/docker/Dockerfile.rocm_gfx1250 b/docker/Dockerfile.rocm_gfx1250 index 4c0008f6ec..6e88eb9fed 100644 --- a/docker/Dockerfile.rocm_gfx1250 +++ b/docker/Dockerfile.rocm_gfx1250 @@ -127,6 +127,17 @@ ONBUILD RUN git clone ${VLLM_REPO} \ && git fetch upstream ; fi FROM fetch_vllm_${REMOTE_VLLM} AS fetch_vllm +# Resolve the device-independent source version once for every downstream +# artifact. setuptools-scm reads Git metadata from local and remote sources. +FROM fetch_vllm AS vllm-version +ARG COMMON_WORKDIR +RUN --mount=type=cache,id=vllm-rocm-uv,target=/root/.cache/uv \ + cd ${COMMON_WORKDIR}/vllm \ + && uv pip install --system -r requirements/build/rust.txt \ + && python3 -c \ + "from setuptools_scm import get_version; print(get_version())" \ + > /vllm-version.txt + # ----------------------- # Rust build stage # Builds the `vllm-rs` frontend in a dedicated stage so the wheel build stages @@ -152,6 +163,8 @@ RUN --mount=type=cache,id=vllm-rocm-uv,target=/root/.cache/uv \ cd ${COMMON_WORKDIR}/vllm \ && uv pip install --system -r requirements/build/rust.txt +COPY --from=vllm-version /vllm-version.txt /tmp/vllm-version.txt + # Build the release binary. Cargo's registry/git caches can be written by # concurrent BuildKit jobs on shared workers, so lock those cache mounts while # keeping the cache benefit. Do not cache target/, because stale target metadata @@ -159,6 +172,7 @@ RUN --mount=type=cache,id=vllm-rocm-uv,target=/root/.cache/uv \ RUN --mount=type=cache,id=vllm-rocm-cargo-registry,target=/root/.cargo/registry,sharing=locked \ --mount=type=cache,id=vllm-rocm-cargo-git,target=/root/.cargo/git,sharing=locked \ cd ${COMMON_WORKDIR}/vllm \ + && export SETUPTOOLS_SCM_PRETEND_VERSION="$(cat /tmp/vllm-version.txt)" \ && bash build_rust.sh \ && test -x vllm/vllm-rs @@ -211,6 +225,7 @@ ARG COMMON_WORKDIR ENV VLLM_TARGET_DEVICE=rocm COPY --from=csrc-build ${COMMON_WORKDIR}/vllm/dist /precompiled-wheels +COPY --from=vllm-version /vllm-version.txt /tmp/vllm-version.txt # Drop the pre-built Rust artifacts into the source tree. setup.py detects # them and ships them as-is, skipping the local Rust build. @@ -220,6 +235,7 @@ COPY --from=rust-build ${COMMON_WORKDIR}/vllm/vllm/_rust_*.so ${COMMON_WORKDIR}/ RUN --mount=type=cache,id=vllm-rocm-uv,target=/root/.cache/uv \ cd vllm \ && uv pip install --system -r requirements/rocm.txt \ + && export SETUPTOOLS_SCM_PRETEND_VERSION="$(cat /tmp/vllm-version.txt)" \ && export VLLM_USE_PRECOMPILED=1 \ && export VLLM_PRECOMPILED_WHEEL_LOCATION="$(ls /precompiled-wheels/*.whl)" \ && export VLLM_DOCKER_BUILD_CONTEXT=1 \ @@ -426,6 +442,7 @@ RUN /bin/bash -lc 'set -euo pipefail; \ FROM fetch_vllm AS build_vllm_wheel_release ARG COMMON_WORKDIR +COPY --from=vllm-version /vllm-version.txt /tmp/vllm-version.txt # Drop the pre-built Rust artifacts into the source tree. setup.py detects # them and ships them as-is, skipping the local Rust build. @@ -461,15 +478,10 @@ RUN if [ "$GIT_REPO_CHECK" != "0" ]; then \ cd vllm && bash tools/check_repo.sh; \ fi -# Extract version from git BEFORE any modifications (pin_rocm_dependencies.py modifies requirements/rocm.txt) -# This ensures setuptools_scm sees clean repo state for version detection -RUN --mount=type=bind,source=.git,target=vllm/.git \ - --mount=type=cache,target=/root/.cache/uv \ +# Install the packaging helpers before modifying requirements/rocm.txt. +RUN --mount=type=cache,target=/root/.cache/uv \ cd vllm \ - && uv pip install --system setuptools_scm regex \ - && VLLM_VERSION=$(python3 -c "import setuptools_scm; print(setuptools_scm.get_version())") \ - && echo "Detected vLLM version: ${VLLM_VERSION}" \ - && echo "${VLLM_VERSION}" > /tmp/vllm_version.txt + && uv pip install --system setuptools_scm regex # Fail if git-based package dependencies are found in requirements files # (uv doesn't handle git+ URLs well, and packages should be distributed on PyPI) @@ -507,13 +519,12 @@ RUN --mount=type=cache,target=/root/.cache/uv \ && echo "Building vLLM with custom wheels from /install" \ && uv pip install --system --find-links /install -r requirements/rocm.txt -# Build wheel using pre-extracted version to avoid dirty state from modified requirements/rocm.txt +# Build wheel using the shared source version to avoid dirty state from modified requirements/rocm.txt # (setup.py auto-detects ccache/sccache in PATH) -RUN --mount=type=bind,source=.git,target=vllm/.git \ - --mount=type=cache,id=vllm-rocm-ccache,target=/root/.cache/ccache \ +RUN --mount=type=cache,id=vllm-rocm-ccache,target=/root/.cache/ccache \ cd vllm \ && export CCACHE_BASEDIR="$PWD" \ - && export SETUPTOOLS_SCM_PRETEND_VERSION=$(cat /tmp/vllm_version.txt) \ + && export SETUPTOOLS_SCM_PRETEND_VERSION="$(cat /tmp/vllm-version.txt)" \ && echo "Building wheel with version: ${SETUPTOOLS_SCM_PRETEND_VERSION}" \ && MAX_JOBS="${MAX_JOBS:-$(nproc)}" python3 setup.py bdist_wheel --dist-dir=dist diff --git a/docker/Dockerfile.xpu b/docker/Dockerfile.xpu index ea7159f8c4..456be41f6f 100644 --- a/docker/Dockerfile.xpu +++ b/docker/Dockerfile.xpu @@ -28,8 +28,13 @@ COPY build_rust.sh build_rust.sh # (rustc spawns enough concurrent processes to hit RLIMIT_NOFILE otherwise). ENV CARGO_BUILD_JOBS=4 +# Only Rust inputs are present, so suppress the artificial dirty state caused +# by other tracked files being absent from this build stage. +ENV SETUPTOOLS_SCM_PRETEND_METADATA={dirty=false} + RUN --mount=type=cache,target=/root/.cargo/registry,sharing=locked \ --mount=type=cache,target=/root/.cargo/git,sharing=locked \ + --mount=type=bind,source=.git,target=.git \ bash build_rust.sh FROM ubuntu:24.04 AS vllm-base diff --git a/requirements/build/rust.txt b/requirements/build/rust.txt index e2874dee0a..f507deb803 100644 --- a/requirements/build/rust.txt +++ b/requirements/build/rust.txt @@ -1,4 +1,5 @@ # Dependencies for building Rust artifacts through setuptools-rust. setuptools>=77.0.3,<81.0.0 +setuptools-scm>=9.2.0 setuptools-rust>=1.9.0 wheel diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 6262bf2e78..a8608e34f2 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -5505,9 +5505,14 @@ dependencies = [ "tracing", "url", "uuid", + "vllm-build-info", "vllm-tracing", ] +[[package]] +name = "vllm-build-info" +version = "0.1.0" + [[package]] name = "vllm-chat" version = "0.1.0" @@ -5574,6 +5579,7 @@ dependencies = [ "tracing", "uuid", "vllm-bench", + "vllm-build-info", "vllm-chat", "vllm-engine-core-client", "vllm-managed-engine", @@ -5755,6 +5761,7 @@ dependencies = [ "url", "uuid", "validator", + "vllm-build-info", "vllm-chat", "vllm-engine-core-client", "vllm-llm", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 723e34806f..5c4b47d581 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "src/bench", + "src/build-info", "src/chat", "src/cmd", "src/engine-core-client", @@ -135,6 +136,7 @@ url = "2.5.7" uuid = { version = "1.22.0", features = ["v4"] } validator = { version = "0.20.0", features = ["derive"] } vllm-bench = { path = "src/bench" } +vllm-build-info = { path = "src/build-info" } vllm-chat = { path = "src/chat" } vllm-engine-core-client = { path = "src/engine-core-client" } vllm-llm = { path = "src/llm" } diff --git a/rust/src/bench/Cargo.toml b/rust/src/bench/Cargo.toml index 960e7a62f7..24a8f12e91 100644 --- a/rust/src/bench/Cargo.toml +++ b/rust/src/bench/Cargo.toml @@ -34,6 +34,7 @@ tokio-stream.workspace = true tracing.workspace = true url.workspace = true uuid.workspace = true +vllm-build-info.workspace = true vllm-tracing.workspace = true [lints] diff --git a/rust/src/bench/src/main.rs b/rust/src/bench/src/main.rs index 1764983e44..3485e22bb1 100644 --- a/rust/src/bench/src/main.rs +++ b/rust/src/bench/src/main.rs @@ -12,7 +12,7 @@ use clap::Parser; #[command( name = "vllm-bench", about = "Benchmark online serving throughput", - version + version = vllm_build_info::VERSION )] struct Cli { #[command(flatten)] diff --git a/rust/src/build-info/Cargo.toml b/rust/src/build-info/Cargo.toml new file mode 100644 index 0000000000..41d3092af0 --- /dev/null +++ b/rust/src/build-info/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "vllm-build-info" +version.workspace = true +edition.workspace = true +license.workspace = true + +[lints] +workspace = true diff --git a/rust/src/build-info/src/lib.rs b/rust/src/build-info/src/lib.rs new file mode 100644 index 0000000000..962fbe2f7d --- /dev/null +++ b/rust/src/build-info/src/lib.rs @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Copyright contributors to the vLLM project + +/// The vLLM package version supplied by the build system. +/// +/// Direct Cargo builds fall back to the internal crate version. +pub const VERSION: &str = match option_env!("VLLM_RS_BUILD_VERSION") { + Some(version) => version, + None => env!("CARGO_PKG_VERSION"), +}; diff --git a/rust/src/cmd/Cargo.toml b/rust/src/cmd/Cargo.toml index a326a0f999..bf92e05ee1 100644 --- a/rust/src/cmd/Cargo.toml +++ b/rust/src/cmd/Cargo.toml @@ -28,6 +28,7 @@ tokio-util.workspace = true tracing.workspace = true uuid.workspace = true vllm-bench.workspace = true +vllm-build-info.workspace = true vllm-chat.workspace = true vllm-engine-core-client.workspace = true vllm-managed-engine.workspace = true diff --git a/rust/src/cmd/src/cli.rs b/rust/src/cmd/src/cli.rs index 833b93ee43..e851fad549 100644 --- a/rust/src/cmd/src/cli.rs +++ b/rust/src/cmd/src/cli.rs @@ -39,7 +39,8 @@ use crate::cli::unsupported::UnsupportedArgs; #[derive(Debug, Parser)] #[command( name = "vllm-rs", - about = "Rust frontend and managed-engine CLI for vLLM." + about = "Rust frontend and managed-engine CLI for vLLM.", + version = vllm_build_info::VERSION )] pub struct Cli { #[command(subcommand)] diff --git a/rust/src/server/Cargo.toml b/rust/src/server/Cargo.toml index 8b8f57a0da..f6e6f08b53 100644 --- a/rust/src/server/Cargo.toml +++ b/rust/src/server/Cargo.toml @@ -45,6 +45,7 @@ tracing-subscriber.workspace = true url.workspace = true uuid.workspace = true validator.workspace = true +vllm-build-info.workspace = true vllm-chat.workspace = true vllm-engine-core-client.workspace = true vllm-llm.workspace = true diff --git a/rust/src/server/src/routes/tests.rs b/rust/src/server/src/routes/tests.rs index ac65ae269a..260851b4ef 100644 --- a/rust/src/server/src/routes/tests.rs +++ b/rust/src/server/src/routes/tests.rs @@ -1746,7 +1746,7 @@ async fn version_returns_engine_vllm_version() { json, json!({ "version": "test-vllm-version", - "rust_frontend_version": env!("CARGO_PKG_VERSION"), + "rust_frontend_version": vllm_build_info::VERSION, }) ); } diff --git a/rust/src/server/src/routes/version.rs b/rust/src/server/src/routes/version.rs index e4f6f3f1ea..2398224c5c 100644 --- a/rust/src/server/src/routes/version.rs +++ b/rust/src/server/src/routes/version.rs @@ -21,6 +21,6 @@ pub async fn version(State(state): State>) -> Json str | None: + """Set the device-independent vLLM source version for Rust artifacts.""" + version = os.getenv(VLLM_RS_BUILD_VERSION) or None + if version is None: + try: + version = get_version(root=ROOT_DIR) + except LookupError: + return None + + os.environ[VLLM_RS_BUILD_VERSION] = version + return version def rust_extensions(*, optional: bool = False) -> list[RustExtension]: @@ -61,6 +76,7 @@ def build_binary(build_rust_args: list[str]) -> None: def main() -> None: + prepare_build_environment() build_binary(sys.argv[1:])