From 142b55b055f9eea81f0f946acbd31ec24d5c6053 Mon Sep 17 00:00:00 2001 From: Andrew Hayzen Date: Tue, 10 Sep 2024 10:01:14 +0100 Subject: [PATCH] WIP: cxx-qt-build: use isolated cc::Build for QmlModules Closes #1065 --- crates/cxx-qt-build/src/lib.rs | 52 ++++++++++++++++------------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/crates/cxx-qt-build/src/lib.rs b/crates/cxx-qt-build/src/lib.rs index e81f3c670..6ad3bd5af 100644 --- a/crates/cxx-qt-build/src/lib.rs +++ b/crates/cxx-qt-build/src/lib.rs @@ -302,14 +302,13 @@ fn static_lib_name() -> String { format!("{}-cxxqt-generated", crate_name()) } -// TODO: useful once we have a cc_builder per qml_module -// fn qml_module_static_lib_name(module_uri: &str) -> String { -// format!( -// "{}-qml-module-{}-cxxqt-generated", -// crate_name(), -// module_name_from_uri(module_uri) -// ) -// } +fn qml_module_static_lib_name(module_uri: &str) -> String { + format!( + "{}-qml-module-{}-cxxqt-generated", + crate_name(), + module_name_from_uri(module_uri) + ) +} fn panic_duplicate_file_and_qml_module( path: impl AsRef, @@ -784,12 +783,12 @@ impl CxxQtBuilder { ); } - // TODO: for now we use the global CxxQtBuilder cc_builder + // TODO: for now we clone the global CxxQtBuilder cc_builder // this means that any includes/files etc on these are in this builder // but we cannot have separate builds until we can configure includes, // qt modules, files, cc_builder options etc in the QmlModule itself - let cc_builder = &mut self.cc_builder; - qtbuild.cargo_link_libraries(cc_builder); + let mut cc_builder = self.cc_builder.clone(); + qtbuild.cargo_link_libraries(&mut cc_builder); let mut moc_include_paths = HashSet::new(); for files in generate_cxxqt_cpp_files( @@ -882,23 +881,20 @@ impl CxxQtBuilder { dir::module_target(&qml_module.uri).join("plugin_init.o"), ); - // TODO: once we have a separate cc_builder per qml_module we will - // need to build the qml module here and link it - // - // // Build the QML module as a library - // if cc_builder.get_files().count() > 0 { - // let qml_library_name = qml_module_static_lib_name(&qml_module.uri); - - // // The linker argument order matters! - // // We need to link the object file first, then link the static library. - // // Otherwise, the linker will be unable to find the symbols in the static library file. - // // See also: https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc - // if !dir::is_exporting() { - // println!("cargo::rustc-link-arg=-l{}", &qml_library_name); - // } - - // cc_builder.compile(&qml_library_name); - // } + // Build the QML module as a library + if cc_builder.get_files().count() > 0 { + let qml_library_name = qml_module_static_lib_name(&qml_module.uri); + + // The linker argument order matters! + // We need to link the object file first, then link the static library. + // Otherwise, the linker will be unable to find the symbols in the static library file. + // See also: https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc + if !dir::is_exporting() { + println!("cargo::rustc-link-arg=-l{}", &qml_library_name); + } + + cc_builder.compile(&qml_library_name); + } } }