Skip to content

#2016: the four targets the build store could not serve are worktree-independent - #2048

Merged
ehartford merged 2 commits into
mainfrom
fix-2016
Oct 3, 2026
Merged

ehartford merged 2 commits into
mainfrom
fix-2016

Conversation

@ehartford

@ehartford ehartford commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2016. A second fresh worktree's :dev now re-runs none of the targets the issue lists: all of them come from the build store.

Root causes and fixes

  • with-sha256. The driver compiles Executable/Library/Object/Archive targets in-process (src/main.w, the kind 0/1/3/4 branches). Before this change it ignored the target's declared environment there, because Target.with_env only reached actions. As a result the D50 prefix map never applied, and the binary's debug map (N_SO/N_OSO) named the worktree.
    • The driver now sets a target's declared env around an in-process compile and puts back what was there before (build_graph_apply_target_env / build_graph_restore_target_env).
    • The env is now part of the target's key (build_cache_signature_parts).
    • build.w declares WITH_FILE_PREFIX_MAP for with-sha256. The value comes from the one owner of that mapping, compiler_file_prefix_map in build/compiler.w.
    • A second cause showed up once the root was gone. link_stage_make_archive (src/compiler/Link.w) named each runtime archive <obj>.<pid>.<nanos>.a, and N_OSO records that name. So two links of the same program differed. The archive is now named by content (<obj>.ar-<sha16>.a), renamed into place, and kept.
  • bootstrap-/stage1-llvm-link-metadata. run_generate_llvm_link_metadata_action wrote absolute paths to the SDK archives, the darwin -syslibroot/-isysroot, llvm_cc and llvm_ld.
    • Paths under the root are now written relative to it (comp_root_relative_text).
    • Every process that reads these files runs in the root: comp_run_compiler_capture and emit-c's emitc_run_capture_env now use run_capture_cwd_with_env(root).
  • sdk-clang-main. It declared write_scope(".deps") and wrote libclangMain.a into the SDK.
    • The SDK is now read only.
    • For an SDK without the archive, the action builds it as its declared output at out/gen/sdk-clang-main/libclangMain.a, keyed on sdk.lock and compiled with -ffile-prefix-map.
    • The link metadata and the clang-resource fact both read it through comp_host_has_clang_main.
  • sysroot-zig-source (Linux). It extracted into .deps/src. The target is removed.
    • Each linux sysroot target now fetches the pinned source into its own scratch (sdk_materialize_zig_source), the same way darwin-sysroot does.
    • Each one declares its tree as an output and maps the root out of the glibc objects.
  • The store's own check (found while measuring).
    • build_cache_store_names_root used contains(root). It refused stage1 because seed-input.json recorded a driver at <root>-drivers/with. It now matches the root only as a whole path.
    • build_cache_store_portable now writes <root> wherever the root is a whole path, including <root>=/with-src. Before, an env value naming the root made a different key in every worktree.

Evidence

  • Second fresh worktree :dev, darwin, one store, with a driver built from the tree on each side:
    • Before (main 74e3001): 5 targets ran (sdk-clang-main, both link-metadata targets, with-sha256, stage1), wall 65.1 s.
    • After: 0 ran, 62 restored, wall 31.4 s (24.6 s on an earlier run).
  • Second fresh worktree :dev, linux-x86_64 (eric-5090): 0 ran, 63 restored (linux-sysroot included), wall 11.0 s. Nothing was written under .deps/src.
  • Byte identity across two independently built darwin worktrees (store disabled in one): with-sha256, both sets of link records, sdk-clang-main's marker and stage1 are all identical. On linux the sysroot pack and tree are identical across two worktrees.
  • New tests:
    • test/behavior/behav_2016_build_store_env_key_and_root_boundary.w
    • test/behavior/behav_2016_build_store_in_process_env.w
    • Each assertion was shown failing on main or before its fix: env not in the key, sibling-prefix refusal, the tool naming its case directory, and the temporary archive name.
  • src/main build :gate: green (1143.7 s).
  • out/release/bin/with check build.w and check lib/std/build.w: ok.
  • src/main build :fixpoint: stage2 == stage3 over all 16 units.

Not covered

  • The pinned seed has no build store and drops the env for in-process compiles. Seed-driven builds see this change after the next seed.
  • The legacy :install group copies the link records to $INSTALL_LIBDIR. They are now root-relative. They used to point into the worktree that built them.

Eric Hartford added 2 commits October 3, 2026 09:46
…independent

- with-sha256: the driver compiled it in-process and dropped the target's
  declared environment (Target.with_env reached only actions), so the
  D50 prefix map never applied and its debug map (N_SO/N_OSO) named the
  worktree. The driver now sets a target's declared env around an
  in-process compile (src/main.w build_graph_apply_target_env), the env
  keys the target (BuildGraphCache signature), and build.w declares
  WITH_FILE_PREFIX_MAP for with-sha256 from the one owner of the mapping
  (build/compiler.w compiler_file_prefix_map).
- bootstrap-/stage1-llvm-link-metadata: the rsp, llvm_cc and llvm_ld
  named the SDK and darwin sysroot by absolute path. They are written
  relative to the root, and every process that reads them (stage
  compiles, emit-c's C driver) runs in the root.
- sdk-clang-main: wrote libclangMain.a into the SDK under .deps. The SDK
  is read only; a built archive is its declared output under
  out/gen/sdk-clang-main, keyed on sdk.lock, compiled with
  -ffile-prefix-map.
- sysroot-zig-source (Linux): extracted into .deps/src. Removed; each
  linux sysroot target fetches the pinned source into its own scratch as
  darwin-sysroot does, declares its tree, and maps the root out of the
  glibc objects.
- The store's root check and its <root> spelling treat the root as a
  whole path: a sibling sharing its prefix is not the root (stage1's
  seed-input.json naming <root>-drivers/with was refused), and
  <root>=/with-src is spelled portably.
…inks to the same bytes every time

link_stage_make_archive (src/compiler/Link.w) wrapped each runtime object
in <obj>.<pid>.<nanos>.a for the link and deleted it after; the debug map
(N_OSO) records the archive's path, so two links of with-sha256 from one
tree differed in that name, LC_UUID and the signature. The archive is now
<obj>.ar-<sha256/16>.a, made under a per-link name and renamed into
place, and kept. The process-wide registry of temporaries it fed is gone;
the sweep of a process's own leftovers stays. The in-process env test
also builds the tool a third time with no store and compares bytes.
@ehartford
ehartford marked this pull request as ready for review October 3, 2026 17:22
@ehartford
ehartford merged commit 01ec974 into main Oct 3, 2026
@ehartford
ehartford deleted the fix-2016 branch October 3, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant