rust-qt / ritual

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

Automatically detect inaccessible methods by trying to compile them #24

Closed Riateche closed 5 years ago

Riateche commented 8 years ago

Some methods are inaccessible even if they are declared in the library's header. The most common cases:

  1. A template method can use a method of a template type that may not be present, e.g. QVector<T>::contains will not compile if T does not have operator==.
  2. Template partial specialization can remove any methods for any template type, e.g. QFuture<void>::result is removed.
  3. A method can simply be left without implementation. Any attempt to use it will only fail on link stage with "undefined reference" error. In Qt, it's qt_check_for_QGADGET_macro method that is used only for template magic but has no implementation.

Currently the only way to fix it is to add all wrong methods to the blacklist in the lib spec. This is a very inconvenient way if there are a lot of methods.

Solution:

  1. Implement preliminary generation of small C++ projects for each method.
  2. Try to compile the projects and remove methods that don't compile.
  3. Add a lib spec field for a reference method that should always be available. This method will be tested before all others to check if the toolchain and environment are set up correctly for compiling.
  4. Drop the complicated code responsible for eliminating methods in favor of just testing if they compile. This may include complicated inheritance exceptions and abstract class constructors.

Template methods are currently not supported because they induce too many template instantiation errors. Automatic detection would allow to enable them.

Riateche commented 5 years ago

Done.