-
Notifications
You must be signed in to change notification settings - Fork 552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sccache seems to have no effect for Rust docker builds #1160
Comments
Hmm, nothing is jumping out at me that might be incorrect. |
I'm curious as to why you want to use sccache when building the docker image. Usually you would want to use sccache when running inside the docker image. Also from what I'm seeing you are first building an empty project generated from |
I want to save all the building information so in CI/CD later, when I change something that is not the code or dependencies - I won't have to build the image over and over again from scratch. In the Dockerfile above I first build only the dependencies and then rest of the project - if the code changes it is a different thing than when dependencies change. |
That is reasonable, but the dependencies are already cached by cargo (i.e. cargo won't rebuild them), and the result of that step is cached anyway by docker, so I don't see what could gained here by adding sccache to the mix. |
@jschwe you are correct, but at the end of the "docker build" step I purge everything from the CI runner not to leave any traces from the build as a standard procedure. I thought I would be able to use sccache to cache the results into a dedicated mounted place inside the server. You can argue that both options are identical. |
It appears as if you don't save and restore |
That is what I did not understand - I thought that merely defining the env var with |
did anyone figure out how to make this work? i'm trying the
|
This works for me: RUN --mount=type=cache,mode=0777,target=/home/root/.cache/sccache \
cargo build --release && sccache --show-stats It also prints stats so you can verify if the cache was being used or not. What did not work was using a env. variable as RUN --mount=type=cache,mode=0777,target=${SCCACHE_DIR} \
cargo build --release && sccache --show-stats |
strange, for me this doesn't work, always getting 0 cache hits, with or without the env variable
|
perhaps the key is to use the |
Did you use buildx? Have you set the wrapper variables in the Dockerfile? ENV CARGO_HOME=/usr/local/cargo
ENV RUSTC_WRAPPER=/usr/local/cargo/bin/sccache
ENV SCCACHE_DIR=/home/root/.cache/sccache # must be same as the 'target' value for the mount cmd |
@lcmgh yes i am using |
It is recommended to use cloud storage services such as S3 or GCS when using sccache in Docker or CI environments. |
@Xuanwo i will not build the rust executable in the Docker container, and will only copy the final artifact in once its ready |
Hi,
According to what I understand from the readme here, in order to make sccache work with
cargo build --release
in Dockerfile I only need to install it usingcargo install sccache
and then set the environment variableRUSTC_WRAPPER
, and then build the project normally. And when the build is triggered for the second time (when there is a cache present) - it should be much faster.Well, this is not the case for me - maybe I'm doing something wrong. Here is my Dockerfile which I then trigger in Gitlab CI:
When I run this stage, each time the compilation takes exactly the same (long) time. When I look at the directory where I defined to save the cache - it is empty. It seems like either I missed some steps from the readme or that sccache just does not work for some reason.
I Would appreciate some help.
The text was updated successfully, but these errors were encountered: