Skip to content

Use rust-toolchain.toml before rustup on Dockerfile-{cuda,cuda-all}#842

Merged
alvarobartt merged 2 commits intomainfrom
use-rust-toolchain-in-dockerfile
Mar 6, 2026
Merged

Use rust-toolchain.toml before rustup on Dockerfile-{cuda,cuda-all}#842
alvarobartt merged 2 commits intomainfrom
use-rust-toolchain-in-dockerfile

Conversation

@alvarobartt
Copy link
Copy Markdown
Member

@alvarobartt alvarobartt commented Mar 6, 2026

What does this PR do?

This PR adds a COPY rust-toolchain.toml rust-toolchain.toml to the Dockerfile-cuda and Dockerfile-cuda-all files, since as those are not pulling from lukemathwalker/cargo-chef:latest-rust-1.92-bookworm as the base image; rustup was installing the latest stable Rust version, which was leading to issues when building earlier versions of Text Embeddings Inference e.g.,

git clone git@github.com:huggingface/text-embeddings-inference.git
cd text-embeddings-inference/
git checkout v1.8.0
docker build --platform linux/amd64 -t text-embeddings-inference:cuda-1.8.0 -f Dockerfile-cuda-all .

Which was failing with the following exception:

  ...
  35.83 error[E0521]: borrowed data escapes outside of associated function
  35.83   --> /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/metrics-0.23.0/src/recorder/mod.rs:77:9
  35.83    |
  35.83 71 |       fn new(recorder: &dyn Recorder) -> Self {
  35.83    |              --------  - let's call the lifetime of this reference `'1`
  35.83    |              |
  35.83    |              `recorder` is a reference that is only valid in the associated function body
  35.83 ...
  35.83 77 | /         LOCAL_RECORDER.with(|local_recorder| {
  35.83 78 | |             local_recorder.set(Some(recorder_ptr));
  35.83 79 | |         });
  35.83    | |          ^
  35.83    | |          |
  35.83    | |__________`recorder` escapes the associated function body here
  35.83    |            argument requires that `'1` must outlive `'static`
  35.83    |
  35.83 note: raw pointer casts of trait objects cannot extend lifetimes
  35.83   --> /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/metrics-0.23.0/src/recorder/mod.rs:75:60
  35.83    |
  35.83 75 |         let recorder_ptr = unsafe { NonNull::new_unchecked(recorder as *const _ as *mut _) };
  35.83    |                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  35.83    = note: this was previously accepted by the compiler but was changed recently
  35.83    = help: see <https://github.com/rust-lang/rust/issues/141402> for more information
  35.83
  35.84 For more information about this error, try `rustc --explain E0521`.
  35.84 error: could not compile `metrics` (lib) due to 1 previous error
  35.84 warning: build failed, waiting for other jobs to finish...
  63.24
  63.24 thread 'main' (7) panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cargo-chef-0.1.71/src/recipe.rs:218:27:
  63.24 Exited with status code: 101
  63.24 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
  ------
  Dockerfile-aws-cuda:52
  --------------------
    51 |
    52 | >>> RUN --mount=type=secret,id=actions_results_url,env=ACTIONS_RESULTS_URL \
    53 | >>>     --mount=type=secret,id=actions_runtime_token,env=ACTIONS_RUNTIME_TOKEN \
    54 | >>>     cargo chef cook --release --locked --recipe-path recipe.json && sccache -s;
    55 |
  --------------------
  ERROR: failed to solve: process "/bin/sh -c cargo chef cook --release --locked --recipe-path recipe.json && sccache -s;" did not
  complete successfully: exit code: 101

rustup was installing the latest stable Rust (1.86+) because no toolchain was specified, and given that Rust 1.86+ tightened lifetime checking for raw pointer casts (see rust-lang/rust#141402 and metrics-rs/metrics#564), it broken metrics-0.23.0 which was pinned in the Cargo.lock on v1.8.0.

By copying rust-toolchain.toml before any cargo invocation, rustup automatically installs and uses the exact Rust version, which fixes the immediate compile failure and prevents any future version drift.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline?
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the documentation guidelines.
  • Did you write any new necessary tests? If applicable, did you include or update the insta snapshots?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@alvarobartt alvarobartt merged commit 8f756c4 into main Mar 6, 2026
2 checks passed
@alvarobartt alvarobartt deleted the use-rust-toolchain-in-dockerfile branch March 6, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant