Skip to content

libuv_sys: restore uv_translate_sys_error / uv_os_getppid (Windows build of main) and lint crate references - #38733

Closed
robobun wants to merge 1 commit into
mainfrom
farm/a3aff90a/libuv-sys-restore-windows-externs
Closed

robobun wants to merge 1 commit into
mainfrom
farm/a3aff90a/libuv-sys-restore-windows-externs

Conversation

@robobun

@robobun robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fix

  • src/libuv_sys/libuv.rs: restore the two extern "C" declarations. Signatures match src/jsc/bindings/libuv/uv.h (int uv_translate_sys_error(int), uv_pid_t uv_os_getppid(void), uv_pid_t is int on Windows) and the three call sites; they are the lines Remove dead code from libuv_sys, cares_sys, simdutf FFI, test_runner, and C++ bindings #37332 removed.
  • test/internal/source-lints/libuv-sys-references.test.ts: a source lint that collects every name referenced through bun_libuv_sys from src/ (bun_libuv_sys::x, bun_sys::windows::libuv::x, the uv:: / libuv:: aliases in files that import the crate, and use ...::{...} lists) and requires each to be an item the crate defines or re-exports. On main it fails with exactly the three file:line pairs rustc reports above; with the restore it passes. It runs on any host in the source-lints workflow (which also runs on merge_group), so the same class of break is reported in seconds instead of after the Windows build. It does not replace rust:check-all: only crate-root names are checked, not signatures.
  • Verified: cargo check --workspace --target x86_64-pc-windows-msvc and --target aarch64-pc-windows-msvc both exit 0 with this change (the x64 one reproduces the three errors without it); bun bd test test/internal/source-lints/libuv-sys-references.test.ts passes (~1.7s debug, ~0.1s release) and fails on main; bun test test/internal/source-lints/ all green; cargo fmt --check clean.

Background

cargo check on the Windows targets, before and after

Before (main, x86_64-pc-windows-msvc, --keep-going):

src/runtime/node/node_cluster_binding.rs:391:50: error[E0425]: cannot find function `uv_translate_sys_error` in crate `bun_libuv_sys`: not found in `bun_libuv_sys`
src/runtime/node/node_util_binding.rs:75:46: error[E0425]: cannot find function `uv_translate_sys_error` in crate `bun_libuv_sys`: not found in `bun_libuv_sys`
src/runtime/ipc_host.rs:374:37: error[E0425]: cannot find function `uv_os_getppid` in crate `bun_libuv_sys`: not found in `bun_libuv_sys`
error: could not compile `bun_runtime` (lib) due to 3 previous errors

After (this branch):

x86_64-pc-windows-msvc:  Finished `dev` profile [unoptimized + debuginfo] target(s) in 46.23s   (exit 0, no warnings)
aarch64-pc-windows-msvc: Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 09s   (exit 0, no warnings)

Lint on main (git stash push -- src/ && bun bd test test/internal/source-lints/libuv-sys-references.test.ts):

+   "src/runtime/ipc_host.rs:374: bun_libuv_sys::uv_os_getppid",
+   "src/runtime/node/node_cluster_binding.rs:391: bun_libuv_sys::uv_translate_sys_error",
+   "src/runtime/node/node_util_binding.rs:75: bun_libuv_sys::uv_translate_sys_error",

The lint currently resolves 645 references against 559 crate names. Comments are skipped per match (a hit preceded by // on its line) rather than by stripping them first: src/runtime/api/bun/subprocess.rs:205 has build/*/codegen inside a // comment, and a stripping pass treats that /* as opening a block comment that hides real code down to line 1529, including a real libuv reference at line 1266.

…te references

The dead-code sweep in #37332 removed both extern declarations from
bun_libuv_sys. #31829 merged in between and calls them from three
cfg(windows) blocks (node_cluster_binding.rs, node_util_binding.rs,
ipc_host.rs), so bun_runtime no longer compiles on Windows; the posix
lanes never type-check those blocks.

Restore the two declarations and add a source lint that checks every
name referenced through bun_libuv_sys from src/ against the items the
crate defines, so the next removal of a declaration with a Windows-only
caller fails on every host in seconds.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0d80fc30-b8e9-4b04-945c-ec8ae33d3c41

📥 Commits

Reviewing files that changed from the base of the PR and between e7460e3 and c168b36.

📒 Files selected for processing (2)
  • src/libuv_sys/libuv.rs
  • test/internal/source-lints/libuv-sys-references.test.ts

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

@robobun

robobun commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 8:05 PM PT - Aug 14th, 2026

❌ @robobun, your commit c168b36 has 1 failures in Build #96806 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 38733

That installs a local version of the PR into your bun-38733 executable, so you can run:

bun-38733 --bun

@robobun

robobun commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: closed, superseded by c04101b on main, which restores the same two declarations. See the closing comment below for why this branch is not rebased instead (a clean merge would declare uv_translate_sys_error twice and fail the Windows build with E0428).

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — straightforward Windows build fix restoring two FFI declarations, plus a source-lint to catch the same class of break earlier.

What was reviewed

  • Restored signatures match uv.h (int uv_translate_sys_error(int), uv_pid_t uv_os_getppid(void) with uv_pid_t = c_int on Windows) and the three #[cfg(windows)] callers in node_cluster_binding.rs, node_util_binding.rs, and ipc_host.rs.
  • Confirmed these are exactly the lines #37332 deleted; placement in the extern "C" block matches neighboring declarations.
  • New lint follows the test/internal/source-lints/ conventions (README criteria: no spawn, no built binary; same shape as primordials-exports.test.ts), sorts glob output for determinism, normalizes \\ → /, and guards against vacuous passes with referenced > 200.
  • Checked the alias-gating (importsCrate) so files with an unrelated uv:: (e.g. bun_core's own windows_sys::libuv) are not falsely flagged; crateNames() is intentionally a superset so the lint only reports definite misses.
Extended reasoning...

Overview

Two-part change: (1) restore uv_translate_sys_error and uv_os_getppid extern "C" declarations in src/libuv_sys/libuv.rs that #37332 removed as dead but which #31829 (merged in between) started calling from three #[cfg(windows)] sites, breaking the Windows build of main; (2) add test/internal/source-lints/libuv-sys-references.test.ts, a textual lint that any name referenced through bun_libuv_sys / bun_sys::windows::libuv / the uv:: and libuv:: aliases is defined in src/libuv_sys/, so this class of cfg-gated dangling reference surfaces on any host in seconds.

Security risks

None. The FFI restore re-adds two pre-existing libuv function declarations with signatures verified against src/jsc/bindings/libuv/uv.h and uv/win.h (uv_pid_t is int on Windows, matching pub type uv_pid_t = c_int). No new unsafe code paths, no user-input handling. The test only reads source files.

Level of scrutiny

Low-to-medium. The libuv.rs change is a mechanical revert of two lines to unbreak main on Windows — the compiler is the authority and the PR body shows both Windows targets pass cargo check. The new lint is test-only infrastructure in an established directory with ~20 sibling lints of the same shape; it is deliberately over-approximate on the definition side (impl methods and nested-module items count) so it can only fire on definite misses, and the alias regexes are gated per-file on a real use of the crate to avoid false positives from unrelated uv:: / libuv:: bindings.

Other factors

  • Verified the three call sites exist at the cited lines and use the restored functions with matching types (c_int in/out for the translator, uv_pid_t cast to u32 for getppid).
  • The lint mirrors primordials-exports.test.ts in structure (glob + sort, path-separator normalization, violations array, vacuous-pass guard) and satisfies the source-lints README criteria (no bunExe(), no bun:internal-for-testing, no Bun.build).
  • The comment-handling choice (per-match // check instead of stripping) is justified in-file with a concrete counterexample from the tree; the inLineComment helper correctly handles the start-of-file case via lastIndexOf returning -1.
  • PR body documents that the test fails on unfixed main with exactly the three rustc-reported sites and passes with the restore, satisfying the fails-for-the-right-reason requirement.

@robobun

robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author

Same fix landed in parallel in #38735 (branch farm/4e6aa17d/restore-libuv-sys-externs: identical 4-line restore in src/libuv_sys/libuv.rs, plus a lint of the same shape in test/internal/source-lints/libuv-sys-exports.test.ts). This PR was opened first, so I am closing #38735 in favor of it. For what it is worth, with the same two declarations cargo check --workspace passes for both x86_64-pc-windows-msvc and aarch64-pc-windows-msvc, and the :windows: build-bun lanes passed in CI on both branches.

@robobun

robobun commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: main already has this fix. c04101b ("Fix merge issue") restored both declarations in src/libuv_sys/libuv.rs directly on main, so the Windows build of main is green again without this PR.

This branch should not be merged on top of that: git merge-tree origin/main <this branch> merges cleanly but ends up with uv_translate_sys_error declared twice in the extern "C" block (main's copy in the misc group, this branch's in a separate errors group), which rustc rejects with E0428 on Windows, the same cfg(windows)-only merge skew this PR was about.

The lint in test/internal/source-lints/libuv-sys-references.test.ts on this branch does not depend on the restore (it passes against current main and failed against the broken main with the three rustc locations). It is independent of the fix, so it is left out of this close; it can be picked up as a standalone change if a source-level guard for this break class is wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant