houseabsolute / actions-rust-cross

GitHub Action to compile Rust with cross
Apache License 2.0
121 stars 13 forks source link

Support sccache #33

Open orf opened 6 days ago

orf commented 6 days ago

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/sccache-action@v0.0.6

      - 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 commented 5 days ago

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.