Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docker-compose up -d --build] + [cranelift] = [compilation error] #1483

Open
amab8901 opened this issue Apr 18, 2024 · 7 comments
Open

[docker-compose up -d --build] + [cranelift] = [compilation error] #1483

amab8901 opened this issue Apr 18, 2024 · 7 comments

Comments

@amab8901
Copy link

Cranelift is currently incompatible with the following Docker command (at least in my case):

docker-compose up -d --build

I get this error message:

Dockerfile:11
--------------------
   9 |     FROM chef as builder
  10 |     COPY --from=planner /app/recipe.json recipe.json
  11 | >>> RUN cargo chef cook --release --recipe-path recipe.json
  12 |     COPY . .
  13 |     RUN cargo build --release --bin gapit-modbus
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo chef cook --release --recipe-path recipe.json" did not complete successfully: exit code: 101

Would be awesome if u fix it!

@bjorn3
Copy link
Member

bjorn3 commented Apr 18, 2024

Can you post the full Dockerfile that fails for you?

@amab8901
Copy link
Author

Dockerfile contents:

FROM rust:1.75.0 as chef
RUN cargo install cargo-chef --locked
WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef as builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin nice

FROM debian:bookworm-slim AS runtime
WORKDIR /app
RUN apt update
RUN apt install openssl -y

COPY --from=builder /app/target/release/nice .

CMD ./nice

The error is reproduced via docker build . in the repo root directory. The error is reproducible when the repo is minimalistic with only fn main() {} in the main.rs. I have an outer Cargo.toml like this:

cargo-features = ["codegen-backend"]

[profile.dev]
codegen-backend = "cranelift"

[workspace]
resolver = "2"
members = ["nice"]

Directory tree looks like this:
image

The inner Cargo.toml has the following content:

[package]
name = "nice"

[dependencies]

.cargo/config.toml:

[unstable]
codegen-backend = true

[profile.dev]
codegen-backend = "cranelift"

@bjorn3
Copy link
Member

bjorn3 commented Apr 19, 2024

It looks like you are trying to use cg_clif on stable. It is currently only available on nightly. In addition you need to install the rustc-codegen-cranelift-preview component. I don't know if the container for rustc nightly has a way to install it, but if you were to use rustup, you did do rustup override set nightly; rustup component add rustc-codegen-cranelift-preview.

@amab8901
Copy link
Author

amab8901 commented May 2, 2024

It looks like you are trying to use cg_clif on stable. It is currently only available on nightly. In addition you need to install the rustc-codegen-cranelift-preview component. I don't know if the container for rustc nightly has a way to install it, but if you were to use rustup, you did do rustup override set nightly; rustup component add rustc-codegen-cranelift-preview.

I added your suggestions to my Dockerfile and it fixed it. Thanks 😄 Maybe you can add this in the README file?

@bjorn3
Copy link
Member

bjorn3 commented May 2, 2024

Happy to hear you managed to get it working! The nightly requirement and the need to install the rustc-codegen-cranelift-preview component is documented at https://github.com/rust-lang/rustc_codegen_cranelift#download-using-rustup Do you have any suggestions on how to make it clearer?

@amab8901
Copy link
Author

amab8901 commented May 4, 2024

Happy to hear you managed to get it working! The nightly requirement and the need to install the rustc-codegen-cranelift-preview component is documented at https://github.com/rust-lang/rustc_codegen_cranelift#download-using-rustup Do you have any suggestions on how to make it clearer?

Maybe create a Docker title in that README.md that explains the fact that you need to add

rustup override set nightly
rustup component add rustc-codegen-cranelift-preview

(or something like this) to Dockerfile in order for Docker to work with Cranelift. It's probably obvious to someone experienced with Docker, but Docker is something junior devs usually don't have mastery of (I'm late-junior or early-intermediate) so this is likely to be an issue many devs would stumble on if it isn't explicitly stated what needs to be put in Dockerfile to make it work with Docker.

@JustusFluegel
Copy link

JustusFluegel commented Jul 1, 2024

fwiw I think this isn't necessary to be documented in the readme, this is pretty obvious that to use cranelift in docker that it is necessary to use the same install steps as everywhere else.

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

No branches or pull requests

3 participants