Building and caching multiple Rust binaries on CI

I maintain a C++ application. We recently started using sccache for our Windows builds with MSVC. Currently we have to build sccache from Git because we depend on a bug fix in sccache I did that was just merged but has not been released yet. Currently this is what we are doing in our GitHub Actions workflow file:

    - name: "[Windows] Set up cargo cache"
      if: runner.os == 'Windows'
      uses: actions/cache@v2
      id: sccache-build-cache
        path: C:\Users\runneradmin\.cargo
        # hash of commit to build
        key: e12434e4db24ccbe52b83fb6e37afcb94fc8d37b

    # This needs to be done first because something later messes with $PATH in a way that breaks cargo
    # by causing it to find link.exe from Git for Windows instead of MSVC.
    - name: "[Windows] Build fixed sccache"
      shell: bash
      if: runner.os == 'Windows' && steps.sccache-build-cache.outputs.cache-hit != 'true'
      # TODO: change this to simply `cargo install sccache` after 0.2.16 has been released
      run: cargo install --git --branch master

This works well enough with one binary, but we will be adding more Rust binaries as dependencies in the future. Then using the commit hash of one for the cache key won't work anymore.

We are rewriting our database code with a standalone application in Rust communicating over an HTTP API. I am unclear how we can use cargo to build both sccache and this other binary and cache them on CI. I tried adding a Cargo.toml to the C++ repo root so we could use the hash of the Cargo.lock file as the cache key:

name = "mixxx"
version = "2.3.0"
authors = ["Mixxx DJ Software maintainers"]
edition = "2018"

# sccache's handling of the /fp:fast MSVC compiler option is broken, but this is fixed in the master branch.
sccache = { git = "", branch = "master" }

However, cargo build builds the sccache crate but not the sccache executable. It only builds the dummy mixxx executable (because cargo doesn't work without a src/ or src/ file). cargo install --path . likewise only installs the dummy mixxx executable. I'm unclear if Tracking Issue for RFC 3028: Allow "artifact dependencies" on bin, cdylib, and staticlib crates · Issue #9096 · rust-lang/cargo · GitHub might be needed for this use case? Or is there another way to do this already?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.