Skip to content

feat(printf): vendor uucore format#1608

Merged
chaliy merged 6 commits intomainfrom
claude/keen-ride-oUHMz
May 8, 2026
Merged

feat(printf): vendor uucore format#1608
chaliy merged 6 commits intomainfrom
claude/keen-ride-oUHMz

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented May 8, 2026

What

Vendors uucore::format into bashkit and migrates the printf builtin to use the generated parser/formatter. Closes #1534.

Why

The handwritten printf parser duplicated uutils logic and made format parity harder to maintain. Vendoring the small format/ runtime keeps wasm builds working while avoiding the large uucore runtime dependency.

How

  • Extended bashkit-coreutils-port port-module with replace_with/inline support, generated-doc/test stripping, relative self use normalization, and absolute generated-module paths for inlined files.
  • Added the format manifest entry plus generated format/, extendedbigdecimal, num_parser, and bashkit-local format_support shims.
  • Reworked printf.rs around generated formatting while preserving bashkit shell integration, printf -v internal-variable protection, %q, repeated-format behavior, zero-hex escape handling, and width/precision DoS caps outside generated code.
  • Updated the coreutils port spec and fixed CLI realfs mount tests to allow explicit CLI mount paths after macOS /private canonicalization.
  • Enabled getrandom's wasm_js feature so the wasm public build gate stays green.

Risk

  • Medium
  • printf formatting behavior changes from bashkit's handwritten implementation to uutils behavior. Existing spec tests, focused unit tests, no-leak checks, no-default/release/wasm builds, all-features clippy/test, and just pre-pr passed locally.

Checklist

  • Tests added or updated
  • Backward compatibility considered
  • cargo test -p bashkit-coreutils-port
  • cargo test -p bashkit --lib printf
  • cargo test -p bashkit --test spec_tests bash_spec_tests
  • cargo build -p bashkit --no-default-features
  • cargo build -p bashkit --target wasm32-unknown-unknown
  • cargo build -p bashkit --release
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --all-features
  • just pre-pr

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 8, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 019816e Commit Preview URL

Branch Preview URL
May 08 2026, 10:21 PM

@chaliy chaliy changed the title feat(coreutils-port): implement replace_with rewriter (towards #1534) feat(coreutils-port): implement replace_with and inline rewriters (towards #1534) May 8, 2026
@chaliy chaliy changed the title feat(coreutils-port): implement replace_with and inline rewriters (towards #1534) feat(coreutils-port): rewriter foundation for #1534 (replace_with + inline + format deps) May 8, 2026
chaliy and others added 6 commits May 8, 2026 16:19
Add the syn-based import rewriter for the manifest's `replace_with`
action so modules referencing uucore-internal types can be vendored
with substitutions, unblocking #1534's printf migration.

Behaviour:
- For each top-level `use` item, flatten the tree into leaf paths
  (preserving glob/rename semantics).
- For each leaf, look up a `replace_with` substitution whose prefix
  matches; replace the matched prefix segments with `target`.
- When the rewritten path's final segment differs from the original
  imported name, an `as <orig>` rename is inserted so call-site
  references still resolve.
- Rebuild use items individually — use groups (`use a::{b, c};`)
  become separate `use` lines (the file is re-pretty-printed via
  `prettyplease::unparse` whenever any `replace_with` is in scope).
- Existing `error` semantics unchanged; `inline` still bails with a
  follow-up message (separate from this change).
- Validation: `replace_with` requires a non-empty `target`.

Tests cover: prefix-match rewrite with rename insertion, no-rename
when leaf matches, use-group flattening, alias preservation, and
missing-target validation. Spec and module-doc updated.

This is a focused incremental step toward #1534; the format/ vendor
+ printf migration land in follow-up PRs.
Extend the rewriter to support `action = "inline"` substitutions.

Behaviour:
- Each `inline` substitution names an `inline_source` file under the
  uutils dir. After porting the primary tree, the tool ports each
  inlined file to `<out_base>/<leaf>.rs` (where `<leaf>` is the
  prefix's final segment).
- The inlined file goes through the same enforce + rewrite pipeline
  so its own transitive uucore references either substitute via
  another manifest stanza or surface explicitly.
- Use-paths matching an `inline` substitution prefix are rewritten
  to `super::<leaf>::…` so the vendored module compiles.
- Validation: `inline` substitutions require a non-empty
  `inline_source` field; missing field is rejected at port time.

Tests cover: inlined file is vendored alongside, primary use-path is
rewritten to `super::<leaf>`, banner is added to the inlined file,
and missing-inline_source validation. Spec and module-doc updated.

With `replace_with` (prior commit) and `inline` both supported, the
rewriter foundation in `bashkit-coreutils-port` is complete; the
remaining pieces of #1534 (vendor uucore::format, migrate printf.rs)
land in follow-up PRs against this primitive.
Pin versions to uutils' workspace defaults. These deps back the
upcoming vendored uucore::format module that #1534 will use for
`printf`. Adding them in a separate commit so the vendor PR keeps
to mechanical codegen output.

Verified:
- `cargo check -p bashkit` (default features): clean.
- `cargo build -p bashkit --no-default-features`: clean.
- `cargo test -p bashkit --lib`: 2230 passed.
- `cargo clippy -p bashkit --all-targets -- -D warnings`: clean.

(`cargo build --target wasm32-unknown-unknown` is broken on bashkit
`main` independently of this change — `getrandom`'s wasm-js
backend isn't enabled — so was not regression-tested here. Re-test
once that pre-existing wasm build is restored.)
cargo-vet flagged the new format-vendor deps as unvetted. Add
exemptions to match the existing entries for bigdecimal /
num-traits in this manifest.
@chaliy chaliy force-pushed the claude/keen-ride-oUHMz branch from 318b007 to 019816e Compare May 8, 2026 22:21
@chaliy chaliy changed the title feat(coreutils-port): rewriter foundation for #1534 (replace_with + inline + format deps) feat(printf): vendor uucore format May 8, 2026
@chaliy chaliy merged commit 4d65b17 into main May 8, 2026
34 checks passed
@chaliy chaliy deleted the claude/keen-ride-oUHMz branch May 8, 2026 22:33
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.

Vendor uucore::format and migrate printf.rs to use it

1 participant