LukeMathWalker / zero-to-production

Code for "Zero To Production In Rust", a book on API development using Rust.
https://www.zero2prod.com
Apache License 2.0
5.43k stars 470 forks source link

Incompatible rust (1.72.0) and sqlx (0.7.4) versions #259

Open juanmaia opened 2 months ago

juanmaia commented 2 months ago

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.

hejops commented 2 months ago

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
jashka34 commented 3 weeks ago

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"] }