3

I'm creating a Dockerfile for my Rust package, following the example shown here: 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 .

However, it fails at the step with cargo install, which appears to be because it's unable to find musl-g++. That seems strange.

Am I misunderstanding the error? I'm a bit lost as to how to move forward with this.

Here is the entire message:

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
EB2127
  • 1,788
  • 3
  • 22
  • 43

1 Answers1

0

I would start by running the base image only interactively and look for musl-g++. If not found, add the installation to the Dockerfile and try again.

AdaShoelace
  • 342
  • 1
  • 14