Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ Four independent jobs over the Rust workspace. They share `.github/actions/rust-
| `lolhtml` | `lol-html cargo test` | `cargo test` in `vendor/lolhtml` | yes |
| `mordant` | `mordant` | `bun run rust:mordant` | advisory (`continue-on-error`) |

- `clippy` lints the default targets only (lib and bin): test code was never held to the clippy lint set. Its second step, `cargo check --workspace --all-targets`, type-checks `#[cfg(test)]` code, `tests/` and `benches/` so they keep compiling. Nothing else builds them except the crates `rust:miri` runs.
- `clippy` goes through `scripts/rust-clippy.ts`, which lints the workspace for the three triples of `rustLintTargets` in `scripts/build/rust.ts` (`x86_64-unknown-linux-gnu`, `x86_64-pc-windows-msvc`, `aarch64-apple-darwin`) in one `cargo clippy` run and adds their std itself (`rustup target add`). Clippy never links, so the Linux runner lints all three, and code under `cfg(windows)` or `cfg(target_os = "macos")` is held to the same lints as the rest. A second, short run lints the standalone `bun_shim_impl` binary for Windows: it sits behind the `shim_standalone` feature, so `--workspace` skips it. A lint that fires on one target only, in code every target compiles, is suppressed with `#[cfg_attr(windows, expect(...))]`, not a plain `#[expect]`, which the other targets would report as unfulfilled.
- `clippy` lints the default cargo targets only (lib and bin): test code was never held to the clippy lint set. Its second step, `cargo check --workspace --all-targets`, type-checks `#[cfg(test)]` code, `tests/` and `benches/` so they keep compiling. Nothing else builds them except the crates `rust:miri` runs.
- `clippy`, `miri` and `lolhtml` pin `RUSTUP_TOOLCHAIN` at the workflow level (kept in sync with `channel` in `rust-toolchain.toml`) so rustup does not install that file's cross-target list; the action installs the toolchain with `--profile minimal` plus the components the job names (`clippy`, `miri rust-src`, none).
- `lolhtml` exists because the vendored lol-html is a fork (oven-sh/lol-html, `bun` branch) whose own test suite is the only thing guarding the fork's invariants. It used to trigger only on `scripts/build/deps/lolhtml.ts`; it now shares the workflow's wider path filter.
- `mordant` runs the [mordant](https://github.com/scarletindustries/mordant) lint pack as an advisory (`continue-on-error`) job. Mordant ships its own runner, the way clippy does. `cargo mordant` is `cargo check` with `mordant-driver` (rustc with the lints linked in) as `RUSTC_WORKSPACE_WRAPPER`, and it builds into `target/mordant/check`. The shared action installs mordant's nightly (`MORDANT_TOOLCHAIN`) with `rustc-dev` and `llvm-tools-preview`, and every cargo call in the job names it (`cargo +"$MORDANT_TOOLCHAIN" …`): `cargo install --locked --git … --rev "$MORDANT_REV"` builds the two binaries with it, and `scripts/rust-mordant.ts` runs `cargo mordant` under it. It is not spelled `RUSTUP_TOOLCHAIN` because `test/internal/source-lints/ci-image-pins.test.ts` holds every `RUSTUP_TOOLCHAIN: nightly-…` in a workflow to the channel in `rust-toolchain.toml`, and this one moves with mordant instead. One cache covers them: `~/.cargo/bin/{cargo-mordant,mordant-driver}`, keyed on the nightly and the rev. The job restores it with `actions/cache/restore` and saves it with `actions/cache/save` right after the build, because the post step of `actions/cache` does not run in a job that failed, and a pull request with a finding over the baseline would then build mordant again on every push. Because that nightly is older than ours, the script passes `-A unknown_lints` through `MORDANT_RUSTFLAGS`. It is skipped on `merge_group`.
Expand All @@ -136,7 +137,7 @@ Four independent jobs over the Rust workspace. They share `.github/actions/rust-
- The pin is two values in the `mordant` job's `env:`: `MORDANT_REV` (a mordant commit) and `MORDANT_TOOLCHAIN` (the nightly in mordant's `rust-toolchain` file at that commit).
- `mordant.toml` at the workspace root is the configuration. Mordant reads only its `[mordant]` table, which points `baseline` at `mordant-baseline.toml` (per-(lint, file) counts of the findings that predate the job) and lists the lints this repo has switched off under `disabled`, each with its reason.
- The baseline holds a count for each lint and file, not which findings. A file within its count prints nothing. A file that goes over prints every finding of that lint as a warning, followed by one line with the number found and the number the baseline allows: the new finding is among them, and it need not be the last one in the file. When any crate goes over, `cargo mordant` prints one closing `error: mordant: N finding(s) over the baseline in ...` line and exits with status 101, which fails the job, and lists each such crate with its count in `target/mordant/over-baseline.txt` (relative to the workspace root). Fixing baselined findings needs no baseline update.
- `unused_pub` is the one lint that `cargo mordant` decides itself, after cargo is done. Each compilation records the `pub` items it defines and the workspace items it uses under `target/mordant/unused_pub/`, and `cargo mordant` judges the records of the units the run built. Its baseline entries sit in the section of the crate that defines the item. A use counts only from a target the run builds, and a member is judged only when the run leaves out no member that depends on it: a run under `-p` says little, and the job and the scripts pass `--workspace`. `scripts/rust-mordant.ts` names three triples (`x86_64-unknown-linux-gnu`, `x86_64-pc-windows-msvc`, `aarch64-apple-darwin`), so a use under `cfg(windows)` or `cfg(target_os = "macos")` counts; the host must be named too, since any `--target` drops it. The job and both package.json scripts go through that file, so the list is in one place. The job does not pass `--all-targets`, so an item that only tests use is reported. Passing it needs every test target in the workspace to compile on mordant's nightly, which no other CI job checks.
- `unused_pub` is the one lint that `cargo mordant` decides itself, after cargo is done. Each compilation records the `pub` items it defines and the workspace items it uses under `target/mordant/unused_pub/`, and `cargo mordant` judges the records of the units the run built. Its baseline entries sit in the section of the crate that defines the item. A use counts only from a target the run builds, and a member is judged only when the run leaves out no member that depends on it: a run under `-p` says little, and the job and the scripts pass `--workspace`. `scripts/rust-mordant.ts` runs over the same three triples as clippy (`rustLintTargets`), so a use under `cfg(windows)` or `cfg(target_os = "macos")` counts; the host must be named too, since any `--target` drops it. The job does not pass `--all-targets`, so an item that only tests use is reported. Passing it needs every test target in the workspace to compile on mordant's nightly, which no other CI job checks.
- The baseline file and `MORDANT_BASELINE_WRITE` are inputs of every member's compilation: mordant's driver names them in the dep-info. So a baseline write, or a change to `mordant-baseline.toml`, re-lints every member on the next run, and a warm `target/mordant/check` is safe to keep. On a warm run where nothing changed, cargo replays a crate's warnings and does not run the driver, but each compilation saved its count under `target/mordant/over_baseline_counts/`, so `cargo mordant` still judges every crate, rewrites `over-baseline.txt` and exits 101 as on a cold run (`unused_pub` is judged again on every run). A `target/mordant` left by a mordant build older than the pin has no saved counts, and the run then stops with an error that says to remove that directory.
- Every other lint is counted per rustc process, so a file compiled under three triples is weighed against its recorded count three times, not summed. A baseline write is different: each process rewrites its crate's whole section, so over several `--target`s the last target to finish a crate wins and an entry only another target sees can be dropped. So `bun run rust:mordant:baseline` does not write in one run: the script writes one baseline per target, keeps the largest count for each entry, and takes the `unused_pub` entries from a fourth run over all three targets, the only kind that sees every use. Four runs, about four minutes on 16 cores.
- Locally, `bun run rust:mordant` is the same invocation and `bun run rust:mordant:baseline` regenerates the baseline. Both need mordant installed once, with the two values from the job's `env:`: `rustup toolchain install <MORDANT_TOOLCHAIN> --profile minimal --component rustc-dev --component llvm-tools-preview`, then `cargo +<MORDANT_TOOLCHAIN> install --locked --git https://github.com/scarletindustries/mordant --rev <MORDANT_REV>`. `cargo mordant --version` prints the commit of the installed build. The script adds the three targets' std to that toolchain itself (`rustup target add`). Both also expect `build/debug/codegen`, `vendor/lolhtml` and `vendor/rust-argon2` to exist, which any normal `bun bd` leaves behind.
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/rust-lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- "src/codegen/**"
- "scripts/build/**"
- "scripts/build.ts"
- "scripts/rust-clippy.ts"
- "scripts/rust-miri.ts"
- "scripts/rust-mordant.ts"
- "package.json"
Expand All @@ -36,8 +37,8 @@ env:
BUN_VERSION: "1.4.4"
LLVM_VERSION_MAJOR: "23"
# Pin the toolchain explicitly so rustup ignores rust-toolchain.toml's
# `targets` list (11 cross triples ≈ 450 MB of prebuilt std we don't need
# to lint the host). Keep in sync with `channel` in rust-toolchain.toml.
# `targets` list (11 cross triples ≈ 450 MB of prebuilt std); each job adds
# the few it lints. Keep in sync with `channel` in rust-toolchain.toml.
RUSTUP_TOOLCHAIN: nightly-2026-09-15

jobs:
Expand All @@ -60,18 +61,21 @@ jobs:
ninja-targets: codegen clone-lolhtml clone-rust-argon2

- name: cargo clippy
# scripts/rust-clippy.ts names the targets (Linux, Windows and macOS in
# one run) and installs their std.
env:
BUN_CODEGEN_DIR: ${{ github.workspace }}/build/debug/codegen
run: bun run rust:clippy

- name: cargo check --all-targets
# Clippy above covers the default targets only (lib and bin). This
# Clippy above covers the default cargo targets only (lib and bin). This
# type-checks what it skips (`#[cfg(test)]` code, `tests/`, `benches/`)
# so that code keeps compiling: the miri job builds a few crates'
# tests, nothing builds the rest.
# tests, nothing builds the rest. `--target` shares clippy's build of
# the third-party crates.
env:
BUN_CODEGEN_DIR: ${{ github.workspace }}/build/debug/codegen
run: cargo check --workspace --all-targets --keep-going
run: cargo check --workspace --all-targets --keep-going --target x86_64-unknown-linux-gnu

miri:
name: cargo miri test
Expand Down
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Several situational sections live in `.claude/docs/landing-prs.md` — read the
6. **Use absolute paths** - Always use absolute paths in file operations
7. **Avoid shell commands** - Don't use `find` or `grep` in tests; use Bun's Glob and built-in tools
8. **Memory management** - Prefer RAII (`Drop`) over manual cleanup. Arena edge case: values allocated in an arena (`Arena<T>`/`bumpalo`) do **not** run `Drop` on arena reset — types owning a heap allocation or refcount must be freed/deref'd explicitly first, mirroring the original Zig `deinit()` order.
9. **Cross-platform** - Run `bun run rust:check-all` to compile across all targets (linux/macos/windows × x64/aarch64) when making platform-specific changes. `#[cfg(...)]`-gated code is not type-checked unless the matching target is built.
9. **Cross-platform** - Run `bun run rust:check-all` to compile across all targets (linux/macos/windows × x64/aarch64) when making platform-specific changes. `#[cfg(...)]`-gated code is not type-checked unless the matching target is built. `bun run rust:clippy` lints Linux, Windows and macOS from any host, as CI does.
10. **Debug builds** - Use `BUN_DEBUG_QUIET_LOGS=1` to disable debug logging, or `BUN_DEBUG_<SCOPE>=1` to enable a specific `bun_core::output` scoped logger
11. **Be humble & honest** - NEVER overstate what you got done or what actually works in commits, PRs or in messages to the user.
12. **Branch names must start with `claude/`** - This is a requirement for the CI to work.
Expand Down
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.

2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ disallowed-methods = [
{ path = "std::fs::read_dir", reason = "use bun_sys::dir" },
{ path = "std::fs::read_link", reason = "use bun_sys::file" },
{ path = "std::fs::symlink_metadata", reason = "use bun_sys::file" },
{ path = "std::os::unix::fs::symlink", reason = "use bun_sys::file" },
{ path = "std::os::unix::fs::symlink", reason = "use bun_sys::file", allow-invalid = true },
{ path = "std::env::var", reason = "use bun_core::env_var" },
{ path = "std::env::var_os", reason = "use bun_core::env_var" },
{ path = "std::thread::spawn", reason = "use std::thread::Builder with a stack size, and name the thread (Output::Source::configure_named_thread), or use bun_threading::ThreadPool" },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"test:release": "node scripts/runner.node.ts --exec-path ./build/release/bun",
"rust:check": "cargo check --workspace --keep-going",
"rust:check-all": "bun scripts/rust-check-all.ts",
"rust:clippy": "cargo clippy --workspace --no-deps --keep-going",
"rust:clippy": "bun scripts/rust-clippy.ts",
"rust:mordant": "bun scripts/rust-mordant.ts",
"rust:mordant:baseline": "bun scripts/rust-mordant.ts --baseline",
"rust:miri": "bun scripts/rust-miri.ts",
Expand Down
9 changes: 9 additions & 0 deletions scripts/build/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ export const allRustTargets = [
"aarch64-unknown-freebsd",
] as const;

/**
* What `rust:clippy` and `rust:mordant` lint. Once any `--target` is given,
* cargo checks only the targets listed, so the Linux one is named too. One
* target per OS: a second Windows or macOS target would lint the same
* `cfg(windows)` / `cfg(target_os = "macos")` code again for the few dozen
* arch gates.
*/
export const rustLintTargets = ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "aarch64-apple-darwin"] as const;

/**
* Tier 3 targets — rustup ships no prebuilt `rust-std` for these, so
* `rustup target add` would fail and cargo needs `-Zbuild-std` (which in turn
Expand Down
69 changes: 69 additions & 0 deletions scripts/rust-clippy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bun
/**
* `cargo clippy` over the workspace for every target in `rustLintTargets`: what
* the `cargo clippy` job runs. Code under `cfg(windows)` or
* `cfg(target_os = "macos")` is only linted when its target is. Clippy never
* links, so any host can lint every target once its std is installed.
*
* Usage:
* bun run rust:clippy # every target
* bun run rust:clippy --target x86_64-pc-windows-msvc # only the ones named
* bun run rust:clippy --message-format=short # other args go to `cargo clippy`
*
* With one target named, cargo's "unused dependency" warnings include crates
* that only another target uses. Trust them from a run over every target,
* which is also the only one that lints the standalone `bun_shim_impl` binary.
*
* Read what `--fix` did before keeping it. Clippy sees the code after `cfg`
* stripping, so a fix for one target can delete what another target needs: an
* arm that is `cfg!(unix)`, a `#[cfg(not(windows))]` block, a clamp that is a
* no-op for this target's integer type.
*/

import { spawnSync } from "node:child_process";
import { resolve } from "node:path";
import { rustLintTargets } from "./build/rust.ts";

const repo = resolve(import.meta.dirname, "..");
const args = process.argv.slice(2);
const targets = args.some(arg => arg === "--target" || arg.startsWith("--target=")) ? [] : rustLintTargets;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

function run(cmd: string, args: string[]) {
console.log(`\x1b[36m[clippy]\x1b[0m ${cmd} ${args.join(" ")}`);
return spawnSync(cmd, args, { stdio: "inherit", cwd: repo });
}

if (targets.length > 0) {
// Idempotent, and a fraction of a second once they are there. No rustup
// (a distro's cargo): the targets' std is the user's to provide.
const added = run("rustup", ["target", "add", ...targets]);
if (added.error === undefined && added.status !== 0) process.exit(added.status ?? 1);
}

const workspace = run("cargo", [
"clippy",
"--workspace",
"--no-deps",
"--keep-going",
...targets.flatMap(target => ["--target", target]),
...args,
]).status;

// `bun_shim_impl.exe` is a `[[bin]]` behind a feature, so `--workspace` skips it
// and only sees that file as a module of `bun_install`.
let shim: number | null = 0;
if (targets.length > 0) {
const windows = targets.filter(target => target.includes("windows")).flatMap(target => ["--target", target]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
shim = run("cargo", [
"clippy",
"-p",
"bun_shim_impl",
"--features",
"shim_standalone",
"--no-deps",
...windows,
...args,
]).status;
}

process.exit(workspace !== 0 ? (workspace ?? 1) : (shim ?? 1));
13 changes: 5 additions & 8 deletions scripts/rust-mordant.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bun
/**
* `cargo mordant` over the workspace for every target the `mordant` job
* checks. This file is the one place that names them: the job, `bun run
* rust:mordant` and `bun run rust:mordant:baseline` all come through here.
* `cargo mordant` over the workspace for every target in `rustLintTargets`.
* The job, `bun run rust:mordant` and `bun run rust:mordant:baseline` all come
* through here.
*
* Several targets in one run, because `unused_pub` counts a use only from a
* unit the run builds: a `pub fn` whose one caller is `#[cfg(windows)]` is
Expand All @@ -19,14 +19,11 @@
import { spawnSync } from "node:child_process";
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { join, resolve } from "node:path";
import { rustLintTargets } from "./build/rust.ts";

const repo = resolve(import.meta.dirname, "..");

// Once any `--target` is given, cargo checks only the targets listed, so the
// Linux one is named too. One target per OS: a second Windows or macOS
// target would lint the same `cfg(windows)` / `cfg(target_os = "macos")` code
// again for the few dozen arch gates.
const TARGETS = ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "aarch64-apple-darwin"];
const TARGETS = [...rustLintTargets];

// Mordant's nightly is older than rust-toolchain.toml's, so `#[allow]`s of
// lints added since then are unknown to it.
Expand Down
12 changes: 8 additions & 4 deletions src/bun_core/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,11 @@ pub fn capture_from_context(pc: usize, fp: usize, out: &mut [usize]) -> usize {
// SAFETY: `control_pc` is a code address from the fault context;
// `image_base` is valid for write; history table may be null.
let rf = unsafe {
ntdll::RtlLookupFunctionEntry(control_pc, &mut image_base, core::ptr::null_mut())
ntdll::RtlLookupFunctionEntry(
control_pc,
&raw mut image_base,
core::ptr::null_mut(),
)
};
if rf.is_null() {
// Leaf function with no `.pdata` entry: manually pop the
Expand Down Expand Up @@ -420,9 +424,9 @@ pub fn capture_from_context(pc: usize, fp: usize, out: &mut [usize]) -> usize {
image_base,
control_pc,
rf,
&mut ctx,
&mut handler_data,
&mut establisher_frame,
&raw mut ctx,
&raw mut handler_data,
&raw mut establisher_frame,
core::ptr::null_mut(),
);
}
Expand Down
Loading
Loading