Skip to main content

build_obj_plan

Function build_obj_plan 

Source
pub fn build_obj_plan(
    captured: &CapturedRustcInvocation,
    output_dir: &Path,
) -> ObjBuildPlan
Expand description

Edit a captured rustc invocation so that running it produces an object file containing every pub fn’s mangled symbol — the input to the linker step in [build_link_plan].

Three changes only:

  • --crate-type is forced to rlib. Object files emitted for an rlib crate-type retain mangled pub fn symbols (cdylib’s symbol-visibility filter wouldn’t have run yet, because we stop before linking). lib would also work but rlib is what cargo itself uses for normal dependency compilation, so we stay closer to the rustc call shape that gets the most testing.
  • --emit is forced to a single obj=<output_dir>/<crate>.o directive. This skips the link step (no lib<crate>.rlib metadata bundle, no .rmeta, no codegen-units fan-out into deps) and writes one consolidated object file we can hand directly to the linker.
  • --out-dir is redirected so the host’s target/ isn’t touched (it’s still the rustc-default location for any auxiliary file rustc decides to emit).

Everything else is preserved verbatim — same target triple, sysroot, sysroot suffix, -C flags, -L/-l directives, cfg gates. This is the same “minimal edit, verbatim everything else” principle as the captured-args replay does for the linker side in super::link_plan::build_link_plan; the only difference is where we stop in rustc’s pipeline (obj vs link).