-
Notifications
You must be signed in to change notification settings - Fork 5k
Ban <iostream> from release builds and drop it from bun-uws #35256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
041c0ae
Ban <iostream> from release builds; drop it from bun-uws
robobun 54bce83
[autofix.ci] apply automated fixes
autofix-ci[bot] 18dc9eb
Bump WebKit to 2f7e89c84f (simdutf iostream drop + compile-time ban)
robobun 0179c70
Bump WebKit to af2e8dc639 (pick up #321 lazy WebAssembly namespace)
robobun 76610d3
bun-uws: drop the stderr logging from validation terminates
robobun 5d19ebc
bun-uws: drop stale 'Notify user' comments at checkIteratingSubscribe…
robobun a4a7e9c
source-lints/no-iostream: guard against a vacuous pass when the glob …
robobun ea56cdc
ci: retrigger
robobun f58b0fd
Merge branch 'main' into farm/d433c90c/drop-uws-iostream
Jarred-Sumner a7bc0c7
source-lints/no-iostream: assert scanned > 0 per root, not in aggregate
robobun 507ab81
webkit.ts: restore the why-comment dropped by the main merge
robobun eba02a1
Revert "webkit.ts: restore the why-comment dropped by the main merge"
robobun df60661
Merge branch 'main' into farm/d433c90c/drop-uws-iostream
Jarred-Sumner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // This directory is placed first on the -I search path for Bun's C++ compile | ||
| // (release profile), so `#include <iostream>` resolves here instead of the | ||
| // toolchain header. | ||
| // | ||
| // <iostream> is unlike <ostream>/<istream>/<sstream>/<fstream>: on libstdc++ | ||
| // it emits a reference to std::ios_base_library_init (or, on configurations | ||
| // without the init-priority attribute, a static `std::ios_base::Init __ioinit` | ||
| // object) in every translation unit that includes it. One such reference | ||
| // anywhere in the link pulls libstdc++'s globals_io.o in, whose | ||
| // _GLOBAL__sub_I.00090_globals_io.cc static initializer constructs | ||
| // cin/cout/cerr/clog and their wchar_t siblings before main. That in turn | ||
| // references the full std::locale facet set (ctype / numpunct / moneypunct / | ||
| // timepunct / messages, for both char and wchar_t), so roughly fifty libstdc++ | ||
| // functions run on every Bun process start. | ||
| // | ||
| // Bun never touches C++ iostreams at runtime. Use fputs/fprintf for error | ||
| // output, or WTF's dataLog()/PrintStream in JSC-adjacent code. | ||
| // | ||
| // Because Bun's own headers include wtf/SIMDUTF.h (and others) from the | ||
| // WebKit prebuilt, this shim also catches a WebKit header that starts | ||
| // including <iostream>: it will fail Bun's release build rather than silently | ||
| // regressing startup. | ||
| #ifndef BUN_ALLOW_IOSTREAM | ||
| #error "<iostream> is banned in Bun release builds: it drags std::ios_base::Init and the full std::locale facet set into pre-main startup. Use <cstdio> fputs/fprintf for stderr output. See src/banned-includes/iostream." | ||
| #else | ||
| #include_next <iostream> | ||
| #endif |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { Glob } from "bun"; | ||
| import { expect, test } from "bun:test"; | ||
| import { readFileSync } from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| // <iostream> is unique among the C++ stream headers: on libstdc++ it emits a | ||
| // reference to std::ios_base_library_init in every TU that includes it, which | ||
| // forces libstdc++'s globals_io.o into the link. That object's | ||
| // _GLOBAL__sub_I.00090_globals_io.cc initializer constructs cin/cout/cerr/clog | ||
| // (and the wchar_t variants) before main, dragging the full std::locale facet | ||
| // set (ctype/numpunct/moneypunct/timepunct/messages for char and wchar_t) into | ||
| // every Bun process startup. Bun never touches C++ iostreams at runtime. | ||
| // | ||
| // <ostream>, <istream>, <sstream> and <fstream> are fine: they declare the | ||
| // stream types but do not emit the static Init object. If you need to print to | ||
| // stderr from C++, use fputs/fprintf. | ||
| // | ||
| // The upstream source of the original leak was the vendored simdutf header | ||
| // inside WebKit (Source/WTF/wtf/simdutf/simdutf_impl.h); that is handled by | ||
| // the WebKit pin. This test guards Bun's own compiled C++ so the initializer | ||
| // cannot creep back in through packages/ or src/. | ||
| test("C++ sources compiled into Bun do not include <iostream>", async () => { | ||
| const repoRoot = path.resolve(import.meta.dir, "..", "..", ".."); | ||
|
|
||
| const roots = ["src", "packages/bun-uws", "packages/bun-usockets"]; | ||
| // sizegen.cpp is a build-time code generator, not linked into the bun binary. | ||
| const allowlist = new Set(["src/jsc/headergen/sizegen.cpp"]); | ||
|
|
||
| const iostreamInclude = /^\s*#\s*include\s*<iostream>/m; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const violations: string[] = []; | ||
|
|
||
| for (const root of roots) { | ||
| const glob = new Glob("**/*.{h,hpp,hxx,cpp,cc,cxx}"); | ||
| for await (const rel of glob.scan({ cwd: path.join(repoRoot, root) })) { | ||
| const relFromRepo = path.join(root, rel).replaceAll("\\", "/"); | ||
| if (allowlist.has(relFromRepo)) continue; | ||
| const source = readFileSync(path.join(repoRoot, root, rel), "utf8"); | ||
| if (iostreamInclude.test(source)) { | ||
| violations.push(relFromRepo); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| violations.sort(); | ||
| expect(violations).toEqual([]); | ||
|
Check warning on line 45 in test/internal/source-lints/no-iostream-include.test.ts
|
||
|
robobun marked this conversation as resolved.
|
||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.