Hi there,
I’m trying to use zig’s build system to build the HDF5 library (C lib + C++ bindings). HDF5 has a very complicated build system, so I would like to re-use some parts of it for the time being. In particular, I’d like to be able to run the configure bash script that comes with the script before building the library.
Currently, I have a config
step set-up:
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 })
});
run_config.has_side_effects = true;
// Capture the output to create a dependency for the main code
const output = run_config.captureStdOut();
config_step.dependOn(&b.addInstallFile(output, "hdf5-config.log").step);
b.default_step.dependOn(config_step);
To make sure that the compile steps don’t run before the config step is finished, I figured I’d capture the output of the script and add it as a dependency for the other steps:
hdf5.root_module.addAnonymousImport("sometext", .{.root_source_file = output });
hdf5.step.dependOn(config_step);
However, this does not work :c.
The script seems to run first, followed by a compilation attempt (I get a blank line while the script is running, followed by the usual compiler output when it starts compiling the C files). However, the compiler cannot find the headers generated by the script after it is finished.
Running zig build
a second time works just fine (after the headers were generated by the first run).
Any help is much appreciated!