feat: support for ctx.actions.copy aliasing content - #30386
Open
thesayyn wants to merge 2 commits into
Open
Conversation
thesayyn
force-pushed
the
copy-support
branch
4 times, most recently
from
July 21, 2026 05:40
d32dfa2 to
4c41310
Compare
Adds ctx.actions.copy(output, target_file): makes target_file's content available at output (a second exec path), sharing its digest, with no byte copy and no spawn. Unlike ctx.actions.symlink, which plants a followable symbolic link that resolves back to the target's location, ctx.actions.copy only declares the relationship and defers materialization to sandbox/spawn creation -- the execution strategy places the target's content at the output's own path (hard link, copy, or the shared digest on remote execution), so its realpath stays inside the consuming tree (which tools such as Node.js require). Strategies that cannot materialize content (a purely symlinking sandbox or non-sandboxed local execution) fall back to a symlink. The original is never a declared input of the consumer -- it sees only the copy. Reuses the existing resolved-path metadata rather than adding new machinery: FileArtifactValue.isContentCopy() marks the value (ordinary symlinks are unchanged), a declaration-only CopyAction injects it, and the remote prefetcher and the local sandbox stage the content from the recorded source. Design: bazelbuild/proposals#419
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
ctx.actions.copy(output, target_file): a Starlark action that makestarget_file's content available atoutput(a second exec path), sharing itsdigest, with no byte copy and no spawn. Unlike
ctx.actions.symlink(which isalways a followable symlink), a copy requests content materialization: strategies
that can honor it — the hardlinking/copying sandbox, or remote execution via the
shared digest — place a real file at the output's path, so its
realpathisstable within the consuming tree (which tools such as Node.js require). Whether
and how that happens is up to the execution strategy; a purely symlinking sandbox
or non-sandboxed local execution does not provide it. The original is never a
declared input of the consumer — it sees only the copy.
Motivation
Rulesets that must present inputs at a canonical layout — most visibly rules_js
copying every source into
bazel-bin(copy_to_bin), and similarly rules_pythonand rules_oci — do so today with a byte copy per file. The dominant cost is the
per-action work (spawns, uploads), not the bytes.
ctx.actions.copygives thesame observable result (a content-identical file at a new path) while avoiding the
duplication wherever the execution strategy can.
Design: bazelbuild/proposals#419
Build API Changes
Yes — adds the
ctx.actions.copyStarlark method.(ordinary
symlinkand copy actions are untouched).Checklist
Release Notes
RELNOTES[NEW]: ctx.actions.copy(output, target_file) makes a file's content
available at a second path without duplicating bytes (realized as a hard
link/copy, or via the shared digest on remote execution) — an alternative to
copying for tools that require real files rather than symlinks.