Repository navigation
feat(harmonyos): add a HarmonyOS preview target - #79
Merged
Merged
Conversation
togotop
force-pushed
the
feat/harmony-main
branch
from
November 15, 2026 16:17
4294f0b to
1de629a
Compare
This was referenced Nov 15, 2026
Closed
togotop
force-pushed
the
feat/harmony-main
branch
from
November 16, 2026 05:48
1de629a to
4ae7108
Compare
togotop
force-pushed
the
feat/harmony-main
branch
from
November 16, 2026 06:14
386fcc9 to
7b0c54d
Compare
Collaborator
The harmonyos target, its ArkTS host and its render layer come onto the current main as a scoped port: cmd/nsgo/harmony builds and packages the HAP, internal/platform/harmonyos runs the engine in ArkWeb, and the driver's frame clock and kind names arrive with them. Everything else stays as main has it: the engine, the backends and their build options are untouched, so the branch's cross-platform ops writer and text runs are not part of this port. The tool learns the target in build.go, package.go (running a HAP with hdc), doctor, check, project settings and the test runner, and keeps it out of all, as its packages are unsigned previews. A share, an update check and a notification permission answer with what the platform has rather than leaving an app's callback waiting. Checked: go tool nsgo check; the harmonyos and cmd/nsgo/harmony tests; go build ./...; examples/hello builds into a HAP and its tests pass on the HarmonyOS emulator (TestGreets 1.06 s, TestNotificationServicesAnswer 890 ms) and headless. cmd/nsgo's TestInitTemplates fails on this machine with the module proxy off, as it does on main.
A structural batch that only deletes views left their FrameNodes on the ArkUI tree: syncNode is gated on dirty, so syncChildren never ran to drop them, and the stale modal covered every later press. Walk the tree in full for structural batches; ordinary batches still write only the views named. - Wrap BuilderNode leaves in a Stack: their frame node ignores position, so canvases landed at the parent's top left corner. - Measure wrapped text without a constraint too: measureTextSize answers the constraint's width, which left labels as wide as their cell. - Take the bottom inset from TYPE_NAVIGATION_INDICATOR, which a full-screen window's TYPE_SYSTEM area does not include. - Give multiline inputs their font's line height, not their whole height, and align their text to the top. - Force-stop the app before installing a HAP, and stop the test HAP when its run ends, so no stale black window hides the next launch. - Fail a test run whose page prints nothing within two minutes instead of waiting forever.
Rebasing onto the current main brought eleven mount items and six events this target never answered. What the SDK has is answered now: keep-awake holds the screen on through setWindowKeepScreenOn, biometrics ask userAuth for the enrolled kind and show its prompt, and a permission asks for the microphone or the camera with checkAccessTokenSync and requestPermissionsFromUser, opening the app's settings page through settings.openAppDetailSettingsPage. Every other permission key, which only a Mac keeps, answers unavailable at once. An overlay permission answers unavailable, since showing over other apps needs SYSTEM_FLOAT_WINDOW, a system app's. An app declares the permissions its module asks for in nsgo.yaml's harmonyos.permissions, which the build writes into module.json with the reason and used scene a prompt needs: without them the request answers denied with no dialog. The bridge test found a real bug: saved() was called by the renderer but neither declared on Bridge nor listed in javaScriptProxy's methodList, so a save that never reached the dialog panicked the module. Both are fixed, and the test now checks every call against the list. Checked on the HarmonyOS emulator: a test app reads the microphone's status as denied and accessibility as unavailable, gets no enrolled biometric, and gets both keep-awake calls; examples/hello passes there and headless, and the harmony package tests pass. The emulator has no camera or microphone, so no prompt shows for either: an ask answers denied with dialogShownResults false.
.agent/skills/nsgo holds the site's llms.txt, which lists every page of the documentation as Markdown, and a SKILL.md that points at it: an agent working in this checkout can find the first-party page for a component, a command or a target instead of guessing from a signature, and is told to read the source at the commit at hand since no API is stable. The skill is not the one apps install (skills/nsgo): that one is for writing an app, and this one is for finding the docs while changing the engine.
upstream moved the module root's run_*.go and view_*.go into internal/backend (a45d732) and the module-wide tests into internal/moduletest, so the harmonyos backend, which lived in the root as run_harmonyos.go, no longer filled in the `run` that backend.Run calls and the target stopped compiling. Move it to internal/backend/run_harmonyos.go and take the API the refactor left: engine.App and Options instead of App and options. internal/backend already may import internal/platform/, so the layering rules hold. Record what a span's Style.Cursor does here, which the new core field raises: nothing, as the platform has no pointer.
A Windows download that carries no signature, or one from a certificate SmartScreen does not know, warns the user before it opens. MyGo signs Windows packages; NSGo wrote them unsigned, and Windows code signing was a roadmap gap. Add it here without the Windows SDK, so a Mac signs what it builds: - internal package cmd/nsgo/authenticode signs a PE image: it parses the headers, computes the Authenticode digest (headers without the checksum and certificate table entry, every section in file order, the bytes between and after them, a short last block padded to 8 bytes), writes a WIN_CERTIFICATE holding a PKCS nsgo-dev#7 SignedData over SpcIndirectDataContent and recomputes the PE checksum. A re-signed image replaces the old signature rather than appending a second. The digest covers SpcIndirectDataContent's value, not its SEQUENCE header, as Authenticode readers check it. - sign.certificate (a .pfx, NSGO_CERTIFICATE_PASSWORD) signs the executable, the command companion, the resources' PE images that carry no signature, and the installer. sign.sign_command signs them with a tool of its own, %1 standing for the path, for a hardware token or a cloud service. sign.timestamp_url, DigiCert's unless "none", asks an RFC 3161 server for a token, which the signer carries as its unsigned attribute so the signature outlives the certificate. - The installer's uninstaller comes from makensis, so it signs through NSIS's !uninstfinalize running `nsgo sign-uninstaller` with the certificate in the environment; that needs NSIS 3.08, and without it the uninstaller stays unsigned. - -certificate, -sign-command and -timestamp-url replace the three from the command line. build refuses two ways of signing at once, a certificate on a build that names no Windows target, and it refuses a certificate outside a release build. Verified: the package's tests, including osslsigncode's verification of an image signed here, and a real build of examples/hello whose exe, setup and uninstaller each verify with osslsigncode. The MSIX stays unsigned: AppxSignature.p7x is a package signature of its own, recorded in the roadmap.
f72ed88 added a call to nsisScript before the harmonyos branch gave it a context, and the rebase that replayed the signing change updated the two calls above it but not this one, so cmd/nsgo did not vet or test.
widget.Update and Available now call publish and available, which the branch defines in widget_js.go and widget_other.go (!darwin && !js) but not in widget_darwin.go, so the widget package, and every app that imports it, stopped building for macOS and iOS (undefined: publish, undefined: available). widget_darwin.go gets both, with the body Update and Available had before: write the timeline into the app group's container and ask WidgetKit to reload the kind.
hdc exits 0 when a device refuses a HAP or aa start cannot start the ability, and says so only in what it prints. build -run read only the exit status, so on a phone that refuses an unsigned HAP (code 9568320, no signature file) it reported success with nothing installed, and nsgo test -target harmonyos waited its two minutes and then blamed the page for not starting. The install and start steps now also fail on the error line hdc prints, with its output, for both -run and the test runner.
The display clock fires every vsync and each tick queued another runJavaScript('nsgoFrame()') whether or not the page had finished the last one. Whenever a frame took longer than a vsync, ticks piled up in the page: on a Huawei Enjoy 90 Plus (HarmonyOS 7.0) up to 112 frames were queued at launch with --nsgo-fps and 12 to 15 after each navigation, and every touch, scroll report and event the host sent waited behind them, so taps answered late or seemed lost. A tick now finds the pending frame and skips; the engine's clock reads the time, so the next frame catches up. With the change at most one frame is queued.
syncNode writes a view it creates but left its dirty flag set, so the next batch that reached the view's parent wrote it, and every view under it, again: after each navigation in the gallery a small follow-up batch rewrote about 300 views and took 47 to 77 ms on the phone. Making a view now spends its flag; that batch takes 4 to 8 ms.
A structural batch walked the whole tree and wrote every view's attributes again, so that a batch naming only deleted views would still reach the parents that drop them. Every navigation, and every batch a list sends as it recycles rows while scrolling, paid for the full tree: on the phone a scroll batch in the Photos demo took up to 126 ms on the UI thread (1.7 s over three flings) and navigating back 104 to 119 ms. The tree now records the parents whose children a batch inserted, moved or removed, and the renderer syncs those children (removals first, so a moved view leaves its old parent before the new one takes it) and then writes only the views the batch named; a new root is still drawn in full, and a batch that changes a screen's header or a scroll view's sticky cells marks that view, as those are drawn when the view is written. Removing stale children collects the wanted ones once instead of scanning every child for each, which was quadratic in a long list. Navigating back now takes 71 to 81 ms, and with the next commit the scroll batches take at most 10 ms (113 ms over the same flings).
style wrote every common attribute of a view, and text every font attribute, each time the view was written, and each write crosses into ArkUI and dirties the node. A navigation in the gallery writes about 700 views, new ones and the covered page's resized ones, so style alone took 95 to 160 ms of it on the phone. The renderer now keeps what it last wrote to each node and writes an attribute only when it differs, sets a press handler once, and takes a Stack or Text it just made as holding ArkUI's defaults, so a new view's default background, corners, border, opacity, transform and visibility are not written at all. A navigation's structural batch went from 187 to 191 ms to 110 to 115 ms, and navigating back from 71 to 81 ms to 50 to 77 ms.
Rich text is a Text of Spans built with ForEach, which was keyed by each run's index alone. ForEach keeps the child of a key it has already built, so when a batch changed a run's text or style but not the number of runs, the span kept what it first showed: on the phone the gallery's interval counter stayed at 0 while its timer ticked every second, and any label, value or counter drawn as rich text ignored the taps that changed it, which read as taps getting no response. A run is now keyed by its index and its content, so a changed run is built again.
driver.FindKey now takes the keys the focused view uses and returns the binding's ID, which EventKey carries in Count; the page knows only whether a text input has the focus, so it reports KeyUseText alone. Main also added items and events the preview does not answer yet; the coverage table lists them so the suite passes and their gap stays visible.
houko
force-pushed
the
feat/harmony-main
branch
from
November 16, 2026 22:48
7beb0c3 to
b2ae23f
Compare
5 of 17 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.






