3
3
//
4
4
// SPDX-License-Identifier: MIT OR Apache-2.0
5
5
6
+ use cxx_qt_build:: CxxQtBuilder ;
7
+ use qt_build_utils:: QtBuild ;
8
+
6
9
fn main ( ) {
7
10
let feature_qt_gui_enabled = std:: env:: var ( "CARGO_FEATURE_QT_GUI" ) . is_ok ( ) ;
8
11
let feature_qt_qml_enabled = std:: env:: var ( "CARGO_FEATURE_QT_QML" ) . is_ok ( ) ;
@@ -11,24 +14,26 @@ fn main() {
11
14
Err ( _) => false ,
12
15
} ;
13
16
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.
15
20
if feature_qt_gui_enabled {
16
- qt_modules . push ( "Gui" . to_owned ( ) ) ;
21
+ builder = builder . qt_module ( "Gui" ) ;
17
22
}
18
23
if feature_qt_qml_enabled {
19
- qt_modules . push ( "Qml" . to_owned ( ) ) ;
24
+ builder = builder . qt_module ( "Qml" ) ;
20
25
}
21
26
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
-
27
27
// Find the Qt version and tell the Rust compiler
28
28
// this allows us to have conditional Rust code
29
+ //
30
+ // TODO: is this useful to have in cxx-qt-build?
29
31
println ! (
30
32
"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
32
37
) ;
33
38
34
39
let mut rust_bridges = vec ! [
@@ -188,15 +193,10 @@ fn main() {
188
193
] ) ;
189
194
}
190
195
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" ) ) ;
193
198
}
194
199
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
-
200
200
let mut cpp_files = vec ! [
201
201
"core/qbytearray" ,
202
202
"core/qcoreapplication" ,
@@ -251,12 +251,14 @@ fn main() {
251
251
cpp_files. extend ( [ "core/qdatetime" , "core/qtimezone" ] ) ;
252
252
}
253
253
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
+ } ) ;
260
262
println ! ( "cargo:rerun-if-changed=src/assertion_utils.h" ) ;
261
263
262
264
fn copy_dir ( src : impl AsRef < std:: path:: Path > , dest : impl AsRef < std:: path:: Path > ) {
@@ -291,33 +293,20 @@ fn main() {
291
293
)
292
294
. expect ( "could not copy common.h" ) ;
293
295
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) ;
304
299
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
+ }
309
304
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
+ } ) ;
321
310
322
- builder. compile ( "cxx-qt-lib" ) ;
311
+ builder. build ( ) ;
323
312
}
0 commit comments