cmake-rs icon indicating copy to clipboard operation
cmake-rs copied to clipboard

x86_64-linux-musl-g++ when compiling musl target

Open Masber opened this issue 6 months ago • 1 comments

Dear cmake-rs community,

I am new to this type of compilation and I am trying to build a musl binary from my project. For some reason the compilation fails with error:

I installed x86_64-unknown-linux-musl and also musl-cross-make

warning: [email protected]+2.3.0: Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-g++": No such file or directory (os error 2)
error: failed to run custom build command for `rdkafka-sys v4.8.0+2.3.0`

Caused by:
  process didn't exit successfully: `/home/runner/work/manta/manta/target/dist/build/rdkafka-sys-5dd56179dd26227f/build-script-build` (exit status: 101)
  --- stdout
  Configuring and compiling librdkafka
  CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-musl = None
  CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_musl = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-unknown-linux-musl = None
  CMAKE_GENERATOR_x86_64_unknown_linux_musl = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  cargo:warning=Compiler family detection failed due to error: ToolNotFound: failed to find tool "x86_64-linux-musl-g++": No such file or directory (os error 2)
  CMAKE_PREFIX_PATH_x86_64-unknown-linux-musl = None
  CMAKE_PREFIX_PATH_x86_64_unknown_linux_musl = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-unknown-linux-musl = None
  CMAKE_x86_64_unknown_linux_musl = None
  TARGET_CMAKE = None
  CMAKE = None
  running: cd "/home/runner/work/manta/manta/target/x86_64-unknown-linux-musl/dist/build/rdkafka-sys-74997b9c2854f9a2/out/build" && CMAKE_PREFIX_PATH="/home/runner/work/manta/manta/target/x86_64-unknown-linux-musl/dist/build/libz-sys-26a7bea048d246d1/out:" LC_ALL="C" "cmake" "/home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rdkafka-sys-4.8.0+2.3.0/librdkafka" "-DRDKAFKA_BUILD_STATIC=1" "-DRDKAFKA_BUILD_TESTS=0" "-DRDKAFKA_BUILD_EXAMPLES=0" "-DCMAKE_INSTALL_LIBDIR=lib" "-DWITH_ZLIB=1" "-DWITH_CURL=0" "-DWITH_SSL=0" "-DWITH_SASL=0" "-DWITH_ZSTD=0" "-DENABLE_LZ4_EXT=0" "-DCMAKE_SYSTEM_NAME=Linux" "-DCMAKE_SYSTEM_PROCESSOR=x86_64" "-DCMAKE_INSTALL_PREFIX=/home/runner/work/manta/manta/target/x86_64-unknown-linux-musl/dist/build/rdkafka-sys-74997b9c2854f9a2/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -static" "-DCMAKE_C_COMPILER=/usr/bin/x86_64-linux-musl-gcc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -static" "-DCMAKE_CXX_COMPILER=x86_64-linux-musl-g++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 -static" "-DCMAKE_ASM_COMPILER=/usr/bin/x86_64-linux-musl-gcc" "-DCMAKE_BUILD_TYPE=MinSizeRel"
  -- The C compiler identification is GNU 11.4.0
  -- The CXX compiler identification is unknown
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/x86_64-linux-musl-gcc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Configuring incomplete, errors occurred!

  --- stderr
  Building and linking librdkafka statically
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
    Compatibility with CMake < 3.10 will be removed from a future version of
    CMake.

    Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
    to tell CMake that the project requires at least <min> but has been updated
    to work with policies introduced by <max> or earlier.


  CMake Error at CMakeLists.txt:6 (project):
    The CMAKE_CXX_COMPILER:

      x86_64-linux-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 /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.54/src/lib.rs:1119:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

  × failed to find bin manta for path+file:///home/runner/work/manta/manta#1.54.96
  help: did the above build fail?

full logs --> https://github.com/eth-cscs/manta/actions/runs/15229587583/job/42836254358

I would like to understand how to solve this issue

kind regards

Masber avatar May 25 '25 11:05 Masber

Hello! For me, adding this step allows me to run it.

      - name: Install packages
        run: |
          curl -LO https://github.com/cross-tools/musl-cross/releases/download/20250520/x86_64-unknown-linux-musl.tar.xz
          sudo mkdir -p /opt/x-tools
          sudo tar -xf x86_64-unknown-linux-musl.tar.xz -C /opt/x-tools
          echo CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=/opt/x-tools/x86_64-unknown-linux-musl/bin/x86_64-unknown-linux-musl-gcc >> $GITHUB_ENV
          echo CC_x86_64_unknown_linux_musl=/opt/x-tools/x86_64-unknown-linux-musl/bin/x86_64-unknown-linux-musl-gcc >> $GITHUB_ENV
          echo CXX_x86_64_unknown_linux_musl=/opt/x-tools/x86_64-unknown-linux-musl/bin/x86_64-unknown-linux-musl-g++ >> $GITHUB_ENV
          echo AR_x86_64_unknown_linux_musl=/opt/x-tools/x86_64-unknown-linux-musl/bin/x86_64-unknown-linux-musl-ar >> $GITHUB_ENV
          echo RANLIB_x86_64_unknown_linux_musl=/opt/x-tools/x86_64-unknown-linux-musl/bin/x86_64-unknown-linux-musl-ranlib >> $GITHUB_ENV
          echo STRIP_x86_64_unknown_linux_musl=/opt/x-tools/x86_64-unknown-linux-musl/bin/x86_64-unknown-linux-musl-strip >> $GITHUB_ENV
          rustup target add x86_64-unknown-linux-musl

xuxiaocheng0201 avatar Jul 19 '25 19:07 xuxiaocheng0201