Thomas Ferrand [Sun, 11 Feb 2024 15:11:47 +0000 (16:11 +0100)]
feat: Port the inode cache to Windows (#1388)
This PR ports the existing InodeCache to make it work under Windows.
This speeds up ccache a lot, both in the hit and miss cases, when a lot
of headers files are included in several compilation units. In our case
this makes the difference between ccache being worth using or not.
The logic of the InodeCache itself is unchanged. I introduced a
MemoryMap helper class that does the platform specific calls to
mmap/MapViewOfFile. Despite its generic name, I've implemented what was
needed for the InodeCache, it only supports mapping a file (no anonymous
mmap) in a shared fashion with read/write access.
Due to differences in behavior between unix and Windows regarding
unlinking a file that is opened, I am not convinced that it will work
correctly in every situation (for example if a process hold a bucket
lock for more than 5 seconds, the cache is dropped and recreated, under
Windows that won't work as the unlink will fail). That being said it
seems to work well enough when nothing unexpected happens.
I made a small change to the unit test because under Windows, we can't
open() a directory so instead I try to open a temp file in that
directory. After that change the unit tests pass unmodified.
For the bash based test, only the symbolic link test fails. This is
quite strange, when I try to run the test, the call to `ln -fs test1.c
test2.c` fails, but when run manually the same command succeeds. I tried
to run the test manually and it fails anyway but I haven't done anything
to fix it, this looks like more an issue from the DirEntry side than the
InodeCache side. Because of that I've left the bash based test disabled
for Windows, maybe we want to change that to only disable the symbolic
link test?
Joel Rosdahl [Sat, 10 Feb 2024 08:54:19 +0000 (09:54 +0100)]
fix: Fix reading of files larger than 2^31 bytes
For some kernels read(2) makes a short read for counts larger than 2^31,
even for files on 64-bit architectures. Other kernels seem to not like
large counts at all, returning a failure.
Fix this by limiting the read buffer to a smaller value. This also
removes a short read optimization which should have been removed in cff3bf417420ea88fe53e7267ae2a356898ae326.
Joel Rosdahl [Wed, 7 Feb 2024 20:09:02 +0000 (21:09 +0100)]
chore: Further improve /Tc and /Tp handling
- Remember if /Tc or /Tp was used and prepend it to the source file sent
to the preprocessor and compiler.
- Mark non-concatenated versions of /Tc and /Tp as too hard for now.
Joel Rosdahl [Mon, 5 Feb 2024 18:51:49 +0000 (19:51 +0100)]
fix: Fix MSVC crash when using /Zi /Fddebug.pdb
With /Zi, MSVC starts a long-lived mspdbsrv.exe background process. The
implementation of #1274 kills all processes created by ccache including
mspdbsrv.exe, which can make cl.exe crash with this error message:
Joel Rosdahl [Sun, 14 Jan 2024 09:46:54 +0000 (10:46 +0100)]
fix: Disable caching for modified source/include files
On a cache miss, ccache opts out of the direct mode when a "too new"
include file is found. This is done to avoid a race condition in the
direct mode when a header file if modified after ccache is invoked but
before the compiler is executed. Modifying the main source code file is
not a race condition when "run_second_cpp = false", which was the case
at the time the direct mode was introduced. However, the default of
run_second_cpp was changed to true in ccache 3.3, and the potiential
race condition then exists for both the source and the include files.
Fix this by disabling caching completely (not only the direct mode) when
modification of a source/include file is detected.
Joel Rosdahl [Sat, 2 Dec 2023 11:24:07 +0000 (12:24 +0100)]
feat: Improve processing of input file arguments
Instead of checking if a non-option argument has a known file extension,
switch to the better heuristic of checking if the file exists or not: if
it doesn't exist it isn't an input argument.
Rafael Kitover [Sun, 29 Oct 2023 08:33:09 +0000 (08:33 +0000)]
fix: Devmode unused function warnings on new MSVC (#1342)
MSVC apparently has overrides for the two definitions of operator== in
unittest/test_util_string.cpp in the <utility> header, raising a warning
about them being local unused functions:
Rafael Kitover [Sun, 29 Oct 2023 08:31:15 +0000 (08:31 +0000)]
feat: cmake -DOFFLINE=TRUE for offline builds (#1341)
Add the cmake option OFFLINE, defaulting to the value of the standard
variable FETCHCONTENT_FULLY_DISCONNECTED, which is OFF by default, to
disable downloading anything from the internet.
When ON, set FETCHCONTENT_FULLY_DISCONNECTED to ON, ZSTD_FROM_INTERNET
to OFF and HIREDIS_FROM_INTERNET to OFF.
When downloading is OFF and either library is not found, throw an error
using find_package_handle_standard_args().
Add the option to INSTALL.md doc.
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
Rafael Kitover [Sun, 29 Oct 2023 08:28:15 +0000 (08:28 +0000)]
fix: cmake -DSTATIC_LINK=ON on Linux/macOS (#1340)
Make linking dependent libraries as static a hard requirement when
STATIC_LINK is ON, as opposed to the previous behavior of falling back
to dynamic libraries.
A side-effect of this is that if only a dynamic zstd/hiredis is
available on a system, it will not be found, and the download and build
code will be invoked to build a static version from the internet.
Add a general case to handle Linux, macOS and similar by linking
libgcc/libstdc++ statically on gcc/clang.
Move the code into cmake/StaticLinkSupport.cmake and include it from the
main file.
Fix #1330
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
Joel Rosdahl [Mon, 16 Oct 2023 17:33:31 +0000 (19:33 +0200)]
fix: Let DirEntry::size_on_disk return likely size on disk
st_blocks in struct stat cannot be trusted for some filesystems that do
transparent compression or deduplication. For instance, ZFS can adjust
the block count some time in the future when compression is finished.
The only reasonable fix for this seems to be to just guess how much
space the file will take using st_size.