Skip to content

feat: native addons - #12

Merged
triniwiz merged 4 commits into
mainfrom
feat/native-addons
Sep 26, 2026
Merged

triniwiz merged 4 commits into
mainfrom
feat/native-addons

Conversation

@triniwiz

Copy link
Copy Markdown
Member

No description provided.

The classic engine gains a Node-API provider and a native-addon loader,
so addons built for Node (napi-rs, node-addon-api, ...) load with
require('system_lib://name.node') or require('./name.node').

- napi-v8-shim: the napi-android V8 shim already used by windows-v8,
  compiled against rusty_v8 into nativescript.dll (whole-archive, so every
  napi_* is exported), plus glue to create an env over the classic
  context, run a module's init inside the env's call guard, drain
  deferred finalizers and tear envs down.
- runtime::node_api: the Node-specific half of Node-API -- threadsafe
  functions, async work, env and async cleanup hooks, buffers, callback
  scopes, napi_make_callback, napi_module_register, fatal errors. JS-thread
  work goes through one queue woken by a DispatcherQueue work item (never
  inline in a XAML callout) and drained by runtime_pump_timers.
- runtime::native_addons: resolves system_lib:// next to the executable
  (then the app root), loads with LoadLibraryExW, honours
  node_api_module_get_api_version_v1, and caches exports per path.

runtime_deinit runs addon cleanup hooks and envs down before the isolate
goes away.
NAPI_PRIVATE_KEY created a new unique v8::Private on every call, so
napi_type_tag_object stored the tag under one symbol and
napi_check_object_type_tag looked under another: every check failed.
napi-rs 3 tags each class instance and checks the tag on every method
call and &T argument, so no napi-rs class could be used at all
("Value is not an instance of class ..."). The tag key is now one
Private::ForApi symbol cached on the env.

Affects both engines built on this shim (classic via napi-v8-shim, and
windows-v8).
rAF callbacks ran in a microtask that blocked on DwmFlush() for vsync
and queued itself again while callbacks kept requesting frames. A
continuous rAF loop (any animation, a canvas render loop) therefore
never drained the microtask queue: the UI thread stopped returning to
the dispatcher, XAML stopped rendering and the window went "Not
Responding" while JS kept running at the refresh rate.

requestAnimationFrame now only queues the callback and asks for a frame
(__nsRequestFrame). runtime_pump_timers, which the app template drives
once per compositor frame from CompositionTarget.Rendering (outside the
render walk), runs the queued callbacks once and then drains microtasks
(runtime::animation_frames::pump). Callbacks requested during a frame
run in the next one; nothing waits for vsync on the UI thread.

Tests pump frames explicitly, and a new one checks that rAF does not
run on a microtask drain alone.
The bundle scan (dotnet-tool) is syntactic, so ordinary classes of
bundled libraries (babylon.js, phaser: `class X extends e.Foo` compiled
to __extends IIFEs, minified bases like `Ua.$`) were captured as WinRT
extensions. sbg emitted a proxy deriving from each, which cannot
compile (`public class __16 : Ua.$`), so any app bundling such a library
failed to build.

- sbg drops auto-captured extensions whose base is neither in the WinRT
  metadata it can read nor a dotted identifier rooted at Windows,
  Microsoft, System or NativeScript (the Windows App SDK is not in
  system metadata). Explicitly named proxies (@CSharpProxy) are kept.
- sbg removes the *.g.cs an earlier run generated before generating, and
  the template adds the generated proxies to Compile inside
  RunStaticBindingGenerator, after sbg ran: a glob evaluated with the
  project kept compiling proxies for extensions that no longer exist.
@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 02f92fc3-60f4-4162-86c0-d036329dafb0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@triniwiz
triniwiz merged commit f8d2844 into main Sep 26, 2026
3 checks passed
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.

1 participant