feat: native addons - #12
Merged
Merged
Conversation
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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
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.
No description provided.