Skip to content

build: generate bun_core::build_options from Config#30749

Merged
dylan-conway merged 2 commits into
mainfrom
claude/build-options-rs-from-config
May 15, 2026
Merged

build: generate bun_core::build_options from Config#30749
dylan-conway merged 2 commits into
mainfrom
claude/build-options-rs-from-config

Conversation

@dylan-conway
Copy link
Copy Markdown
Member

bun_core::build_options (the Rust analogue of Zig's @import("build_options") — version, sha, baseline, canary, paths) was populated via a dozen BUN_* env vars that scripts/build/rust.ts exported and bun_core/lib.rs read back with option_env!. The names were maintained in two places, and a bare cargo check / rust-analyzer saw placeholder defaults ("0000…" sha, fake version, mixed-separator Windows BASE_PATH).

Now scripts/build/buildOptionsRs.ts writes ${codegenDir}/build_options.rs at configure time with literal pub consts straight from the resolved Config, and bun_core include!()s it (same pattern as generated_classes.rs / cpp.rs). writeIfChanged keeps the mtime stable so an unchanged sha doesn't recompile bun_core and its dependents.

Target/profile-derived constants (ENABLE_TINYCC, ENABLE_ASAN, ENABLE_LOGS) stay as cfg!() inside the generated file so cross-target cargo check still evaluates them per-triple.

Also:

  • adds src/bun_core/build.rs to export BUN_CODEGEN_DIR + rerun-if-changed (mirrors src/{jsc,runtime}/build.rs)
  • wires cfg.fuzzilliENABLE_FUZZILLI (was hardcoded false)
  • drops the Windows mixed-separator BASE_PATH fallback hack

Verified: bun bd --revision reports the configured sha; empty-commit + rebuild reports the new sha; reconfigure with unchanged Config preserves build_options.rs mtime; cargo check -p bun_core passes.

@robobun
Copy link
Copy Markdown
Collaborator

robobun commented May 15, 2026

Updated 1:14 AM PT - May 15th, 2026

@dylan-conway, your commit ca6b0cb has 1 failures in Build #54526 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 30749

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

bun-30749 --bun

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Review Change Stack

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: d1574076-3192-46ea-b8e3-5c4ad5c57af4

📥 Commits

Reviewing files that changed from the base of the PR and between 5b0e92c and ca6b0cb.

📒 Files selected for processing (2)
  • scripts/build/buildOptionsRs.ts
  • src/bun_core/util.rs
💤 Files with no reviewable changes (1)
  • src/bun_core/util.rs

Walkthrough

This PR migrates bun_core::build_options from placeholder inline Rust definitions to a codegen-driven architecture. A TypeScript generator produces build_options.rs at configure time, a Rust build script validates the codegen directory and outputs, and the Rust module now includes the generated file instead of defining constants inline.

Changes

Build options codegen migration

Layer / File(s) Summary
TypeScript codegen generator and integration
scripts/build/buildOptionsRs.ts, scripts/build/codegen.ts, scripts/build/CLAUDE.md
generateBuildOptionsRs(cfg: Config) produces build_options.rs with version components, release/baseline flags, and target-sensitive cfg!() expressions. The function is imported and called during emitCodegen, its output added to o.all and o.rustInputs to ensure Rust build ordering. Module inventory documentation is updated.
Rust build script for codegen directory validation
src/bun_core/build.rs
New build script locates BUN_CODEGEN_DIR relative to the repo root (with default build/debug/codegen), validates that build_options.rs exists, and emits Cargo directives to export BUN_CODEGEN_DIR and track rerun conditions on codegen outputs.
Module include and build environment cleanup
src/bun_core/lib.rs, scripts/build/rust.ts
bun_core::build_options now contains include! from the generated file instead of inline definitions. Build metadata environment variables (BUN_GIT_SHA, BUN_VERSION_*, etc.) are removed from cargo env setup in rust.ts since they are now computed at codegen time.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary change: moving bun_core::build_options generation from environment variables to a Config-driven code generation approach.
Description check ✅ Passed The description comprehensively covers what the PR does, how it works, design decisions, and verification steps, but lacks explicit 'How did you verify your code works?' section matching the template.
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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/build/buildOptionsRs.ts`:
- Around line 31-33: rbstr currently emits Rust byte-string literals using
JSON.stringify which leaves non-ASCII chars intact and produces invalid b"..."
syntax; change rbstr to encode the input string as UTF-8 bytes (e.g.,
Buffer.from(s, "utf8") or similar) and emit a Rust byte-array literal like
&[<comma-separated 0xNN values>] (or &[<decimal bytes>]) instead of b"...",
ensuring the length is preserved if you need a fixed-size array; update the
rbstr function to build that comma-separated byte list from the UTF-8 bytes
rather than using JSON.stringify(s).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 49aaa0d9-c587-4959-8ab1-279982995a08

📥 Commits

Reviewing files that changed from the base of the PR and between 428f61e and 5b0e92c.

📒 Files selected for processing (6)
  • scripts/build/CLAUDE.md
  • scripts/build/buildOptionsRs.ts
  • scripts/build/codegen.ts
  • scripts/build/rust.ts
  • src/bun_core/build.rs
  • src/bun_core/lib.rs

Comment thread scripts/build/buildOptionsRs.ts Outdated
Comment thread scripts/build/buildOptionsRs.ts Outdated
Comment thread src/bun_core/lib.rs
@dylan-conway
Copy link
Copy Markdown
Member Author

@robobun can you address the reviews

Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

LGTM — both prior review points addressed (.as_bytes() for non-ASCII paths, const_parse_u32 removed).

Extended reasoning...

Overview

This PR migrates bun_core::build_options from a dozen option_env!("BUN_*") reads (with names duplicated between rust.ts and lib.rs) to a single generated build_options.rs written at configure time and include!()'d. Touches 7 files: a new TS generator (buildOptionsRs.ts), wiring in codegen.ts, env-var removal from rust.ts, a new src/bun_core/build.rs (mirrors src/{jsc,runtime}/build.rs), the include! swap in lib.rs, dead-code removal in util.rs, and a doc table row in CLAUDE.md.

Prior feedback addressed

My previous review flagged two issues, both now fixed in commit ca6b0cb:

  • rbstr() now emits "...".as_bytes() instead of b"...", so non-ASCII repo paths (e.g. C:\Users\Müller\) compile — restoring parity with the old option_env! → v.as_bytes() path.
  • The orphaned const_parse_u32 helper has been deleted from util.rs.

Security risks

None. This is build-system plumbing that changes how compile-time constants reach bun_core (file vs env vars), not what they are. No user input, no network, no auth, no runtime code paths affected. The generated values (sha, version, paths) are identical to what the env-var handshake produced.

Level of scrutiny

Low-to-moderate. The pattern is not novel — it exactly mirrors the existing generated_classes.rs / cpp.rs / generated_host_exports.rs codegen-then-include! flow, and the new build.rs is a near-copy of src/jsc/build.rs / src/runtime/build.rs. If anything here were wrong, it would manifest as an immediate, loud build failure (CI already validates cargo build end-to-end), not a subtle runtime bug. The one CI failure (node-http-backpressure.test.ts SIGKILL on aarch64) is unrelated to build infrastructure.

Other factors

  • writeIfChanged preserves mtime so unchanged reconfigures don't cascade-recompile bun_core — author verified this explicitly.
  • Target-derived constants (ENABLE_TINYCC/ENABLE_ASAN/ENABLE_LOGS) correctly stay as cfg!() so cross-target cargo check still works.
  • rustInputs push + rerun-if-changed give correct incremental-rebuild semantics on both the ninja and cargo sides.
  • Net deletion of duplicated state (env-var name list maintained in two places → one generator).

@dylan-conway dylan-conway merged commit bb1973e into main May 15, 2026
76 of 77 checks passed
@dylan-conway dylan-conway deleted the claude/build-options-rs-from-config branch May 15, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants