Skip to content

feat: porting to HarmonyOS#2634

Closed
shenjackyuanjie wants to merge 4 commits into
Hmbown:mainfrom
shenjackyuanjie:ohos-elf-port
Closed

feat: porting to HarmonyOS#2634
shenjackyuanjie wants to merge 4 commits into
Hmbown:mainfrom
shenjackyuanjie:ohos-elf-port

Conversation

@shenjackyuanjie
Copy link
Copy Markdown

@shenjackyuanjie shenjackyuanjie commented Jun 3, 2026

Summary

checklist

[x] make code in the repo compileale
[ ] patch nix or wait for upstream update to make repo compile

Greptile Summary

This PR ports CodeWhale to HarmonyOS/OpenHarmony by conditionally excluding Linux-specific subsystems (Landlock, seccomp, bwrap, keyring, arboard, rustyline, xdg-open) when target_env = "ohos", replacing aws-lc-rs-backed rustls with an explicit ring crypto provider for broader platform compatibility, and adding environment-setup scripts and documentation for cross-compilation.

  • Switches reqwest from rustls to rustls-no-provider and injects the ring provider explicitly at startup in both codewhale-cli and codewhale-tui, removing the dependency on aws-lc-rs / cmake / quinn.
  • Adds portable compiler-wrapper scripts (ohos-clang.sh, ohos-clangxx.sh, PowerShell equivalents) and Cargo environment-setup scripts driven by OHOS_NATIVE_SDK, with validation of required SDK paths before they are used.
  • Guards all Linux-native subsystems (sandbox, clipboard, process hardening, self-update, browser open, keyring) with all(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

Filename Overview
crates/tui/src/update.rs Adds OHOS early bail, but the rest of run_update's body is still compiled on OHOS targets — only unreachable at runtime due to the bail, not excluded at compile time.
crates/tui/src/tui/clipboard.rs Correctly gates arboard/wl-copy/image imports behind the non-OHOS cfg predicate; complex but logically correct cfg attribute repetition throughout.
crates/tui/src/sandbox/mod.rs Consistently replaces all target_os = "linux" guards with all(target_os = "linux", not(target_env = "ohos")); sandbox correctly falls through to None on OHOS.
Cargo.toml Switches reqwest from rustls to rustls-no-provider and adds an explicit rustls ring dependency; removes aws-lc-rs/cmake/quinn chain for better cross-platform portability.
scripts/ohos-env.sh Validates SDK paths before use, correctly uses return/exit dual-mode pattern for sourcing vs executing, and uses CARGO_ENCODED_RUSTFLAGS (0x1F separator) for space-safe path handling.
crates/secrets/src/lib.rs All four KeyringStore methods (probe, get, set, delete) and the unsupported_keyring_message helper are consistently updated to exclude OHOS from the native keyring path.
crates/cli/src/lib.rs install_rustls_crypto_provider installs the ring provider at process startup so all subsequent reqwest/rustls calls have a crypto provider available.

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]
Loading

Fix All in Codex Fix All in Claude Code Fix All in Cursor

Reviews (5): Last reviewed commit: "Apply suggestion from @greptile-apps[bot..." | Re-trigger Greptile

Copilot AI review requested due to automatic review settings June 3, 2026 10:49
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

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 .github/APPROVED_CONTRIBUTORS will be closed automatically.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant PR access by commenting /lgtm on a pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .cargo/config.toml Outdated
Comment on lines +1 to +8
[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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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:

  1. Avoid committing absolute paths: Do not hardcode local directory paths in shared configuration files.
  2. 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.
  3. Provide a template: Consider adding .cargo/config.toml to .gitignore and providing a .cargo/config.toml.example template for local configuration.

Comment thread ohos-clang.cmd Outdated
@@ -0,0 +1,3 @@
@echo off
set SDK=D:\apps\DevEco Studio\app\sdk\default\openharmony\native
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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%)

Comment thread ohos-clangxx.cmd Outdated
@@ -0,0 +1,3 @@
@echo off
set SDK=D:\apps\DevEco Studio\app\sdk\default\openharmony\native
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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%)

Comment on lines +101 to 124
#[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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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:

  1. One using arboard for supported platforms.
  2. 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 reqwest to rustls-no-provider, add rustls dependency, 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.

