Hello, so this is a bit of a strange use case.
I am trying to make a build.zig that compiles a .tex file for me using pdflatex. I chose to use build.zig to just learn a bit about it and make use of its file system watching. Now my problem is that I dont know how to make it watch files that arent exactly source files.
In case anyone knows a project where a build.zig is used for non-zig languages id be really interested in looking at how its done too.
As @Sze said, this works if you let the build system know about both the input(s) and output(s). Here’s an example using addFileArg and addOutputFileArg:
Judging from here, I think this would be the most “correct” way to go (untested):
const std = @import("std");
pub fn build(b: *std.Build) !void {
// -jobname=main is just to ensure the output filename is consistent
const build_cmd = b.addSystemCommand(&.{ "pdflatex", "-halt-on-error", "-jobname=main", "-output-directory" });
const output_dir = build_cmd.addOutputDirectoryArg("output");
build_cmd.addFileArg(b.path("main.tex"));
b.getInstallStep().dependOn(&build_cmd.step);
const generated_pdf = output_dir.path("main.pdf");
const show_cmd = b.addSystemCommand(&.{ "firefox", "--new-window" });
// This will implicitly add a dependency on build_cmd
show_cmd.addFileArg(generated_pdf);
const show = b.step("show", "Open the pdf");
show.dependOn(&show_cmd.step);
}
If you want the pdf to end up installed in some particular location, then you’d want to use b.addInstallFile or b.addInstallFileWithDir and pass it generated_pdf