Zig fetch updating file modification times in extracted archives

Background

Running zig fetch to download and extract an archive seems to update the modification time of files in the extracted package. This interferes with automake/autoreconf, similarly to how this article describes it: Timestamps, GNU autotools, and repositories

For context, I generally build my most used tools from source, and am attempting to leverage zig build as a “better Makefile” i.e. fetch upstream sources declared by build.zig.zon, run arbitrary system commands on downloaded packages, install artifacts to a common location.

Reproduction

Version

0.15.2

Fetching the upstream source

zig fetch --save=make https://ftp.gnu.org.uk/gnu/make/make-4.4.tar.gz

build.zig

(Please ignore the lack of .addFileInput() etc. which would semi-integrate this with caching - there’s obviously lots of stuff missing here)

const std = @import("std");

pub fn build(b: *std.Build) void {
    const install_dir = b.getInstallPath(.prefix, "make");
    std.log.info("Install Directory: {s}", .{install_dir});
    const make = b.dependency("make", .{});
    const make_root = make.path("");

    const configure = b.addSystemCommand(&.{
        "./configure",
        "--prefix",
        install_dir,
        "--disable-dependency-tracking",
    });
    configure.setCwd(make_root);

    const bootstrap = b.addSystemCommand(&.{ "sh", "build.sh" });
    bootstrap.setCwd(make_root);
    bootstrap.step.dependOn(&configure.step);

    const install = b.addSystemCommand(&.{"./make"});
    install.setCwd(make_root);
    install.step.dependOn(&bootstrap.step);
    b.getInstallStep().dependOn(&install.step);
}

This gives us the following when run:

WARNING: 'aclocal-1.16' is missing on your system.
         You should only need it if you modified 'acinclude.m4' or
         'configure.ac' or m4 files included by 'configure.ac'.
         The 'aclocal' program is part of the GNU Automake package:
         <https://www.gnu.org/software/automake>
         It also requires GNU Autoconf, GNU m4 and Perl in order to run:
         <https://www.gnu.org/software/autoconf>
         <https://www.gnu.org/software/m4/>
         <https://www.perl.org/>
make: *** [Makefile:651: aclocal.m4] Error 127

Now obviously, I could just go and install autotools - but the core problem is that this occurs as the modification time of the files has been changed, which causes the whole autoreconf-fest to launch into action.

If we download and manually extract the archive with tar, each file has its modification time given at the time of archive creation, which avoids the need for any autotools reconfiguration:

wget https://ftp.gnu.org.uk/gnu/make/make-4.4.tar.gz
tar xvf make-4.4.tar.gz
ls -la make-4.4
total 1264
drwxr-xr-x 10 kai kai   4096 Oct 31  2022 .
drwxrwxr-x  3 kai kai   4096 Mar 14 18:43 ..
-rw-r--r--  1 kai kai  93787 Oct 31  2022 ABOUT-NLS
-rw-r--r--  1 kai kai  55130 Oct 31  2022 aclocal.m4
-rw-r--r--  1 kai kai   4327 Oct 23  2022 AUTHORS
-rw-r--r--  1 kai kai   5225 Oct 31  2022 Basic.mk
drwxr-xr-x  2 kai kai   4096 Oct 31  2022 build-aux
-rw-r--r--  1 kai kai   1217 Oct 23  2022 build.cfg.in
-rw-r--r--  1 kai kai   5582 Oct 23  2022 builddos.bat
-rwxr-xr-x  1 kai kai   5398 Oct 29  2022 build.sh
-rw-r--r--  1 kai kai  12441 Oct 23  2022 build_w32.bat
-rw-r--r--  1 kai kai 242663 Oct 31  2022 ChangeLog
-rwxr-xr-x  1 kai kai 466869 Oct 31  2022 configure
-rw-r--r--  1 kai kai  19269 Oct 31  2022 configure.ac
-rw-r--r--  1 kai kai  35151 Dec 19  2021 COPYING
drwxr-xr-x  2 kai kai   4096 Oct 31  2022 doc
-rw-r--r--  1 kai kai  15766 Jun  1  2022 INSTALL
drwxr-xr-x  2 kai kai   4096 Oct 31  2022 lib
drwxr-xr-x  2 kai kai   4096 Oct 31  2022 m4
-rw-r--r--  1 kai kai   7622 Oct 25  2022 Makefile.am
-rw-r--r--  1 kai kai   5330 Oct 23  2022 makefile.com
-rw-r--r--  1 kai kai  60444 Oct 31  2022 Makefile.in
drwxr-xr-x  2 kai kai   4096 Oct 31  2022 mk
-rw-r--r--  1 kai kai  83578 Oct 31  2022 NEWS
drwxr-xr-x  2 kai kai   4096 Oct 31  2022 po
-rw-r--r--  1 kai kai   8654 Oct 31  2022 README
-rw-r--r--  1 kai kai   2854 Oct 23  2022 README.Amiga
-rw-r--r--  1 kai kai   4496 Oct 23  2022 README.customs
-rw-r--r--  1 kai kai  13738 Oct 23  2022 README.DOS
-rw-r--r--  1 kai kai   6654 Oct 23  2022 README.OS2
-rw-r--r--  1 kai kai  21219 Oct 23  2022 README.VMS
-rw-r--r--  1 kai kai  15544 Oct 23  2022 README.W32
-rw-r--r--  1 kai kai    200 Feb 10  2022 SCOPTIONS
drwxr-xr-x  3 kai kai   4096 Oct 31  2022 src
drwxr-xr-x  3 kai kai   4096 Oct 31  2022 tests
-rw-r--r--  1 kai kai    937 Feb 10  2022 vms_export_symbol_test.com