Summary
Adds
harmonyosas a build and test target.nsgo build -target harmonyosassembles aHAP in Go, the engine runs as WebAssembly inside ArkWeb, and an ArkTS render layer applies
each mount batch to ArkUI views.
This is a preview, not a shipping target, and is scoped as such:
-target all, since its packages are unsigned;docs/architecture/harmonyos.mdmarks it Status: preview and lists what eachbackend limit costs;
cmd/nsgo/harmony/items_test.go), so adriver kind that loses its renderer, or gains one still listed as unsupported, fails
the suite.
What the renderer draws
Layout and glyphs are the platform's: the engine lays every view out and measures text
through ArkUI's own measurer, then the render layer places native components at those
frames.
Views: boxes with background, border, corners, opacity; text with spans; text fields;
scroll views with drag, glide, rest, pull to refresh and sticky cells; images from URLs,
embedded bytes or the app's resources at the device's pixel density; canvases replayed
from the engine's draw ops; web views; videos; modals; screens with a system header.
Input and system: every finger on the surface (the engine hit-tests them, so drags on a
slider or a sheet follow), physical keyboard shortcuts matched against the app's keymap,
the back gesture, the system alert dialog, clipboard text and images out, opened links,
the photo/file/folder pickers, the save dialog, the camera picker, a home-screen card
written through
widget.Update, and the--nsgo-fpsmonitor.How it works
GOOS=js/wasm, the no-DOM build the mini programs userawfileinonInterceptRequestJavaScriptProxy(answers synchronously); ArkTS→page messagesFrameNodetree:typeNodeforStack,Text,TextInput,Scroll,Image;BuilderNodefor spans, canvases, images fromarchive/zip;module.jsonandpack.infoare plain JSONPackageswaps byte for byte, so one host serves every app without the SDK;hvigorwandOHOS_BASE_SDK_HOMEpresent,CompileHostbuilds a host for the app's own id insteadnsgo test -target harmonyosbuilds the tests as the HAP's module and drives the app in the pagensgo doctorreports whetherhdcand the SDK are present, and-runinstalls andstarts the ability, passing the engine's flags as Want parameters (
--ps/--pb), so--nsgo-fpscan be turned on for an already-built HAP.Fixes found by running a real app
The second commit fixes what only showed up once a non-trivial app ran on the emulator:
syncNodewas gated ondirty, so astructural batch naming only deleted views never walked to the parents whose
syncChildrendrops their ArkUI children. The stale modal then swallowed every laterpress — the app looked frozen after its first interaction. Structural batches now sync
in full; ordinary batches still write only the views they name.
BuilderNodeleaves ignored their position, so canvases and rich text landed at theparent's top-left corner. They are wrapped in a
Stackthat holds the frame.measureTextSizeanswers the constraint's width, not the text's, which made everycentred label start at the left edge. Wrapped text is measured again without a
constraint and takes the smaller width.
TYPE_SYSTEM, which a full-screen window does not fillwith the navigation indicator, so a bottom bar sat under the gesture area. It now
takes the larger of that and
TYPE_NAVIGATION_INDICATOR.lineHeight, dropping the glyphs intothe middle of the box; it uses the font's line height and aligns to the top.
page that no longer loaded, and
aa startbrought that back instead of starting thenew one.
-runandnsgo testnow force-stop first, and a test run stops its own HAPwhen it ends so it cannot cover a later launch.
hilog; it now fails aftertwo minutes with a message saying the page did not start.
Known limitations
Each has its reason in
docs/architecture/harmonyos.md#constraints:NativeandShaderviews: a Go app ships no ArkTS component to mount, and ArkTS hasno WebGL or WGSL.
login).
READ_PASTEBOARDissystem_basic),so a read answers empty; writing works.
SaveOptions.Pathis unsupported —js/wasmhas no filesystem — so onlySaveOptions.Datasaves.fetch('resource://rawfile/...')is refused; the host serves those requests itself.ItemBackPreview/ItemHistoryare not wired.Testing
Run on the OpenHarmony emulator (x86_64, API 24):
go test ./cmd/nsgo/harmony/... ./internal/platform/harmonyos/...— including thecoverage tables, which parse
internal/driver's constants and the host'sIndex.etssothat a silently-dropped kind cannot pass.
a dialog opened and dismissed, a note created, titled and typed into, and back to the
list — the first interaction used to freeze the app, which is how (1) was found.
nsgo test -target harmonyos -run TestPhoneTabspasses on the device.go vetclean;gofmtclean; the wasm backend and the tool build.Not covered by this PR, and worth knowing before merging: the emulator is the only device
this ran on, no test drives every view kind through the device-hosted path, and the rest
of the app surfaces (menus, password dialogs, undo/redo) were not exercised on device.
Reviewer notes
module.jsonundercmd/nsgo/harmony/host/arecommitted binaries.
host/build.shrebuilds them with DevEco;nsgo buildnever needsit.
.gitignorenow excludes signing material (.ohos/, keystores, profiles), with the apktests' fixtures excepted.
internal/platform/opsandinternal/platform/textrunsmove intolayering_test.go'sshared platform list, since the HarmonyOS backend and the mini programs both use them.