Home > Blockchain >  Cargo build --release not finding cmake when run from Dockerfile
Cargo build --release not finding cmake when run from Dockerfile

Time:07-05

I am building a programm with uses the Prost extension witch should run in a docker container. When i run cargo build --release from the console everything works fine same with cargo run but when I try to do docker build ./ I get this Error:

#15 160.6 error: failed to run custom build command for `prost-build v0.10.4`
#15 160.6
#15 160.6 Caused by:
#15 160.6   process didn't exit successfully: `/web_server/target/release/build/prost-build-b45bc4869a088027/build-script-build` (exit status: 101)
#15 160.6   --- stdout
#15 160.6   cargo:rerun-if-changed=/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/prost-build-0.10.4/third-party/protobuf/cmake
#15 160.6   CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
#15 160.6   CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
#15 160.6   HOST_CMAKE_TOOLCHAIN_FILE = None
#15 160.6   CMAKE_TOOLCHAIN_FILE = None
#15 160.6   CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
#15 160.6   CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
#15 160.6   HOST_CMAKE_GENERATOR = None
#15 160.6   CMAKE_GENERATOR = None
#15 160.6   CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
#15 160.6   CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
#15 160.6   HOST_CMAKE_PREFIX_PATH = None
#15 160.6   CMAKE_PREFIX_PATH = None
#15 160.6   CMAKE_x86_64-unknown-linux-gnu = None
#15 160.6   CMAKE_x86_64_unknown_linux_gnu = None
#15 160.6   HOST_CMAKE = None
#15 160.6   CMAKE = None
#15 160.6   running: "cmake" "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/prost-build-0.10.4/third-party/protobuf/cmake" "-Dprotobuf_BUILD_TESTS=OFF" "-DCMAKE_INSTALL_PREFIX=/web_server/target/release/build/prost-build-5d68a19605f74072/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/c  " "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=Debug"
#15 160.6
#15 160.6   --- stderr
#15 160.6   thread 'main' panicked at '
#15 160.6   failed to execute command: No such file or directory (os error 2)
#15 160.6   is `cmake` not installed?
#15 160.6
#15 160.6   build script failed, must exit now', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
#15 160.6   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
#15 160.6 warning: build failed, waiting for other jobs to finish...
------
executor failed running [/bin/sh -c cargo build --release]: exit code: 101

My Dockerfile:

FROM rust:1.62 as build

RUN USER=root cargo new --bin web_server
WORKDIR /web_server

COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml


COPY ./src ./src
COPY build.rs build.rs
COPY ./proto ./proto


RUN cargo build --release

FROM debian:buster-slim


COPY --from=build /web_server/target/release/web_server .

CMD ["./web_server"]

I'm on Windows 10 and work from VS Code and i do have Cmake istalled an pathed. Anybody know what i might have done wrong inside the Dockerfile?

CodePudding user response:

From your stderr Docker build logs, you need to install cmake dependency during the image build.

#15 160.6   --- stderr
#15 160.6   thread 'main' panicked at '
#15 160.6   failed to execute command: No such file or directory (os error 2)
#15 160.6   is `cmake` not installed?

rust:1.62 is ubuntu based, so installing that dependency would look like:

RUN apt-get install -y cmake && cargo build --release

Depending on your other build dependencies, you may need to install other packages.


Some motivation why this is needed, based on your comment:

I'm on Windows 10 and work from VS Code and i do have Cmake istalled an pathed. Anybody know what i might have done wrong inside the Dockerfile?

You may have cmake locally installed but it does not look like you have cmake installed while the image is being built. The Docker image build environment is somewhat "sandboxed", it doesn't have access to any locally installed programs like your local cmake. You can read more about Docker image concepts here: https://docs.docker.com/get-started/overview/#images

  • Related