If we look into the global zig cache for the package (after running zig fetch …), each file has its modification time as the time of extraction:

total 1264
drwxr-xr-x 10 kai kai   4096 Mar 14 18:46 .
drwxr-xr-x  3 kai kai   4096 Mar 14 18:46 ..
-rw-rw-r--  1 kai kai  93787 Mar 14 18:46 ABOUT-NLS
-rw-rw-r--  1 kai kai  55130 Mar 14 18:46 aclocal.m4
-rw-rw-r--  1 kai kai   4327 Mar 14 18:46 AUTHORS
-rw-rw-r--  1 kai kai   5225 Mar 14 18:46 Basic.mk
drwxr-xr-x  2 kai kai   4096 Mar 14 18:46 build-aux
-rw-rw-r--  1 kai kai   1217 Mar 14 18:46 build.cfg.in
-rw-rw-r--  1 kai kai   5582 Mar 14 18:46 builddos.bat
-rwxrwxrwx  1 kai kai   5398 Mar 14 18:46 build.sh
-rw-rw-r--  1 kai kai  12441 Mar 14 18:46 build_w32.bat
-rw-rw-r--  1 kai kai 242663 Mar 14 18:46 ChangeLog
-rwxrwxrwx  1 kai kai 466869 Mar 14 18:46 configure
-rw-rw-r--  1 kai kai  19269 Mar 14 18:46 configure.ac
-rw-rw-r--  1 kai kai  35151 Mar 14 18:46 COPYING
drwxr-xr-x  2 kai kai   4096 Mar 14 18:46 doc
-rw-rw-r--  1 kai kai  15766 Mar 14 18:46 INSTALL
drwxr-xr-x  2 kai kai   4096 Mar 14 18:46 lib
drwxr-xr-x  2 kai kai   4096 Mar 14 18:46 m4
-rw-rw-r--  1 kai kai   7622 Mar 14 18:46 Makefile.am
-rw-rw-r--  1 kai kai   5330 Mar 14 18:46 makefile.com
-rw-rw-r--  1 kai kai  60444 Mar 14 18:46 Makefile.in
drwxr-xr-x  2 kai kai   4096 Mar 14 18:46 mk
-rw-rw-r--  1 kai kai  83578 Mar 14 18:46 NEWS
drwxr-xr-x  2 kai kai   4096 Mar 14 18:46 po
-rw-rw-r--  1 kai kai   8654 Mar 14 18:46 README
-rw-rw-r--  1 kai kai   2854 Mar 14 18:46 README.Amiga
-rw-rw-r--  1 kai kai   4496 Mar 14 18:46 README.customs
-rw-rw-r--  1 kai kai  13738 Mar 14 18:46 README.DOS
-rw-rw-r--  1 kai kai   6654 Mar 14 18:46 README.OS2
-rw-rw-r--  1 kai kai  21219 Mar 14 18:46 README.VMS
-rw-rw-r--  1 kai kai  15544 Mar 14 18:46 README.W32
-rw-rw-r--  1 kai kai    200 Mar 14 18:46 SCOPTIONS
drwxr-xr-x  3 kai kai   4096 Mar 14 18:46 src
drwxr-xr-x  3 kai kai   4096 Mar 14 18:46 tests
-rw-rw-r--  1 kai kai    937 Mar 14 18:46 vms_export_symbol_test.com

Workarounds

There’s a couple obvious workarounds:

  1. Manual download + extract with std.http.Client and the inbuilt standard library compression modules
  2. Zig-ify the upstream myself (a-la allyourcodebase) - I’m more using the Zig build system as a task runner instead of a full-fledged compiler, so this feels somewhat orthogonal to what I’m trying to accomplish

Questions

  1. Is what I’m doing just an abuse of the build system and its dependency management?
  2. If not, is this a bug/missed feature in how Zig handles dependency extraction?

The issue is likely that it extracts to a temporary directory then copies into the cache, that updates the mtime.

you just called the build system of the package, you are not leveraging zigs build system.

This is the recommended solution.

But why are you trying to build make? If that is your goal see above.
I think you are probably wanting to use it for another package/project, in which case you can just get a prebuild executable as a zig dependency (it does need to be in an archive or git).