zero-to-production icon indicating copy to clipboard operation
zero-to-production copied to clipboard

Incompatible rust (1.72.0) and sqlx (0.7.4) versions

Open juanmaia opened this issue 10 months ago • 2 comments

When going through the Dockerfile in the chapter 5, I got the following error when running docker build --tag zero2prod --file Dockerfile .

error[E0658]: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
   --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/raw_sql.rs:143:10
    |
143 |     ) -> crate::Result<<E::Database as Database>::QueryResult>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #103532 <https://github.com/rust-lang/rust/issues/103532> for more information

error[E0658]: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
   --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/raw_sql.rs:212:10
    |
212 |     ) -> crate::Result<Vec<<E::Database as Database>::Row>>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #103532 <https://github.com/rust-lang/rust/issues/103532> for more information

error[E0658]: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
   --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/raw_sql.rs:236:10
    |
236 |     ) -> crate::Result<<E::Database as Database>::Row>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #103532 <https://github.com/rust-lang/rust/issues/103532> for more information

error[E0658]: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
   --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/sqlx-core-0.7.4/src/raw_sql.rs:260:10
    |
260 |     ) -> crate::Result<<E::Database as Database>::Row>
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #103532 <https://github.com/rust-lang/rust/issues/103532> for more information

For more information about this error, try `rustc --explain E0658`.
error: could not compile `sqlx-core` (lib) due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
thread 'main' panicked at 'Exited with status code: 101', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-chef-0.1.62/src/recipe.rs:204:27
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This error was not happening when running cargo build --release locally, so I assumed was something related to the rust version 1.72.0 as opposed to the 1.77.2 that I'm running locally. I guess that by the time the book was written sqlx was not yet on version 0.7.4, but probably on a smaller patch version. I'm new to Rust so I can't tell where the breaking change was added, but probably on sqlx, which is relying in a feature that is not yet available on Rust 1.72.0 but it is on 1.77.2, I haven't looked into the error, since upgrading the Dockerfile base image to 1.77.2 solves the problem.

Might be a good idea to lock all minor and patch versions to have a deterministic build.

juanmaia avatar Apr 24 '24 15:04 juanmaia

I can confirm that 1.77.2 gets the build working with sqlx 0.7.4, however 1.77.2-slim (as introduced a few pages later in the book) fails to build for reasons related to openssl.

This topic is actually addressed shortly afterwards in the "bare operating system" section, but to get the rust-slim build working at this stage, just install the missing dependencies explicitly:

-FROM rust:1.72.0-slim AS builder
+FROM rust:1.77.2-slim AS builder

-RUN apt update && apt install lld clang -y
+RUN apt update && apt install pkg-config libssl-dev lld clang -y

hejops avatar Apr 28 '24 13:04 hejops

I have the same error in the process of working with Chapter 5. Fixing the sqlx version to 0.7.1 in Cargo.toml solved the problem.: sqlx = { version = "=0.7.1", default-features = false, features = ["runtime-tokio-rustls", "macros", "postgres", "uuid", "chrono", "migrate"] }

jashka34 avatar Jun 11 '24 18:06 jashka34

This has been fixed in the next book release by updating everything to latest. Closing!

LukeMathWalker avatar Aug 30 '24 13:08 LukeMathWalker