Skip to content

Commit 0328fc3

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 bf73f64 commit 0328fc3

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
@@ -400,7 +400,7 @@ impl CxxQtBuilder {
400400

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

405405
// Write cxx-qt-lib and cxx headers
406406
cxx_qt_lib_headers::write_headers(format!("{header_root}/cxx-qt-lib"));

crates/cxx-qt-lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ qt_gui = ["cxx-qt-lib-headers/qt_gui"]
3939
qt_qml = ["cxx-qt-lib-headers/qt_qml"]
4040
time = ["dep:time"]
4141
url = ["dep:url"]
42+
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
@@ -16,7 +16,7 @@ fn main() {
1616
}
1717

1818
let qtbuild = qt_build_utils::QtBuild::new(qt_modules).expect("Could not find Qt installation");
19-
qtbuild.cargo_link_libraries(None);
19+
2020
// Required for tests
2121
qt_build_utils::setup_linker();
2222

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

185+
qtbuild.cargo_link_libraries(&mut builder);
186+
185187
let mut cpp_files = vec![
186188
"core/qbytearray",
187189
"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)