immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.79k stars 219 forks source link

Build not matching clang version (Fedora 39, Clang 17.0.6) #1060

Closed pantsman0 closed 5 months ago

pantsman0 commented 5 months ago

I am getting a build error in c2rust-ast-exporter when installing from crates.io.

From the error, it appears that the compiler is not properly detecting CLANG_VERSION_MAJOR at in AstExporter.cpp and is using the Optional infill.

The error is below:

error: failed to run custom build command for `c2rust-ast-exporter v0.18.0`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installaDwB9v/release/build/c2rust-ast-exporter-38d748ef236b03be/build-script-build` (exit status: 101)
  --- stdout
  CMAKE_TOOLCHAIN_FILE_x86_64-unknown-linux-gnu = None
  CMAKE_TOOLCHAIN_FILE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-unknown-linux-gnu = None
  CMAKE_GENERATOR_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-unknown-linux-gnu = None
  CMAKE_PREFIX_PATH_x86_64_unknown_linux_gnu = None
  HOST_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-unknown-linux-gnu = None
  CMAKE_x86_64_unknown_linux_gnu = None
  HOST_CMAKE = None
  CMAKE = None
  running: cd "/tmp/cargo-installaDwB9v/release/build/c2rust-ast-exporter-62ed068aa0eab19a/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src" "-DLLVM_DIR=/usr/lib64/cmake/llvm" "-DClang_DIR=/usr/lib64/cmake/clang" "-DCMAKE_INSTALL_PREFIX=/tmp/cargo-installaDwB9v/release/build/c2rust-ast-exporter-62ed068aa0eab19a/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/local/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/local/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/local/bin/cc" "-DCMAKE_BUILD_TYPE=Release"
  -- The C compiler identification is Clang 17.0.6
  -- The CXX compiler identification is Clang 17.0.6
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/local/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/local/bin/c++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Performing Test HAVE_FFI_CALL
  -- Performing Test HAVE_FFI_CALL - Success
  -- Found FFI: /usr/lib64/libffi.so  
  -- Looking for histedit.h
  -- Looking for histedit.h - found
  -- Found LibEdit: /usr/include (found version "2.11") 
  -- Performing Test Terminfo_LINKABLE
  -- Performing Test Terminfo_LINKABLE - Success
  -- Found Terminfo: /usr/lib64/libtinfo.so  
  -- Found ZLIB: /usr/lib64/libz.so (found version "1.2.13")  
  -- Configuring done (3.3s)
  -- Generating done (0.0s)
  -- Build files have been written to: /tmp/cargo-installaDwB9v/release/build/c2rust-ast-exporter-62ed068aa0eab19a/out/build
  running: cd "/tmp/cargo-installaDwB9v/release/build/c2rust-ast-exporter-62ed068aa0eab19a/out/build" && MAKEFLAGS="-j --jobserver-fds=8,9 --jobserver-auth=8,9" "cmake" "--build" "." "--target" "clangAstExporter" "--config" "Release"
  [  8%] Creating directories for 'tinycbor_build'
  [ 16%] Performing download step (git clone) for 'tinycbor_build'
  [ 25%] Performing update step for 'tinycbor_build'
  [ 33%] Performing patch step for 'tinycbor_build'
  patching file Makefile
  patching file Makefile.configure
  [ 41%] Performing configure step for 'tinycbor_build'
  .config file not yet created
  [ 50%] Performing build step for 'tinycbor_build'
  [ 58%] Performing install step for 'tinycbor_build'
  [ 66%] Completed 'tinycbor_build'
  [ 66%] Built target tinycbor_build
  [ 75%] Building CXX object CMakeFiles/clangAstExporter.dir/AstExporter.cpp.o

  --- stderr
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
    Compatibility with CMake < 3.5 will be removed from a future version of
    CMake.

    Update the VERSION argument <min> value or use a ...<max> suffix to tell
    CMake that the project does not need compatibility with older versions.

  CMake Warning (dev) at /usr/share/cmake/Modules/CheckIncludeFile.cmake:77 (message):
    Policy CMP0075 is not set: Include file check macros honor
    CMAKE_REQUIRED_LIBRARIES.  Run "cmake --help-policy CMP0075" for policy
    details.  Use the cmake_policy command to set the policy and suppress this
    warning.

    CMAKE_REQUIRED_LIBRARIES is set to:

      /usr/lib64/libedit.so

    For compatibility with CMake 3.11 and below this check is ignoring it.
  Call Stack (most recent call first):
    /usr/lib64/cmake/llvm/FindLibEdit.cmake:28 (check_include_file)
    /usr/lib64/cmake/llvm/LLVMConfig.cmake:262 (find_package)
    CMakeLists.txt:57 (find_package)
  This warning is for project developers.  Use -Wno-dev to suppress it.

  CMake Warning:
    Manually-specified variables were not used by the project:

      CMAKE_ASM_COMPILER
      CMAKE_ASM_FLAGS

  Cloning into 'tinycbor_build'...
  HEAD is now at d393c16 Parser: fix reading it->extra on big endian when bytesNeeded == 1
  make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
  make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
  make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
  make[4]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
  /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:88:1: error: no template named 'Optional'; did you mean 'std::optional'?
     88 | Optional<APSInt> getIntegerConstantExpr(const Expr &E, const ASTContext &Ctx) {
        | ^~~~~~~~
        | std::optional
  /usr/lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/optional:705:11: note: 'std::optional' declared here
    705 |     class optional
        |           ^
  /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:1502:63: error: no member named 'getField' in 'clang::DesignatedInitExpr::Designator'
   1502 |                                          uintptr_t(designator.getField()));
        |                                                    ~~~~~~~~~~ ^
  /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:2283:21: warning: enumeration value 'Unevaluated' not handled in switch [-Wswitch]
   2283 |             switch (SL->getKind()) {
        |                     ^~~~~~~~~~~~~
  1 warning and 2 errors generated.
  gmake[3]: *** [CMakeFiles/clangAstExporter.dir/build.make:76: CMakeFiles/clangAstExporter.dir/AstExporter.cpp.o] Error 1
  gmake[2]: *** [CMakeFiles/Makefile2:274: CMakeFiles/clangAstExporter.dir/all] Error 2
  gmake[1]: *** [CMakeFiles/Makefile2:281: CMakeFiles/clangAstExporter.dir/rule] Error 2
  gmake: *** [Makefile:215: clangAstExporter] Error 2
  thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

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

  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...
error: failed to compile `c2rust v0.18.0`, intermediate artifacts can be found at `/tmp/cargo-installaDwB9v`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
haberman commented 5 months ago

I just got exactly the same error, but on mac.

LLVM was installed by Brew into /opt/homebrew/Cellar/llvm/17.0.6_1.

thedataking commented 5 months ago

This commit added support for LLVM 17 and this commit fixed a papercut required for LLVM 17 to work. Therefore, I believe the problem is fixed on master, can you try building from that to confirm this thesis?

pantsman0 commented 5 months ago

That looks like it builds. I was building from source so I thought it wasn't fixed, but it looks like I had checked out tag 0.18.0