feat: porting to HarmonyOS#2634
Conversation
|
Thanks @shenjackyuanjie for taking the time to contribute. This repository is currently observing a maintainer-managed contribution gate in dry-run mode, so this pull request is staying open. When enforcement is enabled, pull requests from contributors who are not listed in Please read |
There was a problem hiding this comment.
Code Review
This pull request adds support for HarmonyOS (OHOS) targets by introducing custom compiler wrapper scripts, target configurations, and excluding OHOS from Linux-specific features like sandboxing, process hardening, and native clipboard integrations. Feedback focuses on improving build portability by avoiding hardcoded absolute Windows paths in .cargo/config.toml and the wrapper scripts, as well as enhancing code maintainability in clipboard.rs by abstracting the repetitive, complex platform-specific cfg attributes into a helper struct.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| [target.aarch64-unknown-linux-ohos] | ||
| linker = "D:/githubs/hmnext/CodeWhale/ohos-clang.cmd" | ||
|
|
||
| [env] | ||
| AR_aarch64_unknown_linux_ohos = "D:/apps/DevEco Studio/app/sdk/default/openharmony/native/llvm/bin/llvm-ar.exe" | ||
| CC_aarch64_unknown_linux_ohos = "D:/githubs/hmnext/CodeWhale/ohos-clang.cmd" | ||
| CXX_aarch64_unknown_linux_ohos = "D:/githubs/hmnext/CodeWhale/ohos-clangxx.cmd" | ||
| CMAKE_TOOLCHAIN_FILE_aarch64_unknown_linux_ohos = "D:/apps/DevEco Studio/app/sdk/default/openharmony/native/build/cmake/ohos.toolchain.cmake" |
There was a problem hiding this comment.
The committed .cargo/config.toml contains hardcoded absolute Windows paths (D:/...) specific to a local development environment. This makes the build configuration non-portable and will break compilation for other developers or CI/CD pipelines attempting to build for the HarmonyOS target.
Recommended Improvements:
- Avoid committing absolute paths: Do not hardcode local directory paths in shared configuration files.
- Use environment variables: Instruct developers to set environment variables (e.g.,
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_OHOS_LINKER) in their local environment instead of committing them. - Provide a template: Consider adding
.cargo/config.tomlto.gitignoreand providing a.cargo/config.toml.exampletemplate for local configuration.
| @@ -0,0 +1,3 @@ | |||
| @echo off | |||
| set SDK=D:\apps\DevEco Studio\app\sdk\default\openharmony\native | |||
There was a problem hiding this comment.
The SDK path is hardcoded to a specific local directory on Windows. To make this script portable and usable by other developers, allow overriding the SDK path via an environment variable (e.g., OHOS_NDK_HOME), while keeping the current path as a default fallback.
if "%OHOS_NDK_HOME%"=="" (set SDK=D:\\apps\\DevEco Studio\\app\\sdk\\default\\openharmony\\native) else (set SDK=%OHOS_NDK_HOME%)
| @@ -0,0 +1,3 @@ | |||
| @echo off | |||
| set SDK=D:\apps\DevEco Studio\app\sdk\default\openharmony\native | |||
There was a problem hiding this comment.
The SDK path is hardcoded to a specific local directory on Windows. To make this script portable and usable by other developers, allow overriding the SDK path via an environment variable (e.g., OHOS_NDK_HOME), while keeping the current path as a default fallback.
if "%OHOS_NDK_HOME%"=="" (set SDK=D:\\apps\\DevEco Studio\\app\\sdk\\default\\openharmony\\native) else (set SDK=%OHOS_NDK_HOME%)
| #[cfg(any( | ||
| test, | ||
| all( | ||
| not(test), | ||
| any( | ||
| target_os = "macos", | ||
| target_os = "windows", | ||
| all(target_os = "linux", not(target_env = "ohos")) | ||
| ) | ||
| ) | ||
| ))] | ||
| clipboard: Option<Clipboard>, | ||
| #[cfg(any( | ||
| test, | ||
| all( | ||
| not(test), | ||
| any( | ||
| target_os = "macos", | ||
| target_os = "windows", | ||
| all(target_os = "linux", not(target_env = "ohos")) | ||
| ) | ||
| ) | ||
| ))] | ||
| clipboard_init_attempted: bool, |
There was a problem hiding this comment.
The complex cfg condition for arboard clipboard support is repeated many times throughout this file (for imports, struct fields, initialization, and methods). This significantly reduces readability and maintainability.
Recommended Refactoring:
Abstract the system clipboard into a helper struct (e.g., SystemClipboard) with two conditional implementations:
- One using
arboardfor supported platforms. - A dummy/no-op implementation for unsupported platforms (like HarmonyOS).
This isolates the platform-specific conditional compilation to a single place and keeps ClipboardHandler clean and free of inline cfg clutter.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds OpenHarmony (OHOS) build support by excluding Linux-only integrations on the OHOS target and wiring up a Rustls crypto provider for reqwest after moving to rustls-no-provider.
Changes:
- Add OHOS toolchain helper scripts and a Cargo target config for
aarch64-unknown-linux-ohos. - Gate Linux-only behaviors (xdg-open, Landlock/seccomp/bwrap, prctl-based hardening, wl-copy/wl-paste, etc.) to exclude
target_env = "ohos". - Switch
reqwesttorustls-no-provider, addrustlsdependency, and install the ring provider at process startup (CLI + TUI).
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
ohos-clang.cmd |
Adds a Windows wrapper script to invoke OHOS clang for cross-compilation. |
ohos-clangxx.cmd |
Adds a Windows wrapper script to invoke OHOS clang++ for cross-compilation. |
.cargo/config.toml |
Adds OHOS target linker + env var configuration for Cargo builds. |
.gitignore |
Un-ignores the two OHOS .cmd scripts so they can be committed. |
Cargo.toml |
Switches workspace reqwest to rustls-no-provider and adds workspace rustls config. |
crates/tui/Cargo.toml |
Updates reqwest features, adds rustls, and makes arboard target-specific (excluding OHOS). |
crates/release/Cargo.toml |
Adds rustls dependency (likely to ensure provider/code is linked consistently). |
crates/cli/Cargo.toml |
Adds rustls dependency for provider installation. |
crates/tui/src/main.rs |
Installs the Rustls ring provider at startup. |
crates/cli/src/lib.rs |
Installs the Rustls ring provider before running CLI logic. |
crates/tui/src/utils.rs |
Treats OHOS as “not Linux” for browser-open behavior and related tests. |
crates/tui/src/tui/clipboard.rs |
Excludes clipboard backends on OHOS and makes arboard/image usage conditional. |
crates/tui/src/tools/shell.rs |
Disables Linux-specific parent-death signal setup on OHOS. |
crates/tui/src/tools/diagnostics.rs |
Disables Linux-only probes (bwrap/cgroup) on OHOS. |
crates/tui/src/sandbox/mod.rs |
Excludes Linux sandbox types (Landlock/etc.) on OHOS. |
crates/tui/src/sandbox/process_hardening.rs |
Excludes Linux prctl/setrlimit hardening on OHOS. |
crates/secrets/src/lib.rs |
Excludes Linux keyring backend on OHOS via cfg gating. |
crates/secrets/Cargo.toml |
Makes keyring Linux dependency conditional on not(target_env = "ohos"). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn install_rustls_crypto_provider() { | ||
| let _ = rustls::crypto::ring::default_provider().install_default(); | ||
| } |
| fn install_rustls_crypto_provider() { | ||
| let _ = rustls::crypto::ring::default_provider().install_default(); | ||
| } |
| #[cfg(any( | ||
| test, | ||
| all( | ||
| not(test), | ||
| any( | ||
| target_os = "macos", | ||
| target_os = "windows", | ||
| all(target_os = "linux", not(target_env = "ohos")) | ||
| ) | ||
| ) | ||
| ))] | ||
| use arboard::{Clipboard, ImageData}; |
| #[cfg(any( | ||
| test, | ||
| all( | ||
| not(test), | ||
| any( | ||
| target_os = "macos", | ||
| target_os = "windows", | ||
| all(target_os = "linux", not(target_env = "ohos")) | ||
| ) | ||
| ) | ||
| ))] | ||
| clipboard: Option<Clipboard>, | ||
| #[cfg(any( | ||
| test, | ||
| all( | ||
| not(test), | ||
| any( | ||
| target_os = "macos", | ||
| target_os = "windows", | ||
| all(target_os = "linux", not(target_env = "ohos")) | ||
| ) | ||
| ) | ||
| ))] | ||
| clipboard_init_attempted: bool, |
|
using codex to replace hardcode path into $env |
|
Thanks @shenjackyuanjie. I saw the WIP HarmonyOS branch and your note about replacing hard-coded paths with env-driven paths. This is the right shape for the HarmonyOS work, but it touches broad build, sandbox, shell, clipboard, and dependency surfaces, so I am not pulling it into the v0.8.52 cleanup release. I will keep #2625 / this PR as the follow-up lane after 0.8.52 is published and verified. |
Remove checked-in machine-specific DevEco SDK paths from Cargo and compiler wrappers. Add PowerShell and POSIX setup scripts that derive the OHOS toolchain from OHOS_NATIVE_SDK, plus HarmonyOS documentation linked from install docs and READMEs. Verified: cargo build --target aarch64-unknown-linux-ohos -p codewhale-cli passes with the local OpenHarmony SDK. codewhale-tui reaches the known rustyline/libc ioctl type mismatch on OHOS. Co-authored-by: Codex <codex@openai.com>
667c339 to
2c139b4
Compare
|
Thanks @shenjackyuanjie. The v0.9 branch has harvested the HarmonyOS/OpenHarmony lane with credit and added dependency-graph guards. Full OHOS target verification still needs a host with |
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
Thanks again @shenjackyuanjie. We harvested the release-safe HarmonyOS/OpenHarmony slice into the v0.9.0 stewardship branch with credit ( Keeping this PR useful as the source/validation thread: if you can retest from the v0.9.0 branch with |
I'll give it a try, hopefully nix won't stop us check |
@Hmbown now |
|
Thanks @shenjackyuanjie. I am closing this draft PR as harvested/superseded for the v0.9.0 release train, not because the work was unwanted. What landed on
Verification now includes the local dependency graph guard ( I am not merging this branch directly because it is still draft, has only partial PR checks, and includes broader build/sandbox/clipboard/dependency changes than the release-safe slice. Thank you for pushing this port forward and for doing the SDK-side validation. |


Summary
checklist
[x] make code in the repo compileale
[ ] patch
nixor wait for upstream update to make repo compileGreptile Summary
This PR ports CodeWhale to HarmonyOS/OpenHarmony by conditionally excluding Linux-specific subsystems (
Landlock,seccomp,bwrap,keyring,arboard,rustyline,xdg-open) whentarget_env = "ohos", replacingaws-lc-rs-backed rustls with an explicitringcrypto provider for broader platform compatibility, and adding environment-setup scripts and documentation for cross-compilation.reqwestfromrustlstorustls-no-providerand injects theringprovider explicitly at startup in bothcodewhale-cliandcodewhale-tui, removing the dependency onaws-lc-rs/cmake/quinn.ohos-clang.sh,ohos-clangxx.sh, PowerShell equivalents) and Cargo environment-setup scripts driven byOHOS_NATIVE_SDK, with validation of required SDK paths before they are used.sandbox,clipboard,process hardening,self-update,browser open,keyring) withall(target_os = \"linux\", not(target_env = \"ohos\"))predicates so HarmonyOS falls through to existing no-op or error paths.Confidence Score: 5/5
The PR is safe to merge: all platform-specific subsystems are consistently gated, the rustls provider switch is handled correctly at process startup in both binaries, and the SDK scripts validate paths before use.
The cfg predicate all(target_os = "linux", not(target_env = "ohos")) is applied consistently across every affected site — sandbox, clipboard, keyring, diagnostics, shell, and process hardening. The switch from aws-lc-rs to ring is explicit and purposeful, with the provider installed at process entry in both codewhale-cli and codewhale-tui. No existing Linux or macOS behaviour is changed. The one pattern worth watching is that the OHOS bail in run_update leaves the rest of the function body compiled on OHOS, but the checklist confirms the build passes and no OHOS-incompatible API surfaces in the current function body.
crates/tui/src/update.rs — the OHOS guard relies on a runtime early return rather than compile-time exclusion, which will require attention if OHOS-incompatible code is ever added to that function body in future.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[main / run_cli] --> B[install_rustls_crypto_provider\nring::default_provider\n.install_default] B --> C{target_env?} C -->|ohos| D[Sandbox: None\nClipboard: OSC-52 only\nKeyring: unsupported\nBrowser open: error\nSelf-update: bail!] C -->|linux| E[Sandbox: Landlock/bwrap\nClipboard: wl-copy + arboard\nKeyring: Secret Service\nBrowser: xdg-open\nSelf-update: enabled] C -->|macos| F[Sandbox: Seatbelt\nClipboard: pbcopy + arboard\nKeyring: Keychain\nBrowser: open\nSelf-update: enabled] C -->|windows| G[Sandbox: Windows helper\nClipboard: arboard\nKeyring: Credential Mgr\nBrowser: start\nSelf-update: enabled]Reviews (5): Last reviewed commit: "Apply suggestion from @greptile-apps[bot..." | Re-trigger Greptile