返回 CodeWhale
HarmonyOS.md
根目录 / docs / HarmonyOS.md
1 # HarmonyOS and OpenHarmony
2
3 This page covers Codewhale on HarmonyOS PC and OpenHarmony cross-build setups.
4
5 ## Support Tier
6
7 | Target | Codewhale tier | CI coverage | Distribution |
8 | --- | --- | --- | --- |
9 | HarmonyOS PC with a glibc-compatible userspace | Tier 1 Linux ARM64 runtime | Covered by the Linux ARM64 release build | GitHub release binaries; npm secondary |
10 | `aarch64-unknown-linux-ohos` (OpenHarmony) | Tier 2 cross-build target | `codewhale-tui` is checked with a real OpenHarmony native SDK/sysroot | Build from source; no prebuilt release asset |
11
12 Tier 2 means every relevant source change is compile-checked, but maintainers do
13 not promise a release binary or full device-level runtime testing. The CI job
14 uses the published OpenHarmony 6.1 native SDK; it deliberately fails if the SDK,
15 Clang, or sysroot is unavailable rather than substituting host headers or a stub
16 that could report false success.
17
18 ## Running On HarmonyOS PC
19
20 HarmonyOS PC can use the Linux ARM64 release when its userspace is compatible.
21 For a new installation in a Linux environment, use the official GitHub installer:
22
23 ```bash
24 curl -fsSL https://codewhale.net/install.sh | sh
25 "$HOME/.local/bin/codewhale" --version
26 ```
27
28 The [published v0.9.11 release](https://github.com/Hmbown/CodeWhale/releases/tag/v0.9.11)
29 includes `codewhale-linux-arm64` and `codew-linux-arm64`; asset availability does
30 not establish compatibility with every HarmonyOS device. See
31 [Linux ARM64 portability](INSTALL.md#linux-arm64-portability) for release-specific
32 requirements and the Cargo fallback. For an existing direct install, use
33 `codewhale update`. For an occupied directory or a package-managed install, use
34 [the fresh-directory migration](INSTALL.md#migrating-from-npm-cargo-or-another-installation).
35 npm remains a secondary packaging route. The
36 `codewhale-tui-linux-arm64` filename is retained only for legacy updater
37 compatibility and is not a third command.
38
39 ## Cross-Compiling To OpenHarmony
40
41 The repository does not check in machine-specific SDK paths. Set
42 `OHOS_NATIVE_SDK` to the OpenHarmony native SDK directory, the directory that
43 contains `llvm/bin`, `sysroot`, and `build/cmake/ohos.toolchain.cmake`.
44
45 On Windows PowerShell:
46
47 ```powershell
48 $env:OHOS_NATIVE_SDK="<path-to-openharmony-native-sdk>"
49 . .\scripts\ohos-env.ps1
50 rustup target add aarch64-unknown-linux-ohos
51 cargo build --target aarch64-unknown-linux-ohos -p codewhale-cli
52 ```
53
54 On Linux or macOS:
55
56 ```bash
57 export OHOS_NATIVE_SDK=/path/to/openharmony/native
58 . ./scripts/ohos-env.sh
59 rustup target add aarch64-unknown-linux-ohos
60 cargo build --target aarch64-unknown-linux-ohos -p codewhale-cli
61 ```
62
63 The setup scripts export Cargo's target-specific `linker`, `AR`, `CC`, `CXX`,
64 `CFLAGS`, `CXXFLAGS`, `CARGO_ENCODED_RUSTFLAGS`, `CC_SHELL_ESCAPED_FLAGS`, and
65 CMake toolchain variables for `aarch64-unknown-linux-ohos`. They also point
66 `bindgen` at the SDK's `libclang` and sysroot so `rquickjs-sys` can generate
67 the OpenHarmony bindings that it does not ship pre-generated.
68
69 On Windows, `ohos-env.ps1` points Cargo at the repository's
70 `ohos-clang.cmd` launcher. The launcher delegates to `ohos-clang.ps1`, so the
71 final Rust link—not only C/C++ compilation and bindgen—always carries
72 `-target aarch64-linux-ohos`, the SDK sysroot, and `-D__MUSL__` while preserving
73 Cargo's linker arguments and exit status. The launcher re-quotes every
74 argument before forwarding, so an SDK path containing spaces (for example the
75 default `D:\DevEco Studio\...` install) keeps its `--sysroot` intact through
76 the final link.
77
78 ## Compiler Wrappers
79
80 For ad-hoc compiler calls, use the wrappers in `scripts/ohos/`. They read the same
81 `OHOS_NATIVE_SDK` variable and do not contain local paths.
82
83 Windows PowerShell:
84
85 ```powershell
86 .\scripts\ohos\ohos-clang.ps1 --version
87 .\scripts\ohos\ohos-clangxx.ps1 --version
88 ```
89
90 Linux or macOS:
91
92 ```bash
93 sh ./scripts/ohos/ohos-clang.sh --version
94 sh ./scripts/ohos/ohos-clangxx.sh --version
95 ```
96
97 If you want to run the POSIX wrappers directly as `./scripts/ohos/ohos-clang.sh`, make them
98 executable first:
99
100 ```bash
101 chmod +x ./scripts/ohos/ohos-clang.sh ./scripts/ohos/ohos-clangxx.sh
102 ```
103
104 ## Linker And Toolchain Paths
105
106 The repository does not check in a Cargo linker path or CMake toolchain path.
107 Cargo cannot expand environment variables inside `linker` or CMake toolchain
108 path values, so those values are exported by `scripts/ohos-env.ps1` and
109 `scripts/ohos-env.sh` instead.
110
111 ## Dependency Guard
112
113 Release prep runs a no-SDK dependency check:
114
115 ```bash
116 ./scripts/release/check-ohos-deps.sh
117 ```
118
119 The guard asserts the Windows final-link wrapper contract, proves that OHOS
120 activates the `rquickjs-sys` bindgen feature, resolves the `codewhale-tui`
121 dependency graph for `aarch64-unknown-linux-ohos`, and fails if unsupported
122 host/UI crates re-enter that graph: `nix` 0.28/0.29, `portable-pty`, `starlark`,
123 `arboard`, or `keyring`. This no-SDK check does not replace a real SDK/sysroot
124 build, but it catches the known linker, bindgen, `starlark -> rustyline -> nix`,
125 and PTY/keyring regressions before release.
126
127 Because `portable-pty` is intentionally absent from the OpenHarmony graph, the
128 persistent `terminal/*` PTY tools are not registered on that target. The
129 ordinary `exec_shell` tools remain available through their non-PTY process
130 implementation.
131
132 Linux-only sandbox implementations (bubblewrap, seccomp, and `prctl` process
133 hardening) are compiled only for
134 `all(target_os = "linux", not(target_env = "ohos"))`. OpenHarmony therefore
135 reports no local OS sandbox instead of probing Linux kernel paths or syscalls it
136 does not support. External OpenSandbox execution remains separately available
137 when configured.
138
139 Native desktop clipboard libraries and Wayland helpers are also excluded from
140 the OpenHarmony graph. Text copy degrades to the terminal-client path (OSC 52,
141 or tmux `load-buffer -w` when inside tmux); paste is supplied by the terminal as
142 normal/bracketed input. Image clipboard reads are unavailable on this target.
143 If the terminal cannot accept OSC 52, copy returns a clear "Clipboard
144 unavailable" error rather than panicking or claiming success.
145
145 lines MARKDOWN