Skip to content

Phase 1b-ii: ExternalPreprocessor (subprocess-backed libc probe) #502

Description

@zackees

Part of #493 Phase 1, follow-up to #500 / #501. Lands the concrete ExternalPreprocessor impl backed by std::process::Command that the auto-resolver will use to probe a real cross-compiler at build time.

Scope

  • Add ExternalPreprocessor struct in crates/fbuild-build/src/shrink/probe.rs:
    • pub struct ExternalPreprocessor { compiler: PathBuf, extra_args: Vec<String> }
    • Constructor new(impl Into<PathBuf>) + builder with_args(impl IntoIterator<Item=impl Into<String>>).
  • Implement Preprocessor for ExternalPreprocessor:
    • Invokes <compiler> <extra_args> -E -x c - with the probe source on stdin.
    • Discards stdout (Stdio::null), captures stderr.
    • Returns PreprocessResult { exit_code, stderr }.
    • Maps subprocess spawn / stdin write / wait_with_output failures to io::Error (the trait's fail-closed contract).

Out of scope

  • Caching per-toolchain probe results — separate sub-issue once the auto-resolver lands.
  • Auto-discovering the cross-compiler path from a Toolchain struct — that's part of Phase 1c (wiring probe_libc into the orchestrator).
  • Anything else.

Pass

  • cargo build --workspace --all-targets clean.
  • cargo clippy --workspace --all-targets -- -D warnings exits 0.
  • Tests:
    • Constructor + builder shape (no subprocess).
    • Missing-compiler path → probe_libc returns Libc::Unknown (fail-closed verification end-to-end).
    • Host-cc smoke test (cc / gcc / clang if available) — verifies the subprocess wiring completes without an I/O error and returns a real exit code; does not constrain the libc kind (host could be glibc, musl, newlib-on-cygwin, etc.). Skipped with a clear message if no host C compiler is found.

Notes

  • #[cfg(unix)] / #[cfg(windows)] should not be needed — Command handles platform differences and we use Stdio::null / Stdio::piped portably.
  • The host-cc test is best-effort: GitHub Actions runners (ubuntu-latest, macos-latest, windows-latest with MSYS2/MinGW) all ship cc / gcc, so it will exercise the path in CI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions