Skip to content

Add worker-managed pipelined compilation and incremental build support#9

Draft
walter-zeromatter wants to merge 23 commits intohermeticbuild:mainfrom
walter-zeromatter:pr/worker-pipelining
Draft

Add worker-managed pipelined compilation and incremental build support#9
walter-zeromatter wants to merge 23 commits intohermeticbuild:mainfrom
walter-zeromatter:pr/worker-pipelining

Conversation

@walter-zeromatter
Copy link
Copy Markdown

@walter-zeromatter walter-zeromatter commented Mar 20, 2026

Summary

Implements a multiplex persistent worker for rustc that enables true Cargo-style pipelined compilation:

  • Multiplex worker (worker.rs, worker_protocol.rs): JSON persistent worker protocol with singleplex and multiplex support, cancel handling, signal handling
  • Pipeline state sharing (worker_pipeline.rs): metadata action starts rustc, returns .rmeta early; full action retrieves running process and copies .rlib
  • Multiplex sandboxing (worker_sandbox.rs): sandbox-aware output materialization, writable output preparation
  • Incremental compilation (incremental.bzl): -Cincremental with separate cache dirs for metadata/full actions, skips exec-platform and proc-macro targets
  • PathMapper compatibility in rustc.bzl: File objects for --out-dir, --sysroot, -L via map_each
  • New settings: experimental_worker_pipelining, experimental_incremental

Benefits over hollow-rlib pipelining

  • Eliminates SVH mismatch with non-deterministic proc macros (single rustc invocation)
  • No -Zno-codegen / RUSTC_BOOTSTRAP=1 required
  • ~50% fewer rustc invocations for pipelined crates
  • ~25% shorter critical path

Bug fixes applied during review

  • Fixed redundant assertion in test/chained_direct_deps/mod1.rs
  • Collapsed duplicate _is_incremental_enabled/is_incremental_enabled in incremental.bzl
  • Unified prepare_outputs/prepare_outputs_sandboxed into shared prepare_outputs_impl
  • Added fast-path string equality check in materialize_output_file before canonicalize syscalls
  • Gated lifecycle logging behind RULES_RUST_WORKER_DEBUG env var
  • Trimmed experimental_worker_pipelining docstring from 65 lines to 25

Test plan

  • 10 pipelined_compilation tests pass
  • 4 incremental compilation tests pass
  • Test on Windows

dzbarsky and others added 22 commits March 13, 2026 12:43
Replace the --rustc-quit-on-rmeta / .rmeta approach with Buck2-style
hollow rlibs: the RustcMetadata action runs rustc to completion with
-Zno-codegen, emitting a .rlib archive (named -hollow.rlib) that
contains only metadata and optimized MIR.

Key fixes:
- Main Rustc action uses full rlib --extern deps so the SVH embedded
  in the full rlib matches what downstream binaries expect (avoiding
  E0460 with non-deterministic proc macros).
- RUSTC_BOOTSTRAP=1 is set on both actions: it changes the crate hash,
  so inconsistent use would cause SVH mismatch even for deterministic
  crates.
- -Ldependency= points to the _hollow/ subdirectory so the full rlib
  and hollow rlib never appear in the same search path (avoids E0463).
- transitive_metadata_outputs are always included in the sandbox so
  rustc can resolve transitive -Ldependency= references.

Adds an SVH mismatch test that demonstrates the problem with
non-deterministic proc macros (uses a HashMap-based derive macro whose
output varies by OS-seeded random seed).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dzbarsky dzbarsky force-pushed the main branch 2 times, most recently from d97ab75 to e1ed0e4 Compare April 1, 2026 19:48
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.

4 participants