android / ndk

The Android Native Development Kit
2.01k stars 257 forks source link

[FR] create a sample showing how to use sccache #1790

Open DanAlbert opened 2 years ago

DanAlbert commented 2 years ago

Description

It's actually trivially easy to use sccache with CMake:

find_program(SCCACHE_PATH sccache REQUIRED)
set(CMAKE_C_COMPILER_LAUNCHER "${SCCACHE_PATH}")
set(CMAKE_C_LINKER_LAUNCHER "${SCCACHE_PATH}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${SCCACHE_PATH}")
set(CMAKE_CXX_LINKER_LAUNCHER "${SCCACHE_PATH}")

Might be worthwhile to build a full sample that does that with a GCS bucket for caching a github action.

DanAlbert commented 2 years ago

https://github.com/DanAlbert/sccache-example, but it's incomplete for the reasons mentioned in the readme.

larsbergstrom commented 2 years ago

cc @luser for feedback/tips here on sccache usage or limitations in CMake / with GCS buckets.

luser commented 2 years ago

I actually haven't used sccache with CMake! The guidance in the README was provided by a user. That combination does seem to be used in the wild. For example, in Qt: https://github.com/qt/qtbase/blob/1eb2d4d0da121b51832136773f4c863d3e9affc5/coin/instructions/prepare_building_env.yaml#L467-L492

luser commented 2 years ago

https://github.com/DanAlbert/sccache-example, but it's incomplete for the reasons mentioned in the readme.

re: building sccache via cargo install, that is definitely not recommended! The sccache repo provides pre-built release binaries. I'm not sure if there's some shortcut we could provide to make using sccache via GitHub Actions simpler? That would be worthwhile to explore.

There's not much complexity involved in using a cloud storage backend for sccache, but unfortunately it's not exactly plug-and-play. You need to create the bucket and configure it, and then set the appropriate environment variables to point sccache at it, as well as the access credentials as secrets. It would be nice if CI environments like GitHub Actions provided an API to use their provided cache storage as a simple key/value store. If that were available, sccache could be taught to use that directly, which would be perfect for small projects.

DanAlbert commented 2 years ago

re: building sccache via cargo install, that is definitely not recommended!

Oh yes, I saw the warnings in your docs (thanks for documenting that!) Above I was just trying to prove that it was possible to use with the NDK, and figured I might as well upload it as a starting point for someone else to improve. It's extremely not production ready :)

I'm not sure if there's some shortcut we could provide to make using sccache via GitHub Actions simpler? That would be worthwhile to explore.

I know next to nothing about this, but GitHub does have https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows which is how you would enable caching for other languages. That might be the place to start digging?