Generating dump with build system

I’m trying to make a dump using llvm-objdump and write the output to a file:

  // dump executable
  const objdump_program = try b.findProgram(&.{"llvm-objdump"}, &.{});
  const objdump_run = b.addSystemCommand(&.{objdump_program, "-ds", "zig-out/bin/program"});
  const objdump_step = &b.addInstallFile(objdump_run.captureStdOut(), "bin/program.dump").step;
  b.getInstallStep().dependOn(objdump_step);

It worked the very first time. But it looks like the program.dump file has been cached and is not overwritten by the new output of subsequent llvm_objdump runs.
How do I make the program.dump file be updated every llvm-objdump run?

Try passing the artifact (executable/library/object) file using objdump_run.addFileArg() instead of using a hard-coded path. This should make the build system recognize that objdump should be re-run if the artifact changes.

// dump executable
const objdump_program = b.findProgram(&.{"llvm-objdump"}, &.{}) catch "llvm-objdump";
const objdump_run = b.addSystemCommand(&.{ objdump_program, "-ds" });
objdump_run.addFileArg(program.getEmittedBin());
const objdump_step = &b.addInstallBinFile(objdump_run.captureStdOut(), "program.dump").step;
b.getInstallStep().dependOn(objdump_step);
3 Likes

Thanks a lot. It works. :+1: