1

我正在为我的 Rust 包创建一个 Dockerfile,如下所示:https ://alexbrand.dev/post/how-to-package-rust-applications-into-minimal-docker-containers/

FROM rust:1.47.0 AS build
WORKDIR /usr/src

RUN rustup target add x86_64-unknown-linux-musl
RUN apt-get update
RUN apt-get install cmake musl-tools clang libc++-dev build-essential autoconf libtool pkg-config 

# Create a dummy project and build the app's dependencies.
# If the Cargo.toml or Cargo.lock files have not changed,
# we can use the docker build cache and skip these (typically slow) steps.
RUN USER=root cargo new mypackage
WORKDIR /usr/src/mypackage
COPY Cargo.toml build.rs ./
COPY .git ./.git
RUN cargo build --release

# Copy the source and build the application.
COPY src ./src
RUN cargo install --target x86_64-unknown-linux-musl --path .

但是,它在 cargo install 步骤中失败,这似乎是因为它无法找到musl-g++. 这似乎很奇怪。

我误解了错误吗?我对如何推进这件事有点迷茫。

这是整个消息:

Step 12/16 : RUN cargo install --target x86_64-unknown-linux-musl --path .
 ---> Running in d861b7efa994
...
error: failed to run custom build command for `libmimalloc-sys v0.1.18`

Caused by:
  process didn't exit successfully: `/usr/src/mypackage/target/release/build/libmimalloc-sys-9ec3b6c9ac1c8d9d/build-script-build` (exit code: 101)
  --- stdout
  running: "cmake" "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libmimalloc-sys-0.1.18/c_src/mimalloc" "-DMI_OVERRIDE=OFF" "-DMI_BUILD_TESTS=OFF" "-DMI_SECURE=OFF" "-DMI_LOCAL_DYNAMIC_TLS=OFF" "-Dmi_defines=MI_DEBUG=0" "-DCMAKE_INSTALL_PREFIX=/usr/src/mypackage/target/x86_64-unknown-linux-musl/release/build/libmimalloc-sys-ea7ff527a98597ef/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/musl-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=musl-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/musl-gcc" "-DCMAKE_BUILD_TYPE=Release"
  -- The C compiler identification is GNU 8.3.0
  -- The CXX compiler identification is unknown
  -- Check for working C compiler: /usr/bin/musl-gcc
  -- Check for working C compiler: /usr/bin/musl-gcc -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Configuring incomplete, errors occurred!
  See also "/usr/src/mypackage/target/x86_64-unknown-linux-musl/release/build/libmimalloc-sys-ea7ff527a98597ef/out/build/CMakeFiles/CMakeOutput.log".
  See also "/usr/src/mypackage/target/x86_64-unknown-linux-musl/release/build/libmimalloc-sys-ea7ff527a98597ef/out/build/CMakeFiles/CMakeError.log".

  --- stderr
  CMake Error at CMakeLists.txt:2 (project):
    The CMAKE_CXX_COMPILER:

      musl-g++

    is not a full path and was not found in the PATH.

    Tell CMake where to find the compiler by setting either the environment
    variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
    to the compiler, or to the compiler name if it is in the PATH.


  thread 'main' panicked at '
  command did not execute successfully, got: exit code: 1

  build script failed, must exit now', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.45/src/lib.rs:894:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `mypackage v0.1.0 (/usr/src/mypackage)`, intermediate artifacts can be found at `/usr/src/mypackage/target`

Caused by:
  build failed
4

1 回答 1

0

我将首先以交互方式运行基本映像并查找 musl-g++。如果未找到,请将安装添加到 Dockerfile 并重试。

于 2020-11-19T07:36:34.733 回答