Comment thread .cargo/config.toml Outdated
Comment thread ohos-clang.cmd Outdated
Comment thread ohos-clangxx.cmd Outdated
Comment thread crates/tui/src/main.rs
Comment on lines +112 to +114
fn install_rustls_crypto_provider() {
let _ = rustls::crypto::ring::default_provider().install_default();
}
Comment thread crates/cli/src/lib.rs
Comment on lines +466 to +468
fn install_rustls_crypto_provider() {
let _ = rustls::crypto::ring::default_provider().install_default();
}
Comment on lines +39 to 50
#[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};
Comment on lines +101 to 124
#[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,
@shenjackyuanjie shenjackyuanjie changed the title feat: porting to HarmonyOS WIP: feat: porting to HarmonyOS Jun 3, 2026
Comment thread .cargo/config.toml Outdated
Comment thread ohos-clang.cmd Outdated
Comment thread crates/tui/src/sandbox/process_hardening.rs
@shenjackyuanjie
Copy link
Copy Markdown
Author

using codex to replace hardcode path into $env

@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented Jun 3, 2026

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.

@shenjackyuanjie shenjackyuanjie marked this pull request as draft June 3, 2026 10:59
@shenjackyuanjie shenjackyuanjie changed the title WIP: feat: porting to HarmonyOS feat: porting to HarmonyOS Jun 3, 2026
shenjackyuanjie and others added 2 commits June 4, 2026 09:58
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>
@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented Jun 5, 2026

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 OHOS_NATIVE_SDK, so I’m keeping this open for real SDK confirmation before closing it.

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented Jun 5, 2026

Thanks again @shenjackyuanjie. We harvested the release-safe HarmonyOS/OpenHarmony slice into the v0.9.0 stewardship branch with credit (23c9481, plus the OHOS dependency guard in 6a7063c). I would not merge this PR branch directly because it is still draft, lacks the normal CI matrix, and the submitted TUI graph still includes unsupported OHOS dependencies that the stewardship branch now gates out.

Keeping this PR useful as the source/validation thread: if you can retest from the v0.9.0 branch with OHOS_NATIVE_SDK loaded and confirm cargo check --target aarch64-unknown-linux-ohos -p codewhale-tui, that would close the remaining release evidence gap.

@shenjackyuanjie
Copy link
Copy Markdown
Author

Thanks again @shenjackyuanjie. We harvested the release-safe HarmonyOS/OpenHarmony slice into the v0.9.0 stewardship branch with credit (23c9481, plus the OHOS dependency guard in 6a7063c). I would not merge this PR branch directly because it is still draft, lacks the normal CI matrix, and the submitted TUI graph still includes unsupported OHOS dependencies that the stewardship branch now gates out.

Keeping this PR useful as the source/validation thread: if you can retest from the v0.9.0 branch with OHOS_NATIVE_SDK loaded and confirm cargo check --target aarch64-unknown-linux-ohos -p codewhale-tui, that would close the remaining release evidence gap.

I'll give it a try, hopefully nix won't stop us check

@shenjackyuanjie
Copy link
Copy Markdown
Author

image

@Hmbown now codex/v0.9.0-stewardship works with cargo check --target aarch64-unknown-linux-ohos -p codewhale-tui

@shenjackyuanjie
Copy link
Copy Markdown
Author

image

@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented Jun 6, 2026

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 codex/v0.9.0-stewardship:

  • 23c9481 / 00a7eb8: release-safe HarmonyOS/OpenHarmony scaffolding, SDK env setup, wrappers, docs, and target guards
  • 6a7063c: ./scripts/release/check-ohos-deps.sh guard so unsupported OpenHarmony target dependencies do not drift back in
  • README/changelog credit for your HarmonyOS/OpenHarmony porting work and MatePad Edge validation trail

Verification now includes the local dependency graph guard (./scripts/release/check-ohos-deps.sh: OK) plus your confirmation that codex/v0.9.0-stewardship works with cargo check --target aarch64-unknown-linux-ohos -p codewhale-tui when OHOS_NATIVE_SDK is configured.

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.

@Hmbown Hmbown closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants