deno
e0bb51f8 - fix(ext/napi): polyfill more libuv symbols from compat layer (#34488)

Commit
98 days ago
fix(ext/napi): polyfill more libuv symbols from compat layer (#34488) ## Summary Native addons that link directly against libuv (e.g. `@sentry-internal/node-cpu-profiler`, which `@sentry/profiling-node` uses) previously failed to load on Deno because they call libuv functions that Deno does not polyfill. Deno only exposed `uv_async_*`, `uv_close`, and `uv_mutex_*`. This PR adds lightweight polyfills for the next layer of common libuv calls so these addons can resolve their `uv_*` undefined symbols at `dlopen` time. ### What's polyfilled - `uv_hrtime` returns a monotonic nanosecond timestamp. - `uv_default_loop` returns a null sentinel (Deno does not run a libuv loop); the timer polyfill below is loop-agnostic. - `uv_handle_set_data` / `_get_data` / `_get_loop` / `_get_type` mirror libuv. - `uv_ref` / `uv_unref` / `uv_has_ref` / `uv_is_active` / `uv_is_closing` are trivially correct stubs. - `uv_cpu_info` returns a non-zero error so callers degrade gracefully (e.g. the Sentry profiler skips per-tick CPU stats but still produces a valid profile). - `uv_timer_init` / `_start` / `_stop` / `_set_repeat` / `_get_repeat` / `_again` is a no-op stub. Native CPU profilers capture their profile via V8's `CpuProfiler` and do not depend on the timer firing; only periodic measurement samples are dropped. - `uv_close` now accepts a null callback and recognizes `UV_TIMER` handles. ### Known limitation Addons that also reach into the V8 C++ ABI directly — including `@sentry/profiling-node` — still fail to load. The V8 static archive shipped via the `v8` crate is built with `-fvisibility=hidden`, so V8 C++ symbols are `LOCAL HIDDEN` in the final Deno binary and cannot be promoted into the dynamic export list via `--export-dynamic-symbol-list` (the linker respects the visibility attribute regardless of the export flag). Resolving this requires building V8 with default visibility for the relevant symbols, which is a `rusty_v8` / `v8` crate change out of scope for this PR. This PR still moves the needle: it fixes the libuv half of the problem and unblocks the broader class of addons that depend solely on libuv (not V8 directly). Refs https://github.com/denoland/deno/issues/26421 Closes denoland/orchid#269 ## Test plan - [x] `cargo check -p deno_napi` - [x] `cargo check -p test_napi` - [x] `cargo clippy -p deno_napi -p test_napi --all-targets` (no errors) - [x] New `napi uv polyfills` test passes — exercises every new symbol via `libuv-sys-lite`, which `dlopen`s them from the host `deno` binary. - [x] Existing `napi uv async keeps event loop alive` test still passes. - [ ] CI --------- Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading