mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.85k stars 552 forks source link

Error when trying to use sccache: `error: unrecognized subcommand` #2170

Closed gdubicki closed 6 months ago

gdubicki commented 6 months ago

Hi,

I am trying to use sccache v0.8.0 to cache Rust compilation for Rust v1.78.0.

I am running my code in a Docker image rust:1.78.0-bullseye.

I start my container like this:

docker run -it --platform linux/amd64 -v $(pwd):/app rust:1.78.0-bullseye /bin/bash

And then download and configure sccache like this:

# Get binary because compiling it would be slooooow, of course...
wget https://github.com/mozilla/sccache/releases/download/v0.8.0/sccache-dist-v0.8.0-x86_64-unknown-linux-musl.tar.gz
tar xfvz sccache-dist-v0.8.0-x86_64-unknown-linux-musl.tar.gz
mv sccache-dist-v0.8.0-x86_64-unknown-linux-musl/sccache-dist /usr/local/bin/sccache
rm -rf sccache-dist-v0.8.0-x86_64-unknown-linux-musl
# This configures Rust to use sccache.
export RUSTC_WRAPPER="/usr/local/bin/sccache"
# You should disable incremental compilation when using sccache
export CARGO_INCREMENTAL="0"
# This is the maximum space sccache cache will use on disk.
export SCCACHE_CACHE_SIZE="1G"

...and then when I run cargo test I get:

root@610a4a3cf828:/app# cargo test
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `/usr/local/bin/sccache /usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 2)
  --- stderr
  error: unrecognized subcommand '/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/bin/rustc'

  Usage: sccache <COMMAND>

  For more information, try '--help'.

Of course under that long path there is really rustc:

/usr/local/rustup/toolchains/1.78.0-x86_64-unknown-linux-gnu/bin/rustc --version
rustc 1.78.0 (9b00956e5 2024-04-29)

...and under /usr/local/bin/scache is sccache:

root@610a4a3cf828:/app# /usr/local/bin/sccache  --version
sccache 0.8.0

I feel that I am stuck. I would appreciate any pointers about how I can move forward from here!

AJIOB commented 6 months ago

Hi @gdubicki,

As I can see, you try to use the sscache-dist instead of sccache when downloading.

The dist binary is used only for the distributed compiling (on the few PCs, servers, etc.). Please, configure the local caching at first.

gdubicki commented 6 months ago

Omg, thanks @AJIOB!

I assumed that "dist" here means something like "distribution version" aka "release version".

I was also looking for the x86_64 architecture in the release assets list and the first 20 assets that are shown only include it for the dist package:

Screenshot 2024-05-13 at 14 20 51

It is just slightly misleading...

But, anyway, my problem is solved!