GithubHelp home page GithubHelp logo

chocobo1 / setup-ccache-action Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 4.0 11.93 MB

Setup ccache easily in your workflow, with all the tuning knobs you need!

License: MIT License

TypeScript 100.00%
caching ccache cpp github-actions

setup-ccache-action's Introduction

Setup ccache in Github Actions workflow GithubActionBadge

Please don't hesitate to give this project a star⭐ if it is useful to you!

Basic usage

If you have a simple workflow, the action can be used like this:

- name: Checkout repository
  uses: actions/checkout@v2

- name: Setup ccache
  uses: Chocobo1/setup-ccache-action@v1

- name: Build C++ program
  run: |
    ./configure
    make

Advanced usage

This action provides a few flags for customizing the behavior.
For description of all options, take a look at action.yml.

  • update_packager_index
    By default, this action will update packager's indexes to avoid installation issues (apt/brew on linux/macOS respectively).
    You can disable it to save some time however you are then responsible for ensuring the packager's indexes are up-to-date before using this action.

    - name: Checkout repository
      uses: actions/checkout@v2
    
    - name: Install dependencies
      run: |
        sudo apt update  # ensure indexes are up-to-date
        sudo apt install \
          libboost-dev
    
    - name: Setup ccache
      uses: Chocobo1/setup-ccache-action@v1
      with:
        update_packager_index: false
    
    - name: Build C++ program
      run: |
        cmake -B build ./
        cmake --build build
  • install_ccache
    By default, this action will install ccache with package manager.
    You can omit installation if you've already installed ccache and it is accessible from the shell. If you use false for this option, it is likely you also want to set update_packager_index to false too.

    - name: Checkout repository
      uses: actions/checkout@v2
    
    - name: Install dependencies
      run: |
        sudo apt update  # ensure indexes are up-to-date
        sudo apt install \
          ccache \
          libboost-dev
    
    - name: Setup ccache
      uses: Chocobo1/setup-ccache-action@v1
      with:
        install_ccache: false
        update_packager_index: false
    
    - name: Build C++ program
      run: |
        cmake -B build ./
        ninja -C build
  • prepend_symlinks_to_path
    By default, this action will prepend ccache's compiler symlinks directory to PATH so that compiler invocations will be handled by ccache transparently. If you wish to handle it manually then you can set this option to false. Also see: https://ccache.dev/manual/latest.html#_run_modes
    Note that the symlinks directory is different for each OS and to simplify this the action provides a handy environment variable that you can use: ${{ env.ccache_symlinks_path }}. This variable is only available after the setup ccache step.

    - name: Setup ccache
      uses: Chocobo1/setup-ccache-action@v1
      with:
        prepend_symlinks_to_path: false
    
    - name: Build C++ program
      run: |
        export PATH="${{ env.ccache_symlinks_path }}:$PATH"
        cmake -B build ./
        make -C build
  • ccache_options
    You are able to pass/configure ccache's options with this flag.
    Accepts multiline key=value.
    See: https://ccache.dev/manual/latest.html#_configuration_options

    - name: Setup ccache
      uses: Chocobo1/setup-ccache-action@v1
      with:
        ccache_options: |
          max_size=200M
          compression=false
  • windows_compile_environment
    Specify which compiler environment you are going to use on Windows image.
    This field is mandatory if you intend to use this action on a Windows image!
    Refer to action.yml for available options.

    • If you are using msvc, first make sure you are informed of its limitations and usage tips:

      - name: Setup ccache
        uses: Chocobo1/setup-ccache-action@v1
        with:
          windows_compile_environment: msvc  # this field is required
      
      - name: Build program
        run: |
          cmake `
            -B _build `
            -G "Ninja" `
            -DCMAKE_BUILD_TYPE=Release `
            -DCMAKE_CXX_COMPILER_LAUNCHER:FILEPATH="${{ env.ccache_symlinks_path }}" `
            .
          cmake --build _build
    • If you are uinsg msys2, note that as of October 2021, cmake have some problems when using the default "Ninja" generator. I would suggest using "MSYS Makefiles" generator along with the make package (without mingw-w64-*- prefix in package name).

      # run this action before setting up ccache
      - name: Setup msys2
        uses: msys2/setup-msys2@v2
        with:
          install: |
            make
            mingw-w64-x86_64-toolchain
      
      - name: Setup ccache
        uses: Chocobo1/setup-ccache-action@v1
        with:
          windows_compile_environment: msys2  # this field is required
      
      - name: Build program
        shell: msys2 {0}
        run: |
          cmake \
            -B _build \
            -G "MSYS Makefiles" \
            .
          cmake --build _build

Limitations

This action support running on Ubuntu (ubuntu-*) and macOS (macos-*).
On Windows it has primitive support for msvc and msys2.

Github Actions Permissions

By default, this action will remove previous/stale cache entries which would require actions: write permission. If you use the following configuration, then this action doesn't need any permissions:

- name: Setup ccache
  uses: Chocobo1/setup-ccache-action@v1
  with:
    remove_stale_cache: false

If your workflow doesn't need any permissions then you might want to specify the following at the top level for maximum security:

permissions: {}

References:

setup-ccache-action's People

Contributors

chocobo1 avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

setup-ccache-action's Issues

Use MSYSTEM_PREFIX

Hi @Chocobo1, thx for the great GH action.

This line:

return `/${Process.env.MSYSTEM}/lib/ccache/bin`;

should be? MINGW_PREFIX or MSYSTEM_PREFIX:
return ${Process.env.MINGW_PREFIX}/lib/ccache/bin;

Currently, it is ${Process.env.MSYSTEM}, so the path will be /UCRT64/lib/ccache/bin.
With MSYSTEM_PREFIX it will be /ucrt64/lib/ccache/bin.
I think that the MSYSTEM env. variable is not supposed to be used in paths, that is why MSYSTEM_PREFIX exists.

Here is source where it is defined and link to all occurrences.

Later: Also when I looked at GHA output log I have found two more cases where this upper-case UCRT64 is used:

Clear ccache statistics
Prepend ccache symlinks path to $PATH
  ccache symlinks path (msys): "/UCRT64/lib/ccache/bin"
  (msys) PATH=/UCRT64/lib/ccache/bin:/ucrt64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
Create environment variables
  ${{ env.ccache_symlinks_path }} = /UCRT64/lib/ccache/bin

So it should be changed for env.ccache_symlinks_path output variable and in prepend path too.

I'm not sure what is the difference between MSYSTEM_PREFIX and MINGW_PREFIX, or which one should be used when πŸ™‚, if you want I can ask at the msys2 issue tracker.

Cygwin support

Hi,

I tried to also make use of this action in combination with cygwin.

First the good news: The binary is found (thanks to that cygwin is added to the path).

And now the bad news: First thing I saw was the version check. It finds the binary from cygwin and the one from choco and doesn't seem to b able to handle this. It calls "bin1 bin2 --version" which just can't work. I was able to work around this by deleting the choco ccache.exe (Uninstalling didn't work as choco claims it didn't install it).

Second problem: cygwin ships ccache 3.1.9 which doesn't have --get-config and also doesn't have -p option:

c:\cygwin64\bin\ccache.exe -h
Usage:
ccache [options]
ccache compiler [compiler options]
compiler [compiler options] (via symbolic link)

Options:
-c, --cleanup delete old files and recalculate size counters
(normally not needed as this is done automatically)
-C, --clear clear the cache completely
-F, --max-files=N set maximum number of files in cache to N (use 0 for
no limit)
-M, --max-size=SIZE set maximum size of cache to SIZE (use 0 for no
limit; available suffixes: G, M and K; default
suffix: G)
-s, --show-stats show statistics summary
-z, --zero-stats zero statistics counters

-h, --help print this help text
-V, --version print version and copyright information

Cache-dir could be parsed from -s output:

c:\cygwin64\bin\ccache.exe -s
cache directory /home/micro/.ccache
cache hit (direct) 171
cache hit (preprocessed) 0
cache miss 172
files in cache 516
cache size 79.2 Mbytes
max cache size 1.0 Gbytes

Would be great if you could add cygwin, as it seems to be the only plattfrom that's missing. If you need some additional info, just let me know.

Do not add any timestamp to the cached file

I don't think there should be any timestamp in the cached file: It complicates the action's code as it has to lookup and cleanup, it still pollutes the cache, but what is this effort actually good for? Why would anyone want to keep old revisions of the ccache? It's a cache...

Brew install failing on macOS runners

Hi πŸ‘‹πŸΌ
Thanks for maintaining this nice action!

Since a couple of days ago, we are experiencing some problems on macOS runners, where the action fails to install ccache via brew.
More precisely, it fails with the following warning

/usr/local/bin/brew install ccache
  Error: $HOME must be set to run brew.

See https://github.com/cda-tum/mqt-core/actions/runs/5809540441/job/15748518266#step:3:168 for an example run that fails.

Some googling brings up Homebrew/brew#15833, which describes that a change has been introduced quite recently and $HOME needs to be specified now.

What I suspect is happening is that the process that the brew command is running in does not have access to the $HOME env variable that is automatically set by GitHub Actions. A potential solution could be to just pass that variable through here:

"env": {
"HOMEBREW_NO_INSTALL_CLEANUP": "1",
"HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK": "1"
},

I'll happily submit a PR if you feel that that might be a proper solution.

Should configure ccache before restore cache

If set cache_dir to another place,it will make restore cache never success.
Example:

- name: Set up ccache
  uses: Chocobo1/setup-ccache-action@v1
  with:
    ccache_options: |
      cache_dir=${{ env.workspace }}/.ccache

So I think it should configure ccache before restore cache.

Cache upload failed - ESPIPE: invalid seek

Hi @Chocobo1, today all my ccache actions calls started failing, it's a first time I see any problem with this action.

Here is the link to the failed action.

It fails with this error:

Error: Cache upload failed because file read failed with ESPIPE: invalid seek, read
    at ReadStream.<anonymous> (/home/runner/work/_actions/Chocobo1/setup-ccache-action/v1/dist/webpack:/@Chocobo1/setup-ccache-action/node_modules/@actions/cache/lib/internal/cacheHttpClient.js:180:1)

Do your ccache actions work?

Consider changing Windows warning to an info printout

Core.warning(`setup-ccache-action only support "ubuntu" and "macos" platforms. No operation...`);

IMO, this should be an info printout, not a warning. I'd like to be able to just use this action in a job that runs on all OSes, and have it be a no-op where not supported, rather than using conditionals to avoid the warning.

The warning creates an alert annotation in the workflow. For example: https://github.com/arvidn/libtorrent/actions/runs/1274732824

In the "PR checks" part of the actions UI, these annotations are surfaced with an exclamation mark -- See https://github.com/arvidn/libtorrent/pull/6484/checks

It appears that warnings are generally used where action/intervention is required.

Windows msvc support

Hi choco πŸ‘‹,

this week I have set up the ccache for all my Windows msvc toolchains, it has 100% cache hits and now I want to also set up the ccache for my Windows msvc related GitHub actions.

The following doesn't work, it quits with the Warning: "windows_compile_environment=" is not supported. No operation...:

    - name: ccache install πŸ₯³
      run: |
        choco install ccache -y

    - name: ccache setup πŸ•Ί
      uses: Chocobo1/setup-ccache-action@v1
      with:
        prepend_symlinks_to_path: false
        install_ccache: false
        update_packager_index: false
        ccache_options: |
          compression = false
          max_size = 1G

I don't ask for full msvc support, even the install_ccache may not work.

Would be good to normally continue if the windows_compile_environment is empty or windows_compile_environment=msvc.

I have tried following inside the Windows-2019 GitHub action's image, I'm posting here notes to make it easier for you:

  • The ccache --set-config xx=yy works out of the box if the ccache is already installed.
  • it creates ccache.conf file at $env:APPDATA/ccache/ccache.conf (~/AppData/Roaming/ccache)
  • choco installs ccache.exe at C:\ProgramData\chocolatey\bin\ccache.exe and it's on the system path

I think it would be enough to make it work inside the Windows-2019/2022 images.

Here is my cmake code that fixes/allows 100% ccache hits, it simply disables precompiled headers and replaces /Zi compiler option with the /Z7 in CMAKE_<C|CXX>_FLAGS_<CONFIG> flags.
The Cmake defaults to /Zi so it has 100% ccache misses because ccache doesn't support /Zi but it works great with the /Z7 compiler option. And also ccache doesn't support precompiled headers on Windows msvc.

brew exit code 1

Hi, after paying more attention at the annotations because of the 1.14 update (nice fix, works, thanks), I've seen one more. When giving just the make version and laving all other opts at default I get this output:

==> Installing ccache dependency: hiredis
==> Pouring hiredis--1.1.0.monterey.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again using:
brew postinstall hiredis
==> Summary
🍺 /usr/local/Cellar/hiredis/1.1.0: 41 files, 365.1KB
==> Installing ccache
==> Pouring ccache--4.8.monterey.bottle.tar.gz
Warning: The post-install step did not complete successfully
Warning: HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK is set: not checking for outdated
dependents or dependents with broken linkage!
You can try again using:
brew postinstall ccache
==> Caveats
To install symlinks for compilers that will automatically use
ccache, prepend this directory to your PATH:
/usr/local/opt/ccache/libexec

If this is an upgrade and you have previously added the symlinks to
your PATH, you may need to modify it to the path specified above so
it points to the current version.

NOTE: ccache can prevent some software from compiling.
ALSO NOTE: The brew command, by design, will never use ccache.
==> Summary
🍺 /usr/local/Cellar/ccache/4.8: 75 files, 1.4MB
==> Caveats
==> ccache
To install symlinks for compilers that will automatically use
ccache, prepend this directory to your PATH:
/usr/local/opt/ccache/libexec

If this is an upgrade and you have previously added the symlinks to
your PATH, you may need to modify it to the path specified above so
it points to the current version.

NOTE: ccache can prevent some software from compiling.
ALSO NOTE: The brew command, by design, will never use ccache.
Warning: The process '/usr/local/bin/brew' failed with exit code 1

`I'm not sure if this is by design (of brew) or avoidable, but I know it's annoying as it's the only annotation left in the workflow.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.