richerfu 说明 Zed 的 OpenHarmony 平台适配

richerfu 说明 OpenHarmony 的 Rust target 会误走 Linux 依赖路径,相关 PR 通过 cfg 排除桌面 Linux 依赖并接入 gpui-ohos,同时加入适配 OpenHarmony 的触摸滚动物理。

作者原文

I'm not sure if I fully understood your point, so I'll do my best to clearly explain what I'm trying to achieve with this PR.

OpenHarmony's Rust target triple is aarch64-unknown-linux-ohos, where rustc sets both target_os = "linux" and target_env = "ohos". We are trying to solve three things here:

  1. Avoid Linux dependency build errors (crates/gpui_platform/Cargo.toml):
    Because aarch64-unknown-linux-ohos also matches target_os = "linux", whenever gpui_platform is pulled into the dependency graph, Cargo enables
    gpui_linux and triggers desktop Linux dependency build scripts (Wayland, X11, system libraries, etc.), which fail to compile on OpenHarmony. Guarding
    gpui_linux with not(target_env = "ohos") prevents Cargo from pulling in desktop Linux dependencies on OpenHarmony.
  1. Use our own rendering backend instead of desktop Linux's Wayland/X11 (crates/gpui_platform/src/gpui_platform.rs):
    OpenHarmony's windowing and rendering architecture is much closer to Android and iOS than to desktop Linux (Wayland/X11), so we use our own external backend
    (gpui-ohos) via Application::with_platform(...).
    Once gpui_linux is excluded from Cargo.toml on target_env = "ohos", gpui_platform::linux and gpui_platform::current_platform in gpui_platform.rs
    also need #[cfg] guards so gpui_platform itself still compiles without referencing gpui_linux or hitting a missing return value error.
  1. Align touch scroll physics with Android and iOS (crates/gpui/src/gestures.rs):
    OpenHarmony primarily targets mobile/touch devices, so we added ScrollPhysics::ohos() alongside ScrollPhysics::ios() and ScrollPhysics::android() to
    support OpenHarmony's native touch momentum scrolling curve.