Skip to content

Support HarmonyOS #113

@cavivie

Description

@cavivie

Tracking HarmonyOS NEXT support. Full scoping analysis in this comment.

Status (2026-04-21): Phase 1 PRs ready for review + a signed .so that survives dlopen on a real DevEco 6.0.1(21) wearable emulator. See the handoff comment below for the validation state and what's needed from @cavivie.

Blockers (answer before starting)

  • Confirm whether perry/ui is needed, or logic-only is sufficient for the reporter's use case → UI required, Phase 2 (B1 ArkTS emitter) is in scope; B2 explicitly out.
  • Confirm access to a Huawei dev cert + NEXT device or DevEco Studio emulator for validation → Both confirmed (@cavivie has cert + physical NEXT hardware, will validate intermediate builds).

Phase 1 — toolchain + .so/HAP bundle, no UI

  • Add ohos / ohos-simulator variants to Platform enum + rust_target_tripleshipped as harmonyos / harmonyos-simulator (target strings only; Platform enum deliberately not touched, see PR #121). Maps to aarch64-unknown-linux-ohos / x86_64-unknown-linux-ohos.
  • OpenHarmony SDK detection (env var OHOS_SDK_HOME or similar) — sysroot + llvm/bin/clang path resolution. Supports DevEco 5.x layout (~/Library/Huawei/Sdk/openharmony/<api>/native/) AND DevEco 6.x layout (/Applications/DevEco-Studio.app/Contents/sdk/default/openharmony/native/).
  • Linker invocation: clang --target=aarch64-linux-ohos --sysroot=<sdk>/native/sysroot -D__MUSL__ -shared -fPIC -Wl,-Bsymbolic -Wl,--warn-unresolved-symbols -lace_napi.z -lc -lm -lpthread -ldl.
  • Emit .so output mode — --target harmonyos auto-selects lib<stem>.so.
  • napi_module_register entry wrapper in perry-runtime behind ohos-napi feature flag. Module registration via .init_array; nm_modname derived at runtime via dladdr to match the actual .so filename.
  • Boilerplate ArkTS UIAbility shim generator that loads the .so and invokes the TS entry point. Shipped as plain TypeScript (no @Entry @Component struct) so es2abc --extension ts compiles it directly without ets-loader.
  • HAP bundler: module.json5, ets/ (compiled modules.abc), libs/arm64-v8a/*.so, resources (resources/base/{media,string,color}/).
  • Integrate hvigor assemble + hap-sign (user-supplied cert via env var, not baked into CI) — partial: signing wired via 7 env vars (PERRY_HARMONYOS_P12/_P12_PASSWORD/_CERT/_PROFILE/_KEY_ALIAS/_KEY_PASSWORD/_SIGN_ALG) and shells out to hap-sign-tool.jar directly (skipping hvigor per design Decision 3). Not yet: DevEco encrypts its auto-signing passwords in build-profile.json5, so users with DevEco-auto-generated certs can't use these env vars directly — would need either a decryption helper or a hvigorw integration. Workaround used for v0.5.129 validation: splice Perry's .so + .ets into an existing DevEco project and let hvigor sign.
  • End-to-end: compile hello.ts.hap → install via hdc → run on emulator — partial. libentry.so loads on DevEco 6.0.1(21) wearable emulator and aa start EntryAbility succeeds without throwing. Whether console.log() actually reaches hdc hilog is unverified — perry-runtime writes to stdout (println!()), which OHOS does not route into hilog by default. Likely needs a stdout→hilog shim. Path to HAP-from-perry (not DevEco splice) is blocked on the signing item above.
  • Hand off intermediate build to @cavivie for on-device NEXT validation (resolves KAL unknown below) — ready now. See #121 (PR A, scaffolding) + #122 (PR B, functional, stacked on PR A). The harmony-os branch has 7 commits from main representing the full Phase 1 work.

Phase 2 — TS→ArkTS emitter for perry/ui (option B1) — confirmed in scope

  • New perry-codegen-arkts crate mirroring perry-codegen-js/perry-codegen-wasm shape
  • Map perry/ui HIR widget tree → ArkTS declarative components (Column/Row/Text/Button/...)
  • State reactivity: bridge Perry's State<T> → ArkTS @State/@Link
  • Hybrid build: UI compiles to .ets, logic compiles to .so, both packaged in the same HAP
  • Widget parity audit against existing native UI targets

Phase 3 — deferred

  • Custom GL widget set on XComponent (option B2) — explicitly out for v1 per @cavivie; revisit only if B1 proves unexpectedly complex.

Open unknowns

  • Verify aarch64-unknown-linux-ohos binaries actually run on HarmonyOS NEXT's microkernel via KAL — confirmed on DevEco 6.0.1(21) wearable emulator (v0.5.129). Physical-device validation still outstanding.
  • Confirm libffi / tikv-jemalloc-sys gap doesn't hit perry-stdlib growth before/during this work — untouched; perry-stdlib cross-compiles green today, but if deps shift this could regress.
  • Does TS console.log() reach hdc hilog? Unverified on emulator. Physical-device test from @cavivie would confirm whether the emulator behavior (silent drop) matches devices or is emulator-specific.
  • DevEco auto-signing password decryption vs hvigorw integration — pick one to unblock the end-to-end perry compilehdc install loop without requiring the DevEco-project splice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions