Skip to content

Commit e4037e1

Browse files
committed
cxx-qt-lib: use cxx-qt-build to build rather than cxx
1 parent 0c2b6de commit e4037e1

File tree

2 files changed

+38
-49
lines changed

2 files changed

+38
-49
lines changed

crates/cxx-qt-lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ time = { version = "0.3.20", optional = true }
2424
url = { version = "2.3", optional = true }
2525

2626
[build-dependencies]
27-
cxx-build.workspace = true
27+
cxx-qt-build.workspace = true
2828
qt-build-utils.workspace = true
2929

3030
[features]

crates/cxx-qt-lib/build.rs

+37-48
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

6+
use cxx_qt_build::CxxQtBuilder;
7+
use qt_build_utils::QtBuild;
8+
69
fn main() {
710
let feature_qt_gui_enabled = std::env::var("CARGO_FEATURE_QT_GUI").is_ok();
811
let feature_qt_qml_enabled = std::env::var("CARGO_FEATURE_QT_QML").is_ok();
@@ -11,24 +14,26 @@ fn main() {
1114
Err(_) => false,
1215
};
1316

14-
let mut qt_modules = vec!["Core".to_owned()];
17+
let mut builder = CxxQtBuilder::new();
18+
// Not strictly required to enable modules as the feature should do this
19+
// build lets be explicit for now.
1520
if feature_qt_gui_enabled {
16-
qt_modules.push("Gui".to_owned());
21+
builder = builder.qt_module("Gui");
1722
}
1823
if feature_qt_qml_enabled {
19-
qt_modules.push("Qml".to_owned());
24+
builder = builder.qt_module("Qml");
2025
}
2126

22-
let qtbuild = qt_build_utils::QtBuild::new(qt_modules).expect("Could not find Qt installation");
23-
24-
// Required for tests
25-
qt_build_utils::setup_linker();
26-
2727
// Find the Qt version and tell the Rust compiler
2828
// this allows us to have conditional Rust code
29+
//
30+
// TODO: is this useful to have in cxx-qt-build?
2931
println!(
3032
"cargo:rustc-cfg=qt_version_major=\"{}\"",
31-
qtbuild.version().major
33+
QtBuild::new(vec!())
34+
.expect("Could not find Qt installation")
35+
.version()
36+
.major
3237
);
3338

3439
let mut rust_bridges = vec![
@@ -188,15 +193,10 @@ fn main() {
188193
]);
189194
}
190195

191-
for bridge in &rust_bridges {
192-
println!("cargo:rerun-if-changed=src/{bridge}.rs");
196+
for rust_source in &rust_bridges {
197+
builder = builder.file(format!("src/{rust_source}.rs"));
193198
}
194199

195-
let mut builder =
196-
cxx_build::bridges(rust_bridges.iter().map(|bridge| format!("src/{bridge}.rs")));
197-
198-
qtbuild.cargo_link_libraries(&mut builder);
199-
200200
let mut cpp_files = vec![
201201
"core/qbytearray",
202202
"core/qcoreapplication",
@@ -251,12 +251,14 @@ fn main() {
251251
cpp_files.extend(["core/qdatetime", "core/qtimezone"]);
252252
}
253253

254-
for cpp_file in &cpp_files {
255-
builder.file(format!("src/{cpp_file}.cpp"));
256-
println!("cargo:rerun-if-changed=src/{cpp_file}.cpp");
257-
}
258-
builder.file("src/qt_types.cpp");
259-
println!("cargo:rerun-if-changed=src/qt_types.cpp");
254+
builder = builder.cc_builder(move |cc| {
255+
for cpp_file in &cpp_files {
256+
cc.file(format!("src/{cpp_file}.cpp"));
257+
println!("cargo:rerun-if-changed=src/{cpp_file}.cpp");
258+
}
259+
cc.file("src/qt_types.cpp");
260+
println!("cargo:rerun-if-changed=src/qt_types.cpp");
261+
});
260262
println!("cargo:rerun-if-changed=src/assertion_utils.h");
261263

262264
fn copy_dir(src: impl AsRef<std::path::Path>, dest: impl AsRef<std::path::Path>) {
@@ -291,33 +293,20 @@ fn main() {
291293
)
292294
.expect("could not copy common.h");
293295

294-
// Load the include paths
295-
//
296-
// TODO: note once we use cxx-qt-build we don't need to include the Qt paths here
297-
builder.includes(qtbuild.include_paths());
298-
builder.include(include_out_dir);
299-
300-
// Enable Qt Gui in C++ if the feature is enabled
301-
if feature_qt_gui_enabled {
302-
builder.define("CXX_QT_GUI_FEATURE", None);
303-
}
296+
builder = builder.cc_builder(|cc| {
297+
// Load the include path
298+
cc.include(&include_out_dir);
304299

305-
// Enable Qt Qml in C++ if the feature is enabled
306-
if feature_qt_gui_enabled {
307-
builder.define("CXX_QT_QML_FEATURE", None);
308-
}
300+
// Enable Qt Gui in C++ if the feature is enabled
301+
if feature_qt_gui_enabled {
302+
cc.define("CXX_QT_GUI_FEATURE", None);
303+
}
309304

310-
// Note, ensure our settings stay in sync across cxx-qt-build and cxx-qt-lib
311-
builder.cpp(true);
312-
// MSVC
313-
builder.flag_if_supported("/std:c++17");
314-
builder.flag_if_supported("/Zc:__cplusplus");
315-
builder.flag_if_supported("/permissive-");
316-
builder.flag_if_supported("/bigobj");
317-
// GCC + Clang
318-
builder.flag_if_supported("-std=c++17");
319-
// MinGW requires big-obj otherwise debug builds fail
320-
builder.flag_if_supported("-Wa,-mbig-obj");
305+
// Enable Qt Qml in C++ if the feature is enabled
306+
if feature_qt_gui_enabled {
307+
cc.define("CXX_QT_QML_FEATURE", None);
308+
}
309+
});
321310

322-
builder.compile("cxx-qt-lib");
311+
builder.build();
323312
}

0 commit comments

Comments
 (0)