| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | use std::path::Path; |
| 5 | |
| 6 | fn main() { |
| 7 | println!("cargo:rustc-check-cfg=cfg(no_qt)" ); |
| 8 | |
| 9 | // This is part code tries to detect automatically what default style to use and tries to |
| 10 | // use the native style automatically if Qt is available. |
| 11 | // |
| 12 | // The way this work is this |
| 13 | // 1. `qttypes`' crate's build script already detects Qt and set the DEP_QT_VERSION |
| 14 | // 2. The qt rendering backend's build script will check if the qttype crates found Qt and |
| 15 | // look at the SLINT_NO_QT env variable, and sets the DEP_i_slint_backend_qt_SUPPORTS_NATIVE_STYLE |
| 16 | // env variable so that the default rendering backend can know if Qt was there. |
| 17 | // 3. here, in the default rendering backend, we know if we depends on the qt backend and if it |
| 18 | // has set the DEP_i_slint_backend_qt_SUPPORTS_NATIVE_STYLE env variable. |
| 19 | // We then write a file in the build directory with the default style that depends on the |
| 20 | // Qt availability |
| 21 | // 4a. When using the slint-build crate from a build script, it will be able to read this file |
| 22 | // from `slint_build::compile_with_config` |
| 23 | // 4b. Same when using the `slint!` macro, |
| 24 | |
| 25 | let has_native_style = |
| 26 | std::env::var("DEP_I_SLINT_BACKEND_QT_SUPPORTS_NATIVE_STYLE" ).unwrap_or_default() == "1" ; |
| 27 | |
| 28 | if !has_native_style { |
| 29 | println!("cargo:rustc-cfg=no_qt" ); |
| 30 | } |
| 31 | |
| 32 | let style = i_slint_common::get_native_style( |
| 33 | has_native_style, |
| 34 | &std::env::var("TARGET" ).unwrap_or_default(), |
| 35 | ); |
| 36 | let out_dir = std::env::var_os("OUT_DIR" ).unwrap(); |
| 37 | // out_dir is something like |
| 38 | // <target_dir>/build/i-slint-backend-selector-1fe5c4ab61eb0584/out |
| 39 | // and we want to write to a common directory, so write in the build/ dir |
| 40 | let target_path = |
| 41 | Path::new(&out_dir).parent().unwrap().parent().unwrap().join("SLINT_DEFAULT_STYLE.txt" ); |
| 42 | std::fs::write(target_path, style).unwrap(); |
| 43 | } |
| 44 | |