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§

source§

impl QtBuild

source

pub fn new(qt_modules: Vec<String>) -> Result<Self, QtBuildError>

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}
)
source

pub fn qmake_query(&self, var_name: &str) -> String

Get the output of running qmake -query var_name

Tell Cargo to link each Qt module.

source

pub fn include_paths(&self) -> Vec<PathBuf>

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.

source

pub fn version(&self) -> &SemVer

Version of the detected Qt installation

source

pub fn moc( &mut self, input_file: impl AsRef<Path>, uri: Option<&str> ) -> MocProducts

Run moc on a C++ header file and save the output into cargo’s OUT_DIR. The return value contains the path to the generated C++ file, which can then be passed to cc::Build::files, as well as the path to the generated metatypes.json file, which can be passed to register_qml_module.

  • uri - Should be passed if the input_file is part of a QML module
source

pub fn register_qml_module( &mut self, metatypes_json: &[impl AsRef<Path>], uri: &str, version_major: usize, version_minor: usize, plugin_name: &str, qml_files: &[impl AsRef<Path>], qrc_files: &[impl AsRef<Path>] ) -> QmlModuleRegistrationFiles

Generate C++ files to automatically register a QML module at build time using the JSON output from moc.

This generates a qmldir file for the QML module. The qml_files and qrc_files are registered with the Qt Resource System in the default QML import path qrc:/qt/qml/uri/of/module/.

When using Qt 6, this will run qmlcachegen to compile the specified .qml files ahead-of-time.

source

pub fn qrc(&mut self, input_file: &impl AsRef<Path>) -> PathBuf

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. The compiled static library must be linked with +whole-archive or the linker will discard the generated static variables because they are not referenced from main.

source

pub fn qrc_list(&mut self, input_file: &impl AsRef<Path>) -> Vec<PathBuf>

Run rcc on a .qrc file and return the paths of the sources

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.