mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.74k stars 542 forks source link

The `RUSTC_WORKSPACE_WRAPPER` case does not work if the wrapper is called `rustc` #2040

Open nagisa opened 8 months ago

nagisa commented 8 months ago

I’m trying to set up sccache and I have a wrapper script at a location scripts/coverage-wrappers/rustc that I set RUSTC_WORKSPACE_WRAPPER to.

Cargo then invokes $RUSTC_WRAPPER $RUSTC_WORKSPACE_WRAPPER $RUSTC "$@", sccache compiler detection code notices that $RUSTC_WORKSPACE_WRAPPER is named rustc and tries to invoke $RUSTC_WORKSPACE_WRAPPER -v which naturally fails, because the first argument ain’t $RUSTC as expected by the wrapper.

I think detection logic should be adjusted to check if the first argument to sccache is actually the same thing as $RUSTC_WORKSPACE_WRAPPER and then use the next argument to query version. Or a possible alternative is to invoke $RUSTC_WORKSPACE_WRAPPER $RUSTC ${SCCACHE_ARGS}.

nagisa commented 8 months ago

Another problem, even when I had renamed the wrapper script to something else than rustc I would still see an error when running cargo build

  cargo build --locked --profile dev-release -p neard --bin neard
  shell: /usr/bin/bash -e {0}
  env:
    CI_HACKS: 1
    pythonLocation: /opt/hostedtoolcache/Python/3.11.7/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.7/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.7/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.7/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.7/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.7/x64/lib
    SCCACHE_PATH: /opt/hostedtoolcache/sccache/0.7.5/x64/sccache
    ACTIONS_CACHE_URL: https://acghubeus1.actions.githubusercontent.com/Gv3ljlJl5EjEbK2TmdZ8BXVzVUjRQhtIvr6X7PmTEjRmsGZMxp/
    ACTIONS_RUNTIME_TOKEN: ***
    SCCACHE_GHA_ENABLED: true
    RUSTC_WRAPPER: sccache
    LLVM_PROFILE_FILE: /home/runner/work/nearcore/nearcore/target/nearcore-%p-%4m.profraw
    CARGO_LLVM_COV: 1
    CARGO_LLVM_COV_SHOW_ENV: 1
    CARGO_LLVM_COV_TARGET_DIR: /home/runner/work/nearcore/nearcore/target
    RUSTC_WORKSPACE_WRAPPER: /home/runner/work/nearcore/nearcore/scripts/coverage-wrapper-rustc
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `sccache /home/runner/work/nearcore/nearcore/scripts/coverage-wrapper-rustc /home/runner/.rustup/toolchains/1.75.0-x86_64-unknown-linux-gnu/bin/rustc - --crate-name ___ --print=file-names -Cforce-unwind-tables=y --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit status: 2)
  --- stderr
  sccache: error: failed to execute compile
  sccache: caused by: Compiler not supported: "/home/runner/work/nearcore/nearcore/scripts/coverage-wrapper-rustc: line 9: exec: -E: invalid option\nexec: usage: exec [-cl] [-a name] [command [argument ...]] [redirection ...]\n"

Only after I manually set $CARGO=1 did things started chugging along, which suggests to me that perhaps cargo isn’t always setting $CARGO environment variable? Might be bug in cargo too, though. Not sure.