Skip to content

Commit 7815508

Browse files
committed
qt-build-utils: use cc::Build insteaed of Option<cc::Build>
Whether to link the .o files is now controlled by a Cargo option, not the calling code.
1 parent d0bab9c commit 7815508

File tree

5 files changed

+12
-13
lines changed

5 files changed

+12
-13
lines changed

crates/cxx-qt-build/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ impl CxxQtBuilder {
399399

400400
let mut qtbuild = qt_build_utils::QtBuild::new(self.qt_modules.into_iter().collect())
401401
.expect("Could not find Qt installation");
402-
qtbuild.cargo_link_libraries(Some(&mut self.cc_builder));
402+
qtbuild.cargo_link_libraries(&mut self.cc_builder);
403403

404404
// Write cxx-qt-gen, cxx-qt-lib and cxx headers
405405
cxx_qt_gen::write_headers(format!("{header_root}/cxx-qt-common"));

crates/cxx-qt-lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ qt_gui = ["cxx-qt-lib-headers/qt_gui"]
4040
qt_qml = ["cxx-qt-lib-headers/qt_qml"]
4141
time = ["dep:time"]
4242
url = ["dep:url"]
43+
link_qt_object_files = ["qt-build-utils/link_qt_object_files"]

crates/cxx-qt-lib/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
}
2121

2222
let qtbuild = qt_build_utils::QtBuild::new(qt_modules).expect("Could not find Qt installation");
23-
qtbuild.cargo_link_libraries(None);
23+
2424
// Required for tests
2525
qt_build_utils::setup_linker();
2626

@@ -192,6 +192,8 @@ fn main() {
192192
let mut builder =
193193
cxx_build::bridges(rust_bridges.iter().map(|bridge| format!("src/{bridge}.rs")));
194194

195+
qtbuild.cargo_link_libraries(&mut builder);
196+
195197
let mut cpp_files = vec![
196198
"core/qbytearray",
197199
"core/qcoreapplication",

crates/qt-build-utils/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl QtBuild {
313313
lib_path: &str,
314314
link_lib: &str,
315315
prl_path: &str,
316-
builder: &mut Option<&mut cc::Build>,
316+
builder: &mut cc::Build,
317317
) {
318318
println!("cargo:rustc-link-lib={link_lib}");
319319

@@ -376,7 +376,7 @@ impl QtBuild {
376376
}
377377

378378
/// Tell Cargo to link each Qt module.
379-
pub fn cargo_link_libraries(&self, mut builder: Option<&mut cc::Build>) {
379+
pub fn cargo_link_libraries(&self, builder: &mut cc::Build) {
380380
let prefix_path = self.qmake_query("QT_INSTALL_PREFIX");
381381
let lib_path = self.qmake_query("QT_INSTALL_LIBS");
382382
println!("cargo:rustc-link-search={lib_path}");
@@ -423,7 +423,7 @@ impl QtBuild {
423423
&lib_path,
424424
&link_lib,
425425
&prl_path,
426-
&mut builder,
426+
builder,
427427
);
428428
}
429429

@@ -440,7 +440,7 @@ impl QtBuild {
440440
&lib_path,
441441
"qwasm",
442442
&format!("{platforms_path}/libqwasm.prl"),
443-
&mut builder,
443+
builder,
444444
);
445445
}
446446
}

crates/qt-build-utils/src/parse_cflags.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ fn split_flags(link_args: &[u8]) -> Vec<String> {
109109
words
110110
}
111111

112-
pub(crate) fn parse_libs_cflags(
113-
name: &str,
114-
link_args: &[u8],
115-
_builder: &mut Option<&mut cc::Build>,
116-
) {
112+
pub(crate) fn parse_libs_cflags(name: &str, link_args: &[u8], _builder: &mut cc::Build) {
117113
let mut is_msvc = false;
118114
let target = env::var("TARGET");
119115
if let Ok(target) = &target {
@@ -178,7 +174,7 @@ pub(crate) fn parse_libs_cflags(
178174
let file_name = file_name.to_string_lossy();
179175
if file_name.ends_with(".o") {
180176
#[cfg(feature = "link_qt_object_files")]
181-
if let Some(builder) = _builder {
177+
{
182178
let path_string = path.to_string_lossy().to_string();
183179
unsafe {
184180
// Linking will fail with duplicate symbol errors if the same .o file is linked twice.
@@ -192,7 +188,7 @@ pub(crate) fn parse_libs_cflags(
192188
// https://github.com/rust-lang/rust/issues/99427#issuecomment-1562092085
193189
// TODO: remove builder argument when it's not used anymore to link object files.
194190
// also remove the dependency on cc when this is done
195-
builder.object(path);
191+
_builder.object(path);
196192
}
197193
LINKED_OBJECT_FILES.get_mut().unwrap().insert(path_string);
198194
}

0 commit comments

Comments
 (0)