Skip to content

[CI] Make sccache install script architecture-agnostic - #187826

Closed
luhenry wants to merge 1 commit into
pytorch:mainfrom
riseproject-dev:sccache-multiarch
Closed

luhenry wants to merge 1 commit into
pytorch:mainfrom
riseproject-dev:sccache-multiarch

Conversation

@luhenry

@luhenry luhenry commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

The sccache build patch was hardcoded to aarch64, requiring a manual edit each time a new architecture is added. This change detects the architecture at build time via uname -m and applies the patch generically, so any future arch get the same fix without code duplication.

The sccache-dist binary copy is also made conditional on whether dist-server is included in FEATURES, avoiding a build failure when dist-server support is disabled for a given architecture.

Test Plan:

cd .ci/docker
CI=1 bash -x ./build.sh pytorch-linux-noble-riscv64-py3.12-gcc14-cross-build

The sccache build patch was hardcoded to `aarch64`, requiring a manual
edit each time a new architecture is added. This change detects the
architecture at build time via `uname -m` and applies the patch
generically, so any future arch get the same fix without code duplication.

The `sccache-dist` binary copy is also made conditional on whether
`dist-server` is included in `FEATURES`, avoiding a build failure when
dist-server support is disabled for a given architecture.

Test Plan:
```
cd .ci/docker
CI=1 bash -x ./build.sh pytorch-linux-noble-riscv64-py3.12-gcc14-cross-build
```
@luhenry
luhenry requested a review from a team as a code owner June 22, 2026 09:53
@pytorch-bot

pytorch-bot Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/187826

Note: Links to docs will display an error until the docs builds have been completed.

❌ 13 New Failures, 2 Unclassified Failures

As of commit a196ce5 with merge base 15883c6 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@luhenry

luhenry commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

cc @malfet @atalman @seemethere as you've recently reviewed changes in this file. Thank you! 🙏

@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 23, 2026
@luhenry

luhenry commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@malfet @zxiiro what's the likelihood of this PR getting merged? Anyone else who could be good to review these changes? Thank you

@zxiiro

zxiiro commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Seems reasonable to me. I'll triggered the jobs runs.

@zxiiro

zxiiro commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Failures seem unrelated to this change.

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 26, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: Approvers from one of the following sets are needed:

  • OSS CI (alband, pytorch/pytorch-dev-infra)
  • Metamates (8Keep, aditvenk, AmesingFlank, andrewor14, andyanwang, ...)
  • Core Reviewers (mruberry, lezcano, Skylion007, ngimel, peterbell10, ...)
  • Core Maintainers (soumith, gchanan, ezyang, malfet, albanD, ...)
Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@huydhn

huydhn commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

@claude Review the change in .ci/docker/common/install_cache.sh, do we still need to do that sed hack when building https://github.com/mozilla/sccache from source? Could we just use the official build from https://github.com/mozilla/sccache?

@claude

claude Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

Claude finished @huydhn's task in 4m 7s —— View job


Review: install_cache.sh sccache source build

  • Read the changed file and PR diff
  • Investigate why sccache is built from source (the sed patch reason)
  • Check whether official prebuilt sccache binaries would work
  • Verify the new FEATURES glob condition

@huydhn — answering your question, plus one bug I found in the new code.


What the sed hack actually does

sed -i "/all(target_os = \"linux\", target_arch = \"x86_64\"),/{ p; s/x86_64/${ARCH}/; }" src/bin/sccache-dist/main.rs

It patches sccache-dist/main.rs only — i.e. the distributed-compilation server binary. Upstream gates the real server main() behind #[cfg(all(target_os = "linux", target_arch = "x86_64"))], so on any non-x86_64 host sccache-dist compiles to a stub that errors out. The sed duplicates that cfg line and swaps in the current arch, letting the server compile on aarch64 (and now, generically, any arch).

So the hack is exclusively about sccache-dist (the server). It has nothing to do with the sccache client binary that PyTorch's compiler wrappers actually call.

Do we still need it? → Likely no, and the cleaner fix is to drop dist-server entirely

Grepping the whole .ci/ tree, sccache-dist appears in exactly one place — this script, where it's copied to /opt/cache/bin and then never invoked:

.ci/docker/common/install_cache.sh:21:    cp target/release/sccache-dist /opt/cache/bin

PyTorch CI uses sccache in local/S3 cache mode (the client talks to s3://ossci-compiler-cache...), not in distributed-server mode. If nothing launches sccache-dist, then:

  • the dist-server feature isn't needed in FEATURES,
  • the sed patch isn't needed (it only exists to make dist-server compile off-x86_64),
  • the cp ... sccache-dist isn't needed.

Dropping dist-server from FEATURES would let you delete the sed line, the conditional copy, and sidestep the per-arch build problem this PR is working around — which is strictly simpler than making the patch arch-agnostic. I'd suggest confirming with infra (@malfet / @zxiiro / @seemethere) whether sccache-dist is used by any consumer before this PR doubles down on building it everywhere. If it genuinely is unused, that's the change to make. Drop dist-server →

Could we just use the official prebuilt binary instead of building from source?

For the client, on x86_64/aarch64 — yes in principle: mozilla/sccache ships *-unknown-linux-musl release tarballs for those, and the script already has an unused install_binary() helper (it pulls an old sccache off s3://ossci-linux). But:

  • The whole reason this PR exists is riscv64 (see its test plan, ...-riscv64-...-cross-build). Upstream sccache release tarballs do not publish a riscv64 build, so for that arch you have no choice but to build from source. That's the fundamental driver for the source build.
  • Building from source also pins an exact version (v0.13.0) and feature set across all arches, which the prebuilt route can't guarantee uniformly.

So: the official build can't replace the source build for the new architectures this PR targets. The realistic simplification is the one above (drop dist-server), not switching to prebuilt binaries.


Bug in the new conditional copy (independent of the above)

if [[ "${FEATURES}" =~ *dist-server* ]]; then
  cp target/release/sccache-dist /opt/cache/bin
fi

[[ ... =~ ... ]] treats the right side as an ERE regular expression, not a shell glob. *dist-server* is not the substring test it looks like — the leading * is a quantifier with nothing to quantify (treated as a literal *), so this regex only matches a string that literally contains a * character. Since FEATURES="dist-client dist-server" has no *, the condition is always false and sccache-dist is never copied — even though it was just built. Before this PR the copy was unconditional, so this is a silent behavior change.

Use one of:

if [[ "${FEATURES}" == *dist-server* ]]; then   # glob match with ==
if [[ "${FEATURES}" =~ dist-server ]]; then      # regex substring (no globs)

Fix this →

(If you take the "drop dist-server" route, this branch goes away entirely.)

Minor

  • The FEATURES comment says it "may vary based on the architecture," but the value is hardcoded and never varies. Either wire up the per-arch variation you're anticipating, or drop the comment so it doesn't imply behavior that isn't there.

Summary

  • The sed hack only enables the sccache-dist server on non-x86_64; it's unrelated to the client PyTorch actually uses.
  • sccache-dist appears unused across .ci/ — the simplest fix is to drop dist-server from FEATURES, which removes the need for both the sed patch and the conditional copy.
  • Official prebuilt binaries can't replace the source build for riscv64 (no upstream release for that arch), which is this PR's actual target — so the source build stays necessary.
  • The new =~ *dist-server* test is buggy (regex vs glob) and never matches; use == glob or a =~ substring without *.
    (branch: sccache-multiarch)

@luhenry

luhenry commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

@huydhn I would be all for using the official mozilla/sccache (it also has a riscv64 build contrary to what Claude is saying 1), it doesn't have the dist-client and dist-server features enabled though. Like claude mentions, if we don't make use of sccache-dist anywhere, then we can drop it, download the release from mozilla/sccache and be done with it.

@luhenry

luhenry commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

superseded by #188924. I'll open a PR to download the artifacts from a mozilla/sccache release so that it doesn't even have to be built locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/docker ciflow/trunk Trigger trunk jobs on your pull request open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants