Running a configure script as a build step (trying to build HDF5)

Hi @smups welcome to ziggit :slight_smile:

You don’t need the output, the module and the final dependencies.

const config_step = b.step("configure", "configure hdf5 for building on this machine");
const config_path = try root_dir.realpathAlloc(alloc, "configure");
const run_config = b.addSystemCommand(&.{ config_path });
run_config.addArgs(&.{
    "--enable-cxx",
    b.fmt("--srcdir={s}", .{ root_path })
});

config_step.dependOn(&run_config.step);

The last statement says that config_step depends on the run_config.
So when you say zig build configure runs the configure script.

Additionally you need to say that your const exe = b.addExecutable( exe depends on config_step.

exe.step.dependOn(config_step);

b.addConfigHeader can sometimes replace configure scripts
example for zstd:

    const config_header = b.addConfigHeader(
        .{
            .style = .{ .autoconf = b.path("config.h.in") },
        },
        .{
            .ZSTD_MULTITHREAD_SUPPORT_DEFAULT = null,
            .ZSTD_LEGACY_SUPPORT = null,
        },
    );
    lib.addConfigHeader(config_header);
3 Likes