immunant / c2rust

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

Build fails with LLVM 18 and tip-of-tree #1066

Closed ZeaMays14142 closed 3 months ago

ZeaMays14142 commented 4 months ago

When trying to build a project that uses c2rust-ast-exporter as a dependency, the build fails with an exit status of 2. The error message indicates that the build script for c2rust-ast-exporter failed when it tried to build the clangAstExporter target. This issue occurs even in a minimal project that only includes c2rust-ast-exporter as a dependency and declares it as an external crate.

Environment:

Steps to reproduce:

Create a new Rust project with cargo init. Add c2rust-ast-exporter as a dependency in the Cargo.toml file. Declare c2rust-ast-exporter as an external crate in the main.rs file. The actual script's content is just a HelloWorld Run cargo build.

Expected behavior:

The project builds successfully without any errors.

Actual behavior:

The build fails with an exit status of 2. The error message indicates that the build script for c2rust-ast-exporter failed when it tried to build the clangAstExporter target.

Here is the error

error: failed to run custom build command for `c2rust-ast-exporter v0.18.0` Caused by: process didn't exit successfully: `/home/mirai/TEST/target/debug/build/c2rust-ast-exporter-86a8d91f43f7ae97/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 "/home/mirai/TEST/target/debug/build/c2rust-ast-exporter-36937e6667e9a9ea/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/home/mirai/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src" "-DLLVM_DIR=/home/mirai/llvm-project/stage1/install/lib/cmake/llvm" "-DClang_DIR=/home/mirai/llvm-project/stage1/install/lib/cmake/clang" "-DCMAKE_INSTALL_PREFIX=/home/mirai/TEST/target/debug/build/c2rust-ast-exporter-36937e6667e9a9ea/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 --target=x86_64-unknown-linux-gnu" "-DCMAKE_C_COMPILER=/home/mirai/llvm-project/stage1/install/bin/clang" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 --target=x86_64-unknown-linux-gnu" "-DCMAKE_CXX_COMPILER=/home/mirai/llvm-project/stage1/install/bin/clang++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64 --target=x86_64-unknown-linux-gnu" "-DCMAKE_ASM_COMPILER=/home/mirai/llvm-project/stage1/install/bin/clang" "-DCMAKE_BUILD_TYPE=Debug" -- The C compiler identification is Clang 19.0.0 -- The CXX compiler identification is Clang 19.0.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /home/mirai/llvm-project/stage1/install/bin/clang - 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: /home/mirai/llvm-project/stage1/install/bin/clang++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Performing Test Terminfo_LINKABLE -- Performing Test Terminfo_LINKABLE - Success -- Found Terminfo: /usr/lib/x86_64-linux-gnu/libtinfo.so -- Found LibXml2: /usr/lib/x86_64-linux-gnu/libxml2.so (found version "2.9.13") -- Configuring done -- Generating done -- Build files have been written to: /home/mirai/TEST/target/debug/build/c2rust-ast-exporter-36937e6667e9a9ea/out/build running: cd "/home/mirai/TEST/target/debug/build/c2rust-ast-exporter-36937e6667e9a9ea/out/build" && MAKEFLAGS="-j --jobserver-fds=8,9 --jobserver-auth=8,9" "cmake" "--build" "." "--target" "clangAstExporter" "--config" "Debug" [ 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/FloatingLexer.cpp.o [ 91%] Building CXX object CMakeFiles/clangAstExporter.dir/AstExporter.cpp.o [ 91%] Building CXX object CMakeFiles/clangAstExporter.dir/ExportResult.cpp.o --- stderr 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/mirai/.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-linux-gnu/11/../../../../include/c++/11/optional:662:11: note: 'std::optional' declared here 662 | class optional | ^ /home/mirai/.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/mirai/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:2285:40: error: no member named 'StringKind' in 'clang::StringLiteral' 2285 | case clang::StringLiteral::StringKind::Ordinary: | ~~~~~~~~~~~~~~~~~~~~~~^ /home/mirai/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:2291:40: error: no member named 'StringKind' in 'clang::StringLiteral' 2291 | case clang::StringLiteral::StringKind::Wide: | ~~~~~~~~~~~~~~~~~~~~~~^ /home/mirai/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:2294:40: error: no member named 'StringKind' in 'clang::StringLiteral' 2294 | case clang::StringLiteral::StringKind::UTF8: | ~~~~~~~~~~~~~~~~~~~~~~^ /home/mirai/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:2297:40: error: no member named 'StringKind' in 'clang::StringLiteral' 2297 | case clang::StringLiteral::StringKind::UTF16: | ~~~~~~~~~~~~~~~~~~~~~~^ /home/mirai/.cargo/registry/src/index.crates.io-6f17d22bba15001f/c2rust-ast-exporter-0.18.0/src/AstExporter.cpp:2300:40: error: no member named 'StringKind' in 'clang::StringLiteral' 2300 | case clang::StringLiteral::StringKind::UTF32: | ~~~~~~~~~~~~~~~~~~~~~~^ 7 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/mirai/.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

and here is the backtrace with RUST_BACKTRACE=1


     0: rust_begin_unwind
               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
     1: core::panicking::panic_fmt
               at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
     2: cmake::fail
     3: cmake::run
     4: cmake::Config::build
     5: build_script_build::build_native
     6: build_script_build::main
     7: core::ops::function::FnOnce::call_once```

This issue occurs even in a minimal project that only includes c2rust-ast-exporter as a dependency and declares it as an external crate. The error message suggests that the issue might be with the c2rust-ast-exporter crate itself, or with its interaction with the specific environment.
thedataking commented 3 months ago

Thanks for the report. It looks like there was a change in how clang models string kinds between version 19 (yours) and 17 (the latest version we've added support for). Could you test with the clang that your host OS provides? If I remember correctly, 22.04 LTS shipped with clang/LLVM 14 so that is expected to work.