From 484bcbfea6ec20b8a973404d2899879deec2bf20 Mon Sep 17 00:00:00 2001 From: richerfu <32590310+richerfu@users.noreply.github.com> Date: Mon, 26 Oct 2026 15:29:14 +0000 Subject: [PATCH] feat(gpui): Allow building gpui against ohos (#64579) # Objective This PR will allow to develop and use gpui ohos platform's crate.We need to use ohos instead of linux logic. ## Solution - Avoid linux logic when target is ohos. - Add gesture for ohos. ## Testing I've already test it in HarmonyOS emulator and physical HarmonyOS device. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable ## Showcase I made a gpui backend crate for OpenHarmony [gpui-ohos](https://github.com/ohos-rs/gpui-ohos) and Using it to develop an application which already publish into Huawei store for a long time. Here is [source code](https://github.com/richerfu/nearsend/pull/14) Here is a video to show it. https://github.com/user-attachments/assets/26efe4f7-d5ef-473f-8dbd-e30ab14ec186 --- Release Notes: - [GPUI] N/A --- crates/gpui_platform/Cargo.toml | 2 +- crates/gpui_platform/src/gpui_platform.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/gpui_platform/Cargo.toml b/crates/gpui_platform/Cargo.toml index 6245202a714..4520063e897 100644 --- a/crates/gpui_platform/Cargo.toml +++ b/crates/gpui_platform/Cargo.toml @@ -65,7 +65,7 @@ gpui_ios.workspace = true gpui_windows.workspace = true gpui = { workspace = true, features = ["windows-manifest"] } -[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies] +[target.'cfg(all(any(target_os = "linux", target_os = "freebsd"), not(target_env = "ohos")))'.dependencies] gpui_linux.workspace = true [target.'cfg(target_os = "linux")'.dependencies] diff --git a/crates/gpui_platform/src/gpui_platform.rs b/crates/gpui_platform/src/gpui_platform.rs index 5f328d1bcdd..706caf80db4 100644 --- a/crates/gpui_platform/src/gpui_platform.rs +++ b/crates/gpui_platform/src/gpui_platform.rs @@ -29,7 +29,10 @@ pub fn headless() -> gpui::Application { /// It starts windowed in the process's own environment, or headless if that names no allowed /// display server. Set another initial mode with [`gpui::Application::with_windowing`], and /// switch later with [`gpui::App::request_windowing`]. -#[cfg(any(target_os = "linux", target_os = "freebsd"))] +#[cfg(all( + any(target_os = "linux", target_os = "freebsd"), + not(target_env = "ohos") +))] pub fn linux(allowed_modes: gpui::WindowingModes) -> gpui::Application { gpui::Application::with_platform(gpui_linux::linux_platform(allowed_modes)) } @@ -83,7 +86,18 @@ pub fn current_platform(headless: bool) -> Rc { ) } - #[cfg(any(target_os = "linux", target_os = "freebsd"))] + #[cfg(target_env = "ohos")] + { + let _ = headless; + panic!( + "gpui_platform does not select an OpenHarmony backend; inject gpui-ohos with Application::with_platform" + ) + } + + #[cfg(all( + any(target_os = "linux", target_os = "freebsd"), + not(target_env = "ohos") + ))] { gpui_linux::current_platform(headless) }