Skip to content
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

Support sccache #33

Open
orf opened this issue Nov 23, 2024 · 5 comments
Open

Support sccache #33

orf opened this issue Nov 23, 2024 · 5 comments

Comments

@orf
Copy link

orf commented Nov 23, 2024

Hey! Awesome action <3

It would be amazing to support sccache with this action. It's possible right now, but fiddly: I've hacked it in with:

      # From https://github.com/mozilla/sccache/blob/main/docs/GHA.md
      - name: Configure sccache
        uses: actions/github-script@v7
        with:
          script: |
            core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
            core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

      - name: Run sccache-cache
        uses: mozilla-actions/[email protected]

      - name: Build binary
        uses: houseabsolute/actions-rust-cross@v0
        env:
          CROSS_CONFIG: "cross/Cross.sccache.toml"
          RUSTC_WRAPPER: "sccache"
        with:
          target: ${{ matrix.platform.target }}

With

[build.dockerfile]
file = "cross/cross.sccache.Dockerfile"

[build.env]
passthrough = [
    "SCCACHE_GHA_ENABLED",
    "ACTIONS_CACHE_URL",
    "ACTIONS_RUNTIME_TOKEN",
    "RUSTC_WRAPPER=sccache"
]

And the dockerfile:

ARG CROSS_BASE_IMAGE
FROM $CROSS_BASE_IMAGE
ARG DEBIAN_FRONTEND=noninteractive

COPY cross/sccache.sh /sccache.sh
RUN /sccache.sh x86_64-unknown-linux-musl

ENV RUSTC_WRAPPER="/usr/bin/sccache"

with the script from the cross wiki.

@autarch
Copy link
Member

autarch commented Nov 23, 2024

This seems like it'd be useful. Are you sure that you need the first bit? The docs for the sccache-action don't call this out, so I wonder if this is actually needed.

Also, I'm not clear on where that TOML snippet you shared goes. Is that in your Cargo.toml? If that's the case, can we set those variables via env vars instead? That way people wouldn't need to modify their Cargo.toml to take advantage of this. It'd be nice if this just worked transparently for folks (probably with an option to disable it).

And I think that instead of using that sccache.sh script we could use my ubi tool. It's a little annoying to use because on Linux x86-64 it tries to download the sccache-dist tarball instead of sccache, so you need to passing --match sccache-v to get it to pick the right thing.

@autarch
Copy link
Member

autarch commented Dec 22, 2024

I just implemented support for Swatinem/rust-cache in this action. From my reading, it seems like sccache would be a replacement for that. But I'm not entirely sure how it would work with cross. I'd be open to replacing the rust-cache usage with sccache if it was more performant (and not too likely to hit GitHub Action cache limits).

@orf
Copy link
Author

orf commented Dec 22, 2024

I’ve found a combination of both to be highly effective: we install and use sccache only when there is a cache hit from Swatinem/rust-cache.

This sounds counter-intuitive, but you do indeed hit rate limits when building from scratch. But sccache offers little benefit in this case. using it for incremental compilation only gives you the best of both worlds: a full cache with most objects, and sccache to cache all the other stuff you’re changing in between full caches.

@autarch
Copy link
Member

autarch commented Dec 22, 2024

I’ve found a combination of both to be highly effective: we install and use sccache only when there is a cache hit from Swatinem/rust-cache.

Oh, that's interesting. Do you have any GitHub Actions config file I could look at where you do this? Or maybe you can paste an excerpt here?

@orf
Copy link
Author

orf commented Dec 22, 2024

Unfortunately not (it’s private), and I won’t have access to my work machine for a while.

It’s basically just an if: steps.cache.hit on the setup scache step (we actually use use actions/cache, I assume rust-cache has something similar), and an extra step to set RUSTC_WRAPER and the other env var needed. It’s really simple to get working.

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

No branches or pull requests

2 participants