mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Make it possible to opt out of the default rendering backend selection
The default backend does not select any features or backends by default on the Cargo.toml feature level. And with this change it also doesn't do that anymore based on the target platform. That means if the rust api crate is built with default-features = false, no backend will be selected and the user has to take care of backend initialization through other means. The feature defaults, generally, are in the rust API crate, the interpreter crate and C++ CMakeLists.txt. The latter triggers a cargo build of sixtyfps-cpp with --no-default-features. However the cpp_test job in the CI doesn't build sixtyfps-cpp with CMake but instead calls cargo directly. Therefore the defaults are now also coded in the sixtyfps-cpp Cargo.toml, to ensure that *a* rendering backend is chosen (since the cfg.target bit is gone).
This commit is contained in:
parent
231d46bd69
commit
8f940a446e
3 changed files with 45 additions and 41 deletions
|
@ -26,6 +26,7 @@ backend-gl = ["sixtyfps-rendering-backend-default/sixtyfps-rendering-backend-gl"
|
|||
backend-qt = ["sixtyfps-rendering-backend-default/sixtyfps-rendering-backend-qt"]
|
||||
# Enable some function used by the integration tests
|
||||
testing = ["sixtyfps-rendering-backend-testing"]
|
||||
default = ["backend-gl", "x11", "backend-qt"]
|
||||
|
||||
[dependencies]
|
||||
sixtyfps-corelib = { version = "=0.1.5", path="../../sixtyfps_runtime/corelib", features = ["ffi"] }
|
||||
|
|
|
@ -21,11 +21,3 @@ sixtyfps-rendering-backend-gl = { version = "=0.1.5", path = "../gl", optional =
|
|||
sixtyfps-rendering-backend-qt = { version = "=0.1.5", path = "../qt", optional = true }
|
||||
cfg-if = "1"
|
||||
once_cell = "1.5"
|
||||
|
||||
# Desktop platform uses the Qt backend by default
|
||||
[target.'cfg(any(target_os="windows", target_os="macos", target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))'.dependencies]
|
||||
sixtyfps-rendering-backend-qt = { version = "=0.1.5", path = "../qt" }
|
||||
|
||||
# Other platform uses the Gl backend
|
||||
[target.'cfg(not(any(target_os="windows", target_os="macos", target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))'.dependencies]
|
||||
sixtyfps-rendering-backend-gl = { version = "=0.1.5", path = "../gl" }
|
||||
|
|
|
@ -27,19 +27,20 @@ In order for the crate to be available at runtime, they need to be added as feat
|
|||
#![doc(html_logo_url = "https://sixtyfps.io/resources/logo.drawio.svg")]
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(any(target_os="windows", target_os="macos", target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd"))] {
|
||||
if #[cfg(feature = "sixtyfps-rendering-backend-qt")] {
|
||||
use sixtyfps_rendering_backend_qt as default_backend;
|
||||
} else {
|
||||
} else if #[cfg(feature = "sixtyfps-rendering-backend-gl")] {
|
||||
use sixtyfps_rendering_backend_gl as default_backend;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn backend() -> &'static dyn sixtyfps_corelib::backend::Backend {
|
||||
sixtyfps_corelib::backend::instance_or_init(|| {
|
||||
#[cfg(any(
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(any(
|
||||
feature = "sixtyfps-rendering-backend-qt",
|
||||
feature = "sixtyfps-rendering-backend-gl"
|
||||
))]
|
||||
))] {
|
||||
pub fn backend() -> &'static dyn sixtyfps_corelib::backend::Backend {
|
||||
sixtyfps_corelib::backend::instance_or_init(|| {
|
||||
let backend_config = std::env::var("SIXTYFPS_BACKEND").unwrap_or_default();
|
||||
|
||||
#[cfg(feature = "sixtyfps-rendering-backend-qt")]
|
||||
|
@ -64,20 +65,30 @@ pub fn backend() -> &'static dyn sixtyfps_corelib::backend::Backend {
|
|||
// If Qt is not available always fallback to Gl
|
||||
return Box::new(sixtyfps_rendering_backend_gl::Backend);
|
||||
}
|
||||
|
||||
Box::new(default_backend::Backend)
|
||||
})
|
||||
}
|
||||
|
||||
pub use default_backend::{
|
||||
}
|
||||
pub use default_backend::{
|
||||
native_widgets, Backend, NativeGlobals, NativeWidgets, HAS_NATIVE_STYLE,
|
||||
};
|
||||
};
|
||||
} else {
|
||||
pub fn backend() -> &'static dyn sixtyfps_corelib::backend::Backend {
|
||||
sixtyfps_corelib::backend::instance().expect("no default backend configured, the backend must be initialized manually")
|
||||
}
|
||||
|
||||
pub type NativeWidgets = ();
|
||||
pub type NativeGlobals = ();
|
||||
pub mod native_widgets {}
|
||||
pub const HAS_NATIVE_STYLE: bool = false;
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[cold]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn use_modules() {
|
||||
sixtyfps_corelib::use_modules();
|
||||
default_backend::use_modules();
|
||||
#[cfg(feature = "sixtyfps-rendering-backend-qt")]
|
||||
sixtyfps_rendering_backend_qt::use_modules();
|
||||
#[cfg(feature = "sixtyfps-rendering-backend-gl")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue