Clean up cfgs for Apple operating systems

Replace ios specific cfgs with "apple but not macOS", dubbed
ios_and_friends, so that we also cover iPadOS, etc.. What those have in
common is that they don't have user-resizable windows. (We might want to
add visionOs in the future)

Also, simplify a few macos or ios cfgs with just target_vendor =
"apple", for what applies to all the operating systems.
This commit is contained in:
Simon Hausmann 2025-05-09 15:42:02 +02:00 committed by Simon Hausmann
parent 24e24df737
commit bd0a486da8
14 changed files with 51 additions and 66 deletions

View file

@ -18,12 +18,7 @@ use i_slint_core::platform::PlatformError;
use crate::fullscreenwindowadapter::FullscreenWindowAdapter;
#[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_arch = "wasm32"
)))]
#[cfg(not(any(target_family = "windows", target_vendor = "apple", target_arch = "wasm32")))]
mod input;
#[derive(Clone)]

View file

@ -103,7 +103,7 @@ accesskit = { version = "0.19", optional = true }
accesskit_winit = { version = "0.27", optional = true }
copypasta = { version = "0.10", default-features = false }
[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32")))'.dependencies]
[target.'cfg(not(any(target_family = "windows", target_vendor = "apple", target_arch = "wasm32")))'.dependencies]
# Use same version and executor as accesskit
zbus = { version = "4.4.0", default-features = false, features = ["async-io"] }
futures = { version = "0.3.31" }

View file

@ -6,10 +6,11 @@ use cfg_aliases::cfg_aliases;
fn main() {
// Setup cfg aliases
cfg_aliases! {
ios_and_friends: { all(target_vendor = "apple", not(target_os = "macos"))},
enable_skia_renderer: { any(feature = "renderer-skia", feature = "renderer-skia-opengl", feature = "renderer-skia-vulkan")},
enable_accesskit: { all(feature = "accessibility", not(target_arch = "wasm32")) },
supports_opengl: { all(any(enable_skia_renderer, feature = "renderer-femtovg"), not(target_os = "ios")) },
use_winit_theme: { any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32") },
supports_opengl: { all(any(enable_skia_renderer, feature = "renderer-femtovg"), not(ios_and_friends)) },
use_winit_theme: { any(target_family = "windows", target_vendor = "apple", target_arch = "wasm32") },
muda: { all(feature = "muda", any(target_os = "windows", target_os = "macos")) },
}
// This uses `web_sys_unstable_api`, which is typically set via `RUST_FLAGS`

View file

@ -42,9 +42,8 @@ pub fn create_clipboard(
if #[cfg(all(
unix,
not(any(
target_os = "macos",
target_vendor = "apple",
target_os = "android",
target_os = "ios",
target_os = "emscripten"
))
))]

View file

@ -455,36 +455,34 @@ impl EventLoopState {
.ok_or_else(|| PlatformError::from("Nested event loops are not supported"))?;
let mut winit_loop = not_running_loop_instance;
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios")))]
{
use winit::platform::run_on_demand::EventLoopExtRunOnDemand as _;
winit_loop
.run_app_on_demand(&mut self)
.map_err(|e| format!("Error running winit event loop: {e}"))?;
cfg_if::cfg_if! {
if #[cfg(any(target_arch = "wasm32", ios_and_friends))] {
winit_loop
.run_app(&mut self)
.map_err(|e| format!("Error running winit event loop: {e}"))?;
// This can't really happen, as run() doesn't return
Ok(Self::new(self.shared_backend_data.clone()))
} else {
use winit::platform::run_on_demand::EventLoopExtRunOnDemand as _;
winit_loop
.run_app_on_demand(&mut self)
.map_err(|e| format!("Error running winit event loop: {e}"))?;
// Keep the EventLoop instance alive and re-use it in future invocations of run_event_loop().
// Winit does not support creating multiple instances of the event loop.
self.shared_backend_data.not_running_event_loop.replace(Some(winit_loop));
// Keep the EventLoop instance alive and re-use it in future invocations of run_event_loop().
// Winit does not support creating multiple instances of the event loop.
self.shared_backend_data.not_running_event_loop.replace(Some(winit_loop));
if let Some(error) = self.loop_error {
return Err(error);
if let Some(error) = self.loop_error {
return Err(error);
}
Ok(self)
}
Ok(self)
}
#[cfg(any(target_arch = "wasm32", target_os = "ios"))]
{
winit_loop
.run_app(&mut self)
.map_err(|e| format!("Error running winit event loop: {e}"))?;
// This can't really happen, as run() doesn't return
Ok(Self::new(self.shared_backend_data.clone()))
}
}
/// Runs the event loop and renders the items in the provided `component` in its
/// own window.
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios")))]
#[cfg(all(not(target_arch = "wasm32"), not(ios_and_friends)))]
pub fn pump_events(
mut self,
timeout: Option<std::time::Duration>,

View file

@ -600,7 +600,7 @@ impl i_slint_core::platform::Platform for Backend {
Ok(())
}
#[cfg(all(not(target_arch = "wasm32"), not(target_os = "ios")))]
#[cfg(all(not(target_arch = "wasm32"), not(ios_and_friends)))]
fn process_events(
&self,
timeout: core::time::Duration,
@ -765,7 +765,7 @@ mod testui {
}
// Sorry, can't test with rust test harness and multiple threads.
#[cfg(not(any(target_arch = "wasm32", target_os = "macos", target_os = "ios")))]
#[cfg(not(any(target_arch = "wasm32", target_vendor = "apple")))]
#[test]
fn test_window_accessor_and_rwh() {
slint::platform::set_platform(Box::new(crate::Backend::new().unwrap())).unwrap();

View file

@ -29,7 +29,7 @@ impl WinitSkiaRenderer {
})
}
#[cfg(not(target_os = "ios"))]
#[cfg(not(ios_and_friends))]
pub fn new_opengl_suspended(
shared_backend_data: &Rc<crate::SharedBackendData>,
) -> Box<dyn super::WinitCompatibleRenderer> {
@ -69,9 +69,9 @@ impl WinitSkiaRenderer {
Some(api) => {
match api {
RequestedGraphicsAPI::OpenGL(_) => {
#[cfg(not(target_os = "ios"))]
#[cfg(not(ios_and_friends))]
return Ok(Self::new_opengl_suspended);
#[cfg(target_os = "ios")]
#[cfg(ios_and_friends)]
return Err(format!(
"OpenGL rendering requested but this is not supported on iOS"
)

View file

@ -26,7 +26,7 @@ ttf-parser = { workspace = true, optional = true }
derive_more = { workspace = true, optional = true }
cfg-if = { version = "1", optional = true }
[target.'cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32", target_os = "android")))'.dependencies]
[target.'cfg(not(any(target_family = "windows", target_vendor = "apple", target_arch = "wasm32", target_os = "android")))'.dependencies]
libloading = { version = "0.8.0", optional = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View file

@ -14,8 +14,7 @@ pub struct FontDatabase {
db: Arc<fontdb::Database>,
#[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_vendor = "apple",
target_arch = "wasm32",
target_os = "android",
)))]
@ -62,8 +61,7 @@ thread_local! {
#[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_vendor = "apple",
target_arch = "wasm32",
target_os = "android",
)))]
@ -116,8 +114,7 @@ fn init_fontdb() -> FontDatabase {
#[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_vendor = "apple",
target_arch = "wasm32",
target_os = "android",
)))]
@ -146,8 +143,7 @@ fn init_fontdb() -> FontDatabase {
cfg_if::cfg_if! {
if #[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_vendor = "apple",
target_arch = "wasm32",
target_os = "android",
)))] {
@ -180,8 +176,7 @@ fn init_fontdb() -> FontDatabase {
db: Arc::new(font_db),
#[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_vendor = "apple",
target_arch = "wasm32",
target_os = "android",
)))]

View file

@ -310,8 +310,7 @@ fn get_fallback_fonts(
#[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_vendor = "apple",
target_arch = "wasm32",
target_os = "android"
)))]

View file

@ -1717,16 +1717,15 @@ impl TextInput {
let text_color = self.color();
let cursor_color =
if cfg!(any(target_os = "android", target_os = "macos", target_os = "ios")) {
if cursor_position.is_some() {
self.selection_background_color().with_alpha(1.)
} else {
Default::default()
}
let cursor_color = if cfg!(any(target_os = "android", target_vendor = "apple")) {
if cursor_position.is_some() {
self.selection_background_color().with_alpha(1.)
} else {
text_color.color()
};
Default::default()
}
} else {
text_color.color()
};
let mut repr = TextInputVisualRepresentation {
text,

View file

@ -349,7 +349,7 @@ impl FontCache {
Font { fonts, text_context: self.text_context.clone(), pixel_size }
}
#[cfg(target_os = "macos")]
#[cfg(target_vendor = "apple")]
fn font_fallbacks_for_request(
&self,
_family: Option<&SharedString>,
@ -453,8 +453,7 @@ impl FontCache {
#[cfg(not(any(
target_family = "windows",
target_os = "macos",
target_os = "ios",
target_vendor = "apple",
target_arch = "wasm32",
target_os = "android",
)))]

View file

@ -49,7 +49,7 @@ unicode-segmentation = { workspace = true }
ash = { version = "^0.37.2", optional = true }
vulkano = { version = "0.34.0", optional = true, default-features = false }
[target.'cfg(not(target_os = "ios"))'.dependencies]
[target.'cfg(any(not(target_vendor = "apple"), target_os = "macos"))'.dependencies]
glutin = { workspace = true, default-features = false, features = ["egl", "wgl"] }
[target.'cfg(not(target_os = "android"))'.dependencies]

View file

@ -48,7 +48,7 @@ pub mod d3d_surface;
#[cfg(skia_backend_vulkan)]
pub mod vulkan_surface;
#[cfg(not(target_os = "ios"))]
#[cfg(any(not(target_vendor = "apple"), target_os = "macos"))]
pub mod opengl_surface;
use i_slint_core::items::TextWrap;
@ -222,7 +222,7 @@ impl SkiaRenderer {
}
}
#[cfg(not(target_os = "ios"))]
#[cfg(any(not(target_vendor = "apple"), target_os = "macos"))]
/// Creates a new SkiaRenderer that will always use Skia's OpenGL renderer.
pub fn default_opengl(context: &SkiaSharedContext) -> Self {
Self {