Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: ccache support experiment #22305

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

DRAFT: ccache support experiment #22305

wants to merge 6 commits into from

Conversation

pipcet
Copy link

@pipcet pipcet commented Nov 17, 2024

I've looked into using ccache to speed up (re)compilation of termux packages, and I think I've got something that works, so I'll leave it here, if nothing else, for the next person to search for "ccache" to find.

The basic idea is, of course, to use ccache /path/to/clang instead of /path/to/clang and everything works automatically. It's not quite that easy, for these reasons:

  1. clang, unfortunately, depends on the name of the executable that is invoked to determine its behavior. This requires us to create a new symlink clang++-18 so we can still properly exec the compiler.
  2. Some build systems (ninja? cmake?) auto-detect the presence of a ccache binary in the path. We don't want that, so we rename our ccache binary to ccache.local
  3. The default configuration of ccache limits cache size to 5GB, and includes compression which reduces performance; the current version of this PR also includes debugging flags.
  4. cmake, by default, uses pre-compiled headers, which is a bad idea for many reasons; one of the reasons is that it busts ccache. Disable that.
  5. This patch also includes unrelated changes to mount more volumes when running the Docker container, which I'll remove in a bit.

Sorry for the code drop, but I think the benefits are quite noticeable and probably worth the trouble...

Pip Cet added 6 commits November 17, 2024 17:39
Note that we don't want a /usr/bin/ccache to exist; that makes various
build systems guess wildly that we might want to use ccache, and use
it with very bad default settings. It is therefore necessary to rename
the binary to avoid this incorrect and dangerous autodetection.
@TomJo2000
Copy link
Member

  • There was an earlier PR,
    allow caching builds #16882
    that covers a lot of the same ground as your proposal here.
    I'm assuming the earlier one has stalled for the time being.

Maybe @thunder-coding can have a look at this one, time permitting of course.

Copy link
Member

@thunder-coding thunder-coding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want you can look at the PR linked by @TomJo2000 for somethings missing from this PR

export CC=$TERMUX_HOST_PLATFORM-clang
export CPP=$TERMUX_HOST_PLATFORM-cpp
export CXX=$TERMUX_HOST_PLATFORM-clang++
export AS="ccache-$TERMUX_HOST_PLATFORM-clang"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supporting ability to disable ccache based on a conifg set in .termuxrc would be nice. ccache doesnt always work really well with all builds

@thunder-coding
Copy link
Member

thunder-coding commented Nov 19, 2024

Some build systems (ninja? cmake?) auto-detect the presence of a ccache binary in the path. We don't want that, so we rename our ccache binary to ccache.local

Ninja is a very minimal build system (the authors call it meta-build system) and does not try to be smart in anyway and just follows the rules defined in build.ninja. Talking of CMake, yes it can be told to use ccache in CMakeLists.txt but by default it will not try to use ccache unless specified in command line arguments to cmake

cmake, by default, uses pre-compiled headers, which is a bad idea for many reasons; one of the reasons is that it busts ccache. Disable that.

No, cmake does not use pre-compiled headers by default unless using target_precompile_headers in CMakeLists.txt. Also CMAKE_DISABLE_PRECOMPILE_HEADERS=ON might have negative effects when not using ccaache

@pipcet
Copy link
Author

pipcet commented Nov 19, 2024

Some build systems (ninja? cmake?) auto-detect the presence of a ccache binary in the path. We don't want that, so we rename our ccache binary to ccache.local

Ninja is a very minimal build system (the authors call it meta-build system) and does not try to be smart in anyway and just follows the rules defined in build.ninja. Talking of CMake, yes it can be told to use ccache in CMakeLists.txt but by default it will not try to use ccache unless specified in command line arguments to cmake

cmake, by default, uses pre-compiled headers, which is a bad idea for many reasons; one of the reasons is that it busts ccache. Disable that.

No, cmake does not use pre-compiled headers by default unless using target_precompile_headers in CMakeLists.txt. Also CMAKE_DISABLE_PRECOMPILE_HEADERS=ON might have negative effects when not using ccaache

If you want you can look at the PR linked by @TomJo2000 for somethings missing from this PR

Thanks! I've looked at that, and making ccache usage a build-package.sh option seems like a really good idea to me.

@pipcet
Copy link
Author

pipcet commented Nov 19, 2024

Some build systems (ninja? cmake?) auto-detect the presence of a ccache binary in the path. We don't want that, so we rename our ccache binary to ccache.local

Ninja is a very minimal build system (the authors call it meta-build system) and does not try to be smart in anyway and just follows the rules defined in build.ninja. Talking of CMake, yes it can be told to use ccache in CMakeLists.txt but by default it will not try to use ccache unless specified in command line arguments to cmake

As we have no control over the CMakeLists.txt files used to build packages, I see no way around renaming the binary or taking it out of the PATH for now.

cmake, by default, uses pre-compiled headers, which is a bad idea for many reasons; one of the reasons is that it busts ccache. Disable that.

No, cmake does not use pre-compiled headers by default unless using target_precompile_headers in CMakeLists.txt.

In the package I looked at, the string target_precompile_headers doesn't appear, but it still manages to somehow enable generation and usage of PCH files.

Since, again, we cannot control the CMakeLists.txt, we need to work around the problem by passing a flag to CMake, even if the misbehavior is due to a package bug.

Also CMAKE_DISABLE_PRECOMPILE_HEADERS=ON might have negative effects when not using ccaache

Absolutely, but it does appear to be required when using ccache.

@TomJo2000
Copy link
Member

TomJo2000 commented Nov 19, 2024

As we have no control over the CMakeLists.txt files used to build packages, I see no way around renaming the binary or taking it out of the PATH for now.

We can, and frequently do patch CMakeLists.txt files for packages.
So we do have some degree of control.

But sidestepping the issue is absolutely preferable to some jury rigged autopatcher.

Also CMAKE_DISABLE_PRECOMPILE_HEADERS=ON might have negative effects when not using ccaache

Absolutely, but it does appear to be required when using ccache.

That could be made a toggle.
So TERMUX_PKG_USE_CCACHE=true also turns off precompiled headers

@mbekkomo
Copy link
Contributor

mbekkomo commented Dec 3, 2024

Will there be a plan to support Sccache as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants