Struct qt_build_utils::QtBuild

source ·
pub struct QtBuild { /* private fields */ }
Expand description

Helper for build.rs scripts using Qt

let qt_modules = vec!["Core", "Gui"]
    .iter()
    .map(|m| String::from(*m))
    .collect();
let qtbuild = qt_build_utils::QtBuild::new(qt_modules).expect("Could not find Qt installation");

Implementations

Search for where Qt is installed using qmake. Specify the Qt modules you are linking with the qt_modules parameter, ommitting the Qt prefix ("Core" rather than "QtCore"). After construction, use the QtBuild::qmake_query method to get information about the Qt installation.

The directories specified by the PATH environment variable are where qmake is searched for. Alternatively, the QMAKE environment variable may be set to specify an explicit path to qmake.

If multiple major versions (for example, 5 and 6) of Qt could be installed, set the QT_VERSION_MAJOR environment variable to force which one to use. When using Cargo as the build system for the whole build, prefer using QT_VERSION_MAJOR over the QMAKE environment variable because it will account for different names for the qmake executable that some Linux distributions use.

However, when building a Rust staticlib that gets linked to C++ code by a C++ build system, it is best to use the QMAKE environment variable to ensure that the Rust staticlib is linked to the same installation of Qt that the C++ build system has detected. With CMake, you can get this from the Qt::qmake target’s IMPORTED_LOCATION property, for example:

find_package(Qt6 COMPONENTS Core)
if(NOT Qt6_FOUND)
    find_package(Qt5 5.15 COMPONENTS Core REQUIRED)
endif()
get_target_property(QMAKE Qt::qmake IMPORTED_LOCATION)

execute_process(
    COMMAND cmake -E env
        "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}/cargo"
        "QMAKE=${QMAKE}"
        cargo build
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

Get the output of running qmake -query var_name

Tell Cargo to link each Qt module.

Get the include paths for Qt, including Qt module subdirectories. This is intended to be passed to whichever tool you are using to invoke the C++ compiler.

Version of the detected Qt installation

Run moc on a C++ header file and save the output into cargo’s OUT_DIR. The path to the generated C++ file is returned, which can then be passed to cc::Build::files.

Run rcc on a .qrc file and save the output into cargo’s OUT_DIR. The path to the generated C++ file is returned, which can then be passed to cc::Build::files.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.