rust-qt / ritual

Use C++ libraries from Rust
Apache License 2.0
1.24k stars 49 forks source link

qt_generator generates uncompilable code with clang >= 3.9 #47

Closed o01eg closed 6 years ago

o01eg commented 7 years ago

I built qt-generator binary (I have to remove -fPIC flag and add -fms-compatibility-version=19 to fix issue https://bugreports.qt.io/browse/QTCREATORBUG-15940 in executor.rs) Then I generated core, gui, widgets and ui_tools libraries into project root and add them into Cargo.toml as:

[dependencies]
qt_core = { path = "qt_core"}
qt_gui = { path = "qt_gui"}
qt_widgets = { path = "qt_widgets"}
qt_ui_tools = { path = "qt_ui_tools"}

When I start to build project I get next error:

_build_tools)
   Compiling qt_ui_tools v0.1.5 (file:///D:/devel/qt-rust-test01/qt_ui_tools)
     Running `D:\devel\qt-rust-test01\target\debug\build\qt_ui_tools-76c560e3a1c
9030c\build-script-build`
   Compiling qt_gui v0.1.5 (file:///D:/devel/qt-rust-test01/qt_gui)
     Running `D:\devel\qt-rust-test01\target\debug\build\qt_gui-4cb0bd8ab8a54939
\build-script-build`
   Compiling qt_core v0.1.5 (file:///D:/devel/qt-rust-test01/qt_core)
     Running `rustc --crate-name qt_core qt_core\src\lib.rs --crate-type lib --e
mit=dep-info,link -C debuginfo=2 -C metadata=c487475031745cd9 -C extra-filename=
-c487475031745cd9 --out-dir D:\devel\qt-rust-test01\target\debug\deps -L depende
ncy=D:\devel\qt-rust-test01\target\debug\deps --extern cpp_utils=D:\devel\qt-rus
t-test01\target\debug\deps\libcpp_utils-b667ad60ea3500de.rlib --extern libc=D:\d
evel\qt-rust-test01\target\debug\deps\liblibc-026076ef8cc90032.rlib -L native=C:
/Qt/Qt5.6.2/5.6/msvc2015_64/lib -L native=D:\devel\qt-rust-test01\target\debug\b
uild\qt_core-ec07a1a733c9474e\out\c_lib_install\lib -l Qt5Core`
error: no associated item named `connect_static` found for type `object::Object`
 in the current scope
  --> qt_core\src\connections.rs:47:7
   |
47 |       ::object::Object::connect_static((self.object() as *const ::object::O
bject,
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `qt_core`.

Caused by:
  process didn't exit successfully: `rustc --crate-name qt_core qt_core\src\lib.
rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=c48747503174
5cd9 -C extra-filename=-c487475031745cd9 --out-dir D:\devel\qt-rust-test01\targe
t\debug\deps -L dependency=D:\devel\qt-rust-test01\target\debug\deps --extern cp
p_utils=D:\devel\qt-rust-test01\target\debug\deps\libcpp_utils-b667ad60ea3500de.
rlib --extern libc=D:\devel\qt-rust-test01\target\debug\deps\liblibc-026076ef8cc
90032.rlib -L native=C:/Qt/Qt5.6.2/5.6/msvc2015_64/lib -L native=D:\devel\qt-rus
t-test01\target\debug\build\qt_core-ec07a1a733c9474e\out\c_lib_install\lib -l Qt
5Core` (exit code: 101)
Build failed, waiting for other jobs to finish...

Rust: rustc 1.17.0 (56124baa9 2017-04-24) (MSVC) Cargo: cargo 0.18.0 (fe7b0cdcf 2017-04-24) Clang: 4.0.0 Target: x86_64-pc-windows-msvc Qt: 5.6.2 MSVC: 2017

Generated files: https://gist.github.com/o01eg/f09189548669594c263ed1ee5b823d47

cpp_to_rust revision: 0d4cd5323156

o01eg commented 7 years ago

Same for Gentoo Linux with: Rust: 1.19.0-dev (1d468400f 2017-05-11) and 1.16.0 Cargo: 0.20.0-dev (58fe1a8 2017-05-10) Clang: 3.9.1 tagret: x86_64-pc-linux-gnu Qt: 5.6.2

Riateche commented 7 years ago

Thanks for the report! Looks like the generator couldn't generate wrappers for QObject::connect methods. Unfortunately I wasn't able to reproduce the issue with Qt 5.6.2 on Linux, so I don't know why it's happening.

Can you pull the latest version and run the generator with --debug-logging=save? The logs will be saved to log subdirectory of the cache directory and should explain why the methods were skipped.

o01eg commented 7 years ago

There is log content for qt_core: http://dump.lexs.blasux.ru/files/wunelid/log.7z Revision 61740cfd34 rustc 1.19.0-dev (fa78d5bb8 2017-05-16) cargo 0.20.0-dev (8e35fd7d 2017-05-16)

Riateche commented 7 years ago

Thanks! I see that clang parser returns some strange results. I'll get clang 3.9 and 4.0 and look into the issue. Meanwhile, you can try to use clang 3.8 and see if it helps.

o01eg commented 7 years ago

I've tried clang 3.8.1 on windows and get next error:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits:524:45: error: '_To' does not refer to a value
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits:524:50: error: '_From' does not refer to a value
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\type_traits:525:2: error: expected class name

Same as http://boost.2283326.n4.nabble.com/Using-Boost-with-VS-14-0-update-3-RC-and-Clang-3-8-0-from-CodeBlocks-IDE-compile-fails-in-MS-type-tre-td4687018.html

Still I need -fms-compatibility-version=19 flag.

On linux there no stable clang 3.8 so it would be trouble to downgrade clang.

o01eg commented 7 years ago

Little patch for cpp_to_rust/cpp_to_rust_generator/src/cpp_parser.rs generates correct code for Linux.

      TypeKind::Elaborated => {
          let canonical = type1.get_canonical_type();
          if canonical.get_kind() != TypeKind::Elaborated {
              self.parse_type(canonical, context_class, context_method)
          } else {
              Err(format!("Elaborated type: {:?}. Canonical: {:?}", type1, canonical).into())
          }
      }
      _ => Err(format!("Unsupported kind of type: {:?}. {:?}", type1.get_kind(), type1).into()),
o01eg commented 7 years ago

On windows I get runtime error aboutn missing entry point for ?toLower@QByteArray@@QEGBA?AV1@XZ in qt_core_c.dll. Demangled name is

public: class QByteArray __cdecl QByteArray::toLower(void)const __ptr64&
o01eg commented 6 years ago

Looks like it was caused by DLL hell so it should be fixed now.