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 ;
6
8
use std:: { fs:: File , io:: Write } ;
7
9
8
10
fn main ( ) {
@@ -13,24 +15,26 @@ fn main() {
13
15
Err ( _) => false ,
14
16
} ;
15
17
16
- let mut qt_modules = vec ! [ "Core" . to_owned( ) ] ;
18
+ let mut builder = CxxQtBuilder :: new ( ) ;
19
+ // Not strictly required to enable modules as the feature should do this
20
+ // build lets be explicit for now.
17
21
if feature_qt_gui_enabled {
18
- qt_modules . push ( "Gui" . to_owned ( ) ) ;
22
+ builder = builder . qt_module ( "Gui" ) ;
19
23
}
20
24
if feature_qt_qml_enabled {
21
- qt_modules . push ( "Qml" . to_owned ( ) ) ;
25
+ builder = builder . qt_module ( "Qml" ) ;
22
26
}
23
27
24
- let qtbuild = qt_build_utils:: QtBuild :: new ( qt_modules) . expect ( "Could not find Qt installation" ) ;
25
-
26
- // Required for tests
27
- qt_build_utils:: setup_linker ( ) ;
28
-
29
28
// Find the Qt version and tell the Rust compiler
30
29
// this allows us to have conditional Rust code
30
+ //
31
+ // TODO: is this useful to have in cxx-qt-build?
31
32
println ! (
32
33
"cargo:rustc-cfg=qt_version_major=\" {}\" " ,
33
- qtbuild. version( ) . major
34
+ QtBuild :: new( vec!( ) )
35
+ . expect( "Could not find Qt installation" )
36
+ . version( )
37
+ . major
34
38
) ;
35
39
36
40
let mut rust_bridges = vec ! [
@@ -189,15 +193,10 @@ fn main() {
189
193
] ) ;
190
194
}
191
195
192
- for bridge in & rust_bridges {
193
- println ! ( "cargo:rerun-if-changed= src/{bridge }.rs" ) ;
196
+ for rust_source in & rust_bridges {
197
+ builder = builder . file ( format ! ( "src/{rust_source }.rs" ) ) ;
194
198
}
195
199
196
- let mut builder =
197
- cxx_build:: bridges ( rust_bridges. iter ( ) . map ( |bridge| format ! ( "src/{bridge}.rs" ) ) ) ;
198
-
199
- qtbuild. cargo_link_libraries ( & mut builder) ;
200
-
201
200
let mut cpp_files = vec ! [
202
201
"core/qbytearray" ,
203
202
"core/qcoreapplication" ,
@@ -251,12 +250,14 @@ fn main() {
251
250
cpp_files. extend ( [ "core/qdatetime" , "core/qtimezone" ] ) ;
252
251
}
253
252
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" ) ;
253
+ builder = builder. cc_builder ( move |cc| {
254
+ for cpp_file in & cpp_files {
255
+ cc. file ( format ! ( "src/{cpp_file}.cpp" ) ) ;
256
+ println ! ( "cargo:rerun-if-changed=src/{cpp_file}.cpp" ) ;
257
+ }
258
+ cc. file ( "src/qt_types.cpp" ) ;
259
+ println ! ( "cargo:rerun-if-changed=src/qt_types.cpp" ) ;
260
+ } ) ;
260
261
println ! ( "cargo:rerun-if-changed=src/assertion_utils.h" ) ;
261
262
262
263
// Write this library's manually written C++ headers to files and add them to include paths
@@ -275,33 +276,20 @@ fn main() {
275
276
write ! ( header, "{file_contents}" ) . expect ( "Could not write header: {h_path}" ) ;
276
277
}
277
278
278
- // Load the include paths
279
- //
280
- // TODO: note once we use cxx-qt-build we don't need to include the Qt paths here
281
- builder. includes ( qtbuild. include_paths ( ) ) ;
282
- builder. include ( header_root) ;
283
-
284
- // Enable Qt Gui in C++ if the feature is enabled
285
- if feature_qt_gui_enabled {
286
- builder. define ( "CXX_QT_GUI_FEATURE" , None ) ;
287
- }
279
+ builder = builder. cc_builder ( |cc| {
280
+ // Load the include path
281
+ cc. include ( & header_root) ;
288
282
289
- // Enable Qt Qml in C++ if the feature is enabled
290
- if feature_qt_gui_enabled {
291
- builder . define ( "CXX_QT_QML_FEATURE " , None ) ;
292
- }
283
+ // Enable Qt Gui in C++ if the feature is enabled
284
+ if feature_qt_gui_enabled {
285
+ cc . define ( "CXX_QT_GUI_FEATURE " , None ) ;
286
+ }
293
287
294
- // Note, ensure our settings stay in sync across cxx-qt, cxx-qt-build, and cxx-qt-lib
295
- builder. cpp ( true ) ;
296
- // MSVC
297
- builder. flag_if_supported ( "/std:c++17" ) ;
298
- builder. flag_if_supported ( "/Zc:__cplusplus" ) ;
299
- builder. flag_if_supported ( "/permissive-" ) ;
300
- builder. flag_if_supported ( "/bigobj" ) ;
301
- // GCC + Clang
302
- builder. flag_if_supported ( "-std=c++17" ) ;
303
- // MinGW requires big-obj otherwise debug builds fail
304
- builder. flag_if_supported ( "-Wa,-mbig-obj" ) ;
288
+ // Enable Qt Qml in C++ if the feature is enabled
289
+ if feature_qt_gui_enabled {
290
+ cc. define ( "CXX_QT_QML_FEATURE" , None ) ;
291
+ }
292
+ } ) ;
305
293
306
- builder. compile ( "cxx-qt-lib" ) ;
294
+ builder. build ( ) ;
307
295
}
0 commit comments