houseabsolute / actions-rust-cross

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

Support caching cross-rs download #4

Closed timon-schelling closed 1 year ago

timon-schelling commented 1 year ago

Thanks for creating this action, exactly what I needed.

I would like to propose the implementation of the GitHub actions caching mechanism for Rust cross download. This would significantly improve build times by removing the need for redundant downloads across runs.

https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows

I'll try to come up with a solution myself, but I'm probably not knowledgeable enough in GitHub action development.

autarch commented 1 year ago

Hmm, for some weird reason I didn't get an email when you made this issue. Glad I found it!

Yes, this sounds like a great idea. I'll take a look. It shouldn't be too hard.

timon-schelling commented 1 year ago
    steps:
      - uses: actions/checkout@v3
      - name: Cache cargo & target directories
        uses: Swatinem/rust-cache@v2
      - name: Cache Docker images
        uses: ScribeMD/docker-cache@0.3.3
        with:
          key: docker-${{ runner.os }}-${{ hashFiles('.github/workflows/build.yaml') }}
      - name: Build binary
        uses: houseabsolute/actions-rust-cross@v0
        with:
          target: ${{ matrix.platform.target }}
          toolchain: ${{ matrix.toolchain }}
          command: "build"

I tried this but downloading and unpacking from Cache is actualy slower than pulling the docker image. I Hope you find a better way.

Btw, supporting caching for builds inside cross containers could also help build times.

autarch commented 1 year ago

I just tested caching the install of the cross binary and that seems to save about 20s. Yes, caching the target dir inside the Docker image would be a big win. I'll take a look at that too.

autarch commented 1 year ago

Actually, I realized that caching the cargo and target dirs is probably not in scope for this action. You can simply use the Swatinem/rust-cache action and it just works because (I assume) the checkout dir is mounted as a volume inside the Docker image.

That particular action has a lot of parameters. If I used it inside this action, I'd have to add all those parameters to this action just so you could set them, which doesn't seem very useful. I will update the docs for this action to note that you can use that action with this one.

autarch commented 1 year ago

This is done in v0.0.8.