ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
32.37k stars 2.36k forks source link

`zig cc` doesn't cache when using depfiles (CMake's default) #16712

Open PiotrSikora opened 11 months ago

PiotrSikora commented 11 months ago

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

Download any project using CMake, e.g. zlib-ng:

$ git clone https://github.com/zlib-ng/zlib-ng
$ cd zlib-ng

Purge Zig cache and rebuild standard C library:

$ rm -rf ~/.cache/zig
$ zig cc /dev/null 2>/dev/null

Build zlib-ng with CMake:

$ mkdir build-with-depfiles
$ cd build-with-depfiles
$ CC="zig cc" CXX="zig c++" cmake ..
$ time make zlib >/dev/null && make clean && time make zlib >/dev/null

real    0m16.483s
user    0m14.633s
sys     0m2.011s 

real    0m13.092s
user    0m11.359s
sys     0m1.741s 

Expected Behavior

I expected the build time to improve significantly thanks to Zig's builtin caching system, but that wasn't the case.

Note that it works when the use of depfiles is disabled using -DCMAKE_DEPENDS_USE_COMPILER=OFF.

Purge Zig cache and rebuild standard C library:

$ rm -rf ~/.cache/zig
$ zig cc /dev/null 2>/dev/null

Build zlib-ng with CMake without the use of depfiles:

$ mkdir build-without-depfiles
$ cd build-without-depfiles
$ CC="zig cc" CXX="zig c++" cmake -DCMAKE_DEPENDS_USE_COMPILER=OFF ..
$ time make zlib >/dev/null && make clean && time make zlib >/dev/null

real    0m17.608s
user    0m15.408s
sys     0m2.238s

real    0m1.242s
user    0m0.701s
sys     0m0.563s

The only difference between those invocations are the -MD, -MF, and -MT flags.

PiotrSikora commented 11 months ago

cc @motiejus, since this probably also affects Bazel, which I believe is using depfiles... Although, I imagine that Zig's caching system not caching those artifacts on top of Bazel's cache is a desired feature.

motiejus commented 11 months ago

Although, I imagine that Zig's caching system not caching those artifacts on top of Bazel's cache is a desired feature.

Yes: https://github.com/ziglang/zig/pull/12605