Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mordant-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"defaulted_failure:src/bun_core/string/immutable.rs" = 1

[bun_css]
"derived_field:src/css/properties/margin_padding.rs" = 105

[bun_install]
"defaulted_failure:src/install/npm.rs" = 1
Expand Down
45 changes: 45 additions & 0 deletions scripts/build/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export function emitCodegen(n: Ninja, cfg: Config, sources: Sources): CodegenOut
emitBindgen(ctx);
emitJsSink(ctx);
emitObjectLuts(ctx);
emitCompressedEmbeds(ctx);

n.phony("codegen", o.all);
n.blank();
Expand Down Expand Up @@ -419,6 +420,50 @@ function emitBunError({ n, cfg, sources, o, dirStamp }: Ctx): void {
o.rustInputs.push(...outputs);
}

/**
* zstd-compressed twins of assets that Bun never executes or parses itself —
* the shell completion scripts and the JS/CSS bundles that are only ever
* shipped to a browser (dev-server client runtime, error overlay, error page).
* Release builds embed these via `bun_zstd::embed_compressed!` and inflate on
* first use instead of carrying the plain text in `.rodata`. Anything that runs
* inside Bun (builtin modules, bake.server.js, FFI headers, …) stays as-is.
* Output: `<codegenDir>/compressed/<name>.zst`.
*/
function emitCompressedEmbeds({ n, cfg, o, dirStamp }: Ctx): void {
const script = resolve(cfg.cwd, "src", "codegen", "compress-embed.ts");
const assets: { input: string; name: string }[] = [
// Repo files, named by repo-relative path.
...[
"completions/bun.bash",
"completions/bun.zsh",
"completions/bun.fish",
"src/runtime/bake/bun-framework-react/client.tsx",
].map(rel => ({ input: resolve(cfg.cwd, rel), name: rel })),
// Codegen outputs (browser bundles), named `codegen/<path in codegenDir>`.
...[
"bake.client.js",
"bake.error.js",
"bun-error/index.js",
"bun-error/bun-error.css",
"node-fallbacks/react-refresh.js",
].map(rel => ({ input: resolve(cfg.codegenDir, rel), name: `codegen/${rel}` })),
];
for (const { input, name } of assets) {
const out = resolve(cfg.codegenDir, "compressed", `${name}.zst`);
n.build({
outputs: [out],
rule: "codegen",
inputs: [script, input],
orderOnlyInputs: [dirStamp],
vars: { cwd: cfg.cwd, desc: `compressed/${name}.zst`, args: shJoin(cfg, ["run", script, input, out]) },
});
o.all.push(out);
// Debug reads the originals at runtime; only release embeds these.
if (cfg.debug) o.rustOrderOnly.push(out);
else o.rustInputs.push(out);
}
}

function emitRuntimeJs({ n, cfg, o, dirStamp }: Ctx): void {
const src = resolve(cfg.cwd, "src", "runtime.bun.js");
const out = resolve(cfg.codegenDir, "runtime.out.js");
Expand Down
29 changes: 26 additions & 3 deletions src/ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2049,13 +2049,24 @@ impl Log {
})
}

#[cold]
#[inline]
pub fn add_range_error_with_notes(
&mut self,
source: Option<&Source>,
r: Range,
text: impl IntoText,
notes: Box<[Data]>,
) {
self.add_range_error_with_notes_text(source, r, text.into_text(), notes)
}

#[cold]
fn add_range_error_with_notes_text(
&mut self,
source: Option<&Source>,
r: Range,
text: Cow<'static, [u8]>,
notes: Box<[Data]>,
) {
self.errors += 1;
let data = self.tracked_range_data(source, r, text);
Expand All @@ -2071,8 +2082,15 @@ impl Log {
self.msgs.push(msg);
}

/// Generic only over the text conversion; the body is shared so each
/// `&[u8; N]` literal length does not get its own copy.
#[inline]
pub fn add_error(&mut self, source: Option<&Source>, loc: Loc, text: impl IntoText) {
self.add_error_text(source, loc, text.into_text());
}

#[cold]
pub fn add_error(&mut self, _source: Option<&Source>, loc: Loc, text: impl IntoText) {
fn add_error_text(&mut self, _source: Option<&Source>, loc: Loc, text: Cow<'static, [u8]>) {
self.errors += 1;
let data = self.tracked_range_data(
_source,
Expand Down Expand Up @@ -2768,9 +2786,14 @@ impl Source {
}
}

#[inline]
pub fn range_data(source: Option<&Source>, r: Range, text: impl IntoText) -> Data {
range_data_text(source, r, text.into_text())
}

fn range_data_text(source: Option<&Source>, r: Range, text: Cow<'static, [u8]>) -> Data {
Data {
text: text.into_text(),
text,
location: Location::init_or_null(source, r),
}
}
Expand Down
Loading
Loading