Skip to content

build(unified): compile ProcessBindingConstants.cpp standalone - #29582

Merged
dylan-conway merged 1 commit into
mainfrom
farm/43442fcf/unified-nodefsstatbinding-macro-leak
Apr 22, 2026
Merged

dylan-conway merged 1 commit into
mainfrom
farm/43442fcf/unified-nodefsstatbinding-macro-leak

Conversation

@robobun

@robobun robobun commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

Since #29545 (unified C++ sources), test/js/node/fs/fs.test.ts fails on Windows:

error: expect(received).toEqual(expected)
  {
    ...
+   "S_IFBLK": 24576,
    ...
+   "S_IFSOCK": 49152,
    ...
  }
✗ fs.constants

Node.js does not expose S_IFBLK / S_IFSOCK in fs.constants on Windows, and neither did Bun before #29545.

Cause

ProcessBindingConstants.cpp decides which constants to expose via #ifdef:

#ifdef S_IFBLK
    object->putDirect(vm, ..., jsNumber(S_IFBLK));
#endif

NodeFSStatBinding.cpp #defines S_IFBLK / S_IFSOCK on Windows for its own S_ISBLK() / S_ISSOCK() helpers. Both files live in src/bun.js/bindings/, and with N sorted before P, NodeFSStatBinding.cpp is #included first in the same unified TU — its macros leak into ProcessBindingConstants.cpp's #ifdef checks.

ProcessBindingConstants.cpp has 251 #ifdef/#ifndef checks; it is fundamentally sensitive to ambient macro state and should compile in isolation, same as ProcessBindingUV.cpp (already in noUnify for the identical reason with errno/EAI_* macros).

Fix

Add ProcessBindingConstants.cpp to noUnify in scripts/build/unified.ts.

Verification

  • fs.constants test failure reproduces on Windows in every build based on main ≥ 2cf54bf6dd (e.g. #47110, windows-2019-x64 / x64-baseline / win11-aarch64)
  • Not seen on main CI yet only because build #47033 failed at an unrelated aarch64-musl build-cpp step before Windows tests ran
  • Linux/macOS unaffected (S_IFBLK/S_IFSOCK come from <sys/stat.h> there regardless)

ProcessBindingConstants.cpp uses 251 #ifdef checks to decide which
fs.constants / os.constants to expose per-platform. When bundled in
the same unified TU after NodeFSStatBinding.cpp (which #defines
S_IFBLK / S_IFSOCK on Windows for its own S_IS*() helpers), those
macros leak forward and fs.constants gains S_IFBLK/S_IFSOCK on
Windows, breaking Node.js parity and test/js/node/fs/fs.test.ts.

Same class of issue as ProcessBindingUV.cpp which is already in
noUnify for its errno/EAI_* macro dependencies.
@robobun

robobun commented Apr 22, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 5:05 AM PT - Apr 22nd, 2026

❌ @robobun, your commit cdd40d2 has 2 failures in Build #47152 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 29582

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

bun-29582 --bun

@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1426f4a2-d357-495f-a099-04c97bd7e517

📥 Commits

Reviewing files that changed from the base of the PR and between 7a4e667 and cdd40d2.

📒 Files selected for processing (1)
  • scripts/build/unified.ts

Walkthrough

Modified the build configuration to add src/bun.js/bindings/ProcessBindingConstants.cpp to the noUnify allowlist. This prevents the unified-source bundling logic from concatenating this file with sibling .cpp files, avoiding preprocessor directive leakage during compilation.

Changes

Cohort / File(s) Summary
Build Configuration
scripts/build/unified.ts
Added src/bun.js/bindings/ProcessBindingConstants.cpp to the noUnify allowlist to prevent preprocessor #ifdef directives from leaking when compiled after NodeFSStatBinding.cpp.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding ProcessBindingConstants.cpp to standalone compilation in the unified build system.
Description check ✅ Passed The description covers the template sections (Problem/Cause/Fix) and provides thorough context, though it doesn't explicitly label 'How did you verify your code works?'.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@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 addition to the noUnify list following the established ProcessBindingUV.cpp pattern.

Extended reasoning...

Overview

Adds a single entry (src/bun.js/bindings/ProcessBindingConstants.cpp) to the noUnify array in scripts/build/unified.ts, with an explanatory comment. This forces the file to compile as a standalone TU rather than being bundled with siblings in the unified-sources build.

Security risks

None. This is a build-configuration list change with no effect on runtime logic, auth, crypto, or user-facing surface area beyond restoring pre-#29545 behavior for fs.constants on Windows.

Level of scrutiny

Low. The change is mechanical and follows the exact pattern of the entry directly above it (ProcessBindingUV.cpp, excluded for the identical macro-leakage reason). I verified the root-cause claims: NodeFSStatBinding.cpp:55-72 does #define S_IFBLK/S_IFSOCK under #ifndef guards, and ProcessBindingConstants.cpp:659/668 uses #ifdef S_IFBLK/#ifdef S_IFSOCK to gate exposure. Both files live in the same directory and N sorts before P, so the macro leak is real.

Other factors

The PR description is thorough and the fix is the conservative, correct one — ProcessBindingConstants.cpp has 251 #ifdef checks and is fundamentally sensitive to ambient macro state, so isolating it is preferable to #undefing in NodeFSStatBinding.cpp. No bugs were found by the bug hunter. No outstanding reviewer comments.

@dylan-conway
dylan-conway merged commit f344121 into main Apr 22, 2026
60 of 62 checks passed
@dylan-conway
dylan-conway deleted the farm/43442fcf/unified-nodefsstatbinding-macro-leak branch April 22, 2026 06:59
robobun added a commit that referenced this pull request Apr 22, 2026
Main now compiles ProcessBindingConstants.cpp standalone (noUnify),
which is the more robust fix — that file has 251 #ifdef checks and
needs isolation from ambient macro state regardless of which upstream
file leaks. The push/pop wrapper here is no longer needed.
robobun added a commit that referenced this pull request Apr 22, 2026
Main landed #29582 which excludes ProcessBindingConstants.cpp from the
unified-source bundle, so the push_macro/pop_macro bracket in
NodeFSStatBinding.cpp added here is no longer needed to keep
fs.constants correct on Windows.
structwafel pushed a commit to structwafel/bun that referenced this pull request Apr 25, 2026
…sh#29582)

## Problem

Since oven-sh#29545 (unified C++ sources), `test/js/node/fs/fs.test.ts` fails
on Windows:

```
error: expect(received).toEqual(expected)
  {
    ...
+   "S_IFBLK": 24576,
    ...
+   "S_IFSOCK": 49152,
    ...
  }
✗ fs.constants
```

Node.js does not expose `S_IFBLK` / `S_IFSOCK` in `fs.constants` on
Windows, and neither did Bun before oven-sh#29545.

## Cause

`ProcessBindingConstants.cpp` decides which constants to expose via
`#ifdef`:

```cpp
#ifdef S_IFBLK
    object->putDirect(vm, ..., jsNumber(S_IFBLK));
#endif
```

`NodeFSStatBinding.cpp` `#define`s `S_IFBLK` / `S_IFSOCK` on Windows for
its own `S_ISBLK()` / `S_ISSOCK()` helpers. Both files live in
`src/bun.js/bindings/`, and with `N` sorted before `P`,
`NodeFSStatBinding.cpp` is `#include`d first in the same unified TU —
its macros leak into `ProcessBindingConstants.cpp`'s `#ifdef` checks.

`ProcessBindingConstants.cpp` has **251** `#ifdef`/`#ifndef` checks; it
is fundamentally sensitive to ambient macro state and should compile in
isolation, same as `ProcessBindingUV.cpp` (already in `noUnify` for the
identical reason with errno/EAI_* macros).

## Fix

Add `ProcessBindingConstants.cpp` to `noUnify` in
`scripts/build/unified.ts`.

## Verification

- `fs.constants` test failure reproduces on Windows in every build based
on `main` ≥ `2cf54bf6dd` (e.g.
[#47110](https://buildkite.com/bun/bun/builds/47110), windows-2019-x64 /
x64-baseline / win11-aarch64)
- Not seen on `main` CI yet only because build #47033 failed at an
unrelated aarch64-musl build-cpp step before Windows tests ran
- Linux/macOS unaffected (`S_IFBLK`/`S_IFSOCK` come from `<sys/stat.h>`
there regardless)

Co-authored-by: robobun <robobun@users.noreply.github.com>
xhjkl pushed a commit to xhjkl/bun that referenced this pull request May 14, 2026
…sh#29582)

## Problem

Since oven-sh#29545 (unified C++ sources), `test/js/node/fs/fs.test.ts` fails
on Windows:

```
error: expect(received).toEqual(expected)
  {
    ...
+   "S_IFBLK": 24576,
    ...
+   "S_IFSOCK": 49152,
    ...
  }
✗ fs.constants
```

Node.js does not expose `S_IFBLK` / `S_IFSOCK` in `fs.constants` on
Windows, and neither did Bun before oven-sh#29545.

## Cause

`ProcessBindingConstants.cpp` decides which constants to expose via
`#ifdef`:

```cpp
#ifdef S_IFBLK
    object->putDirect(vm, ..., jsNumber(S_IFBLK));
#endif
```

`NodeFSStatBinding.cpp` `#define`s `S_IFBLK` / `S_IFSOCK` on Windows for
its own `S_ISBLK()` / `S_ISSOCK()` helpers. Both files live in
`src/bun.js/bindings/`, and with `N` sorted before `P`,
`NodeFSStatBinding.cpp` is `#include`d first in the same unified TU —
its macros leak into `ProcessBindingConstants.cpp`'s `#ifdef` checks.

`ProcessBindingConstants.cpp` has **251** `#ifdef`/`#ifndef` checks; it
is fundamentally sensitive to ambient macro state and should compile in
isolation, same as `ProcessBindingUV.cpp` (already in `noUnify` for the
identical reason with errno/EAI_* macros).

## Fix

Add `ProcessBindingConstants.cpp` to `noUnify` in
`scripts/build/unified.ts`.

## Verification

- `fs.constants` test failure reproduces on Windows in every build based
on `main` ≥ `2cf54bf6dd` (e.g.
[#47110](https://buildkite.com/bun/bun/builds/47110), windows-2019-x64 /
x64-baseline / win11-aarch64)
- Not seen on `main` CI yet only because build #47033 failed at an
unrelated aarch64-musl build-cpp step before Windows tests ran
- Linux/macOS unaffected (`S_IFBLK`/`S_IFSOCK` come from `<sys/stat.h>`
there regardless)

Co-authored-by: robobun <robobun@users.noreply.github.com>
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.

2 participants