Skip to content

feat(2.0): rust2 wave1 pilot — library-form commands + differential gate (#1488) - #1548

Merged
caomengxuan666 merged 2 commits into
mainfrom
rust2/pilot-wave1
Nov 9, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
rust2/pilot-wave1

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

What

First pilot batch of #1488 (命令库化): the 15 wave-1 commands implemented as library-form functions in Rust — explicit injected IO, explicit env/cwd, no process-global state, status code returned instead of exit().

true false test [ basename dirname printenv pwd
mkdir rmdir readlink realpath chmod chown df

Shape (the point of the pilot)

pub fn run(args: &[OsString], io: &mut Io, ctx: &Ctx) -> CmdResult  // Result<u32>
  • Io { stdin: &mut dyn Read, stdout/stderr: &mut dyn Write } — injected; commands never touch process stdio. Verbose output (mkdir -v, rmdir -v) goes to stdout with straight quotes and is byte-gated, exactly like GNU.
  • Ctx { cwd, env: &dyn EnvSource } — explicit; the driver's ProcessEnv does exact-name lookup (Windows env is case-insensitive; GNU printenv gfoo must not find GFoo).
  • winuxcmd-ffi (cdylib): winuxcmd_run passes argv/envp/cwd as C strings and stdio as explicit byte buffers; catch_unwind at the boundary maps panics to status 125. No CRT fd binding crosses the ABI.

Workspace rust2/ (std-only, zero crates): winux-core (contract) → winux-cmds (15 commands) → winuxcmd-ffi (ABI) → winuxcmd-driver (gate adapter). Location rationale in rust2/README.md (keeps Rust out of the CMake glob; mirrors the branch name).

Differential gate (three-way)

bash gate/run-gate.sh — Rust driver vs GNU coreutils 9.4 (WSL, native ext4 scratch, env <name> so argv[0] prefixes match) vs C++ Debug dispatcher (build-vs/usr/bin/winuxcmd.exe).

  • 338 generated cases (gate/gen-cases.py; ≥16 per command, 45 for test), modes strict / exit / win / note — rules in GATE-REPORT.md.
  • Result: 307 GNU-gated + 31 win-only + 3 notes, all GREEN, stable across consecutive runs. stderr wording recorded, never gated.
  • Findings already folded back into the implementation: GNU -a-tighter-than--o precedence, 2/3-arg test error wording, readlink -f -e last-wins, chmod --reference has no MODE operand, chown 0: is invalid spec, mkdir -v/rmdir -v verbose goes to stdout, basename ab ab keeps ab.

Completion of the 15

  • Full GNU-aligned semantics (real implementations): true, false, test, [, basename, dirname, printenv, pwd, mkdir, rmdir, readlink, realpath.
  • Subset + documented deviation (Windows platform limits, module-doc'd, gate-classified): chmod (parse GNU-exact; owner-write → readonly attr), chown (validated no-op; LookupAccountNameW resolution → invalid user/invalid group/invalid spec), df (local volumes via raw kernel32 FFI; --output not implemented → note).

Scope guards

No C++ changes; no dispatcher/package wiring (belongs to the replacement wave itself); unit tests 53/53 green (cargo t, threads pinned at 4 — libtest capture deadlock at 32 logical CPUs); cargo fmt --check clean.

Refs #1488

…ate (#1488)

First pilot batch of the 2.0 library-form track: 15 wave-1 commands
(true false test [ basename dirname printenv pwd mkdir rmdir readlink
realpath chmod chown df) implemented as library functions with injected
IO, explicit env/cwd, no process globals, status code returned instead
of exit().

Workspace (rust2/, std-only, MSVC target):
- winux-core: shape contract (Io / EnvSource / Ctx / CmdResult), ABI
  failure status 125, in-memory test support.
- winux-cmds: command modules aligned to GNU coreutils 9.4 (probed on
  WSL), Windows-permission subsets documented in module docs
  (chmod owner-write -> readonly attr; chown validated no-op with
  LookupAccountNameW; df local volumes via raw kernel32 FFI).
- winuxcmd-ffi: cdylib C ABI (winuxcmd_run/free_buf/has_command) with
  catch_unwind at the boundary; explicit argv/envp/cwd strings and
  byte buffers only — no environment stdio crosses the ABI.
- winuxcmd-driver: thin CLI adapter (the only process-state reader),
  used by the differential gate.

Differential gate (gate/): three-way Rust vs GNU (WSL coreutils 9.4,
`env <name>` so argv[0] prefixes match) vs C++ Debug dispatcher
(build-vs/usr/bin/winuxcmd.exe). 338 generated cases (gen-cases.py —
hand-edited tab columns had mis-aligned; generator is the fix), modes
strict/exit/win/note: stdout bytes + exit status byte-equal to GNU on
every strict case. Result: 307 GNU-gated + 31 win-only + 3 notes, all
GREEN, stable across consecutive runs (GATE-REPORT.md, regenerate with
gate/make-report.sh).

Unit tests: 53, all green (in-memory IO + scratch dirs); test threads
pinned at 4 in .cargo/config.toml (libtest capture deadlock at 32
logical CPUs on this host).

Scope guards: no C++ changes, no dispatcher/package wiring (belongs to
the replacement wave), chmod/chown/df implemented to the documented
platform subset only.

Refs #1488
@caomengxuan666
caomengxuan666 merged commit 3a96144 into main Nov 9, 2026
12 of 14 checks passed
@caomengxuan666
caomengxuan666 deleted the rust2/pilot-wave1 branch November 18, 2026 05:50
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.

1 participant