Hello!
I am trying to have my project use the Zig build system as an alternative, and am very close to doing so. There is one last thing that I cannot figure out myself unfortunately, it has to do with an object file (created with addObject
) that depends on the path of the output of a system command.
The full source of the build.zig
can be found here: https://github.com/Ivan-Velickovic/sel4cp_vmm/blob/restructure/examples/simple/build.zig.
I will attempt to show the relevant bits and explain what the problem exactly is.
I have this system command:
const dts_path = fmtPrint("board/{s}/linux.dts", .{ sel4cp_board });
const dtc_command = b.addSystemCommand(&[_][]const u8{
"dtc", "-I", "dts", "-O", "dtb", dts_path, "-o"
});
const dtb_image_path = dtc_command.addOutputFileArg("linux.dtb");
and this object file depends on it:
const guest_images = b.addObject(.{
.name = "guest_images",
.target = target,
.optimize = optimize,
});
dtb_image_path.addStepDependencies(&guest_images.step);
I donβt care where linux.dtb
is (ideally in the install directory but I donβt care at this point to be honest). But, what is important is that when guest_images
is compiled, that it the path to linux.dtb
exists.
const dtb_image_arg = fmtPrint("-DGUEST_DTB_IMAGE_PATH=\"{s}\"", .{ dtb_image_path.getPath(b) });
guest_images.addCSourceFiles(&.{ libvmm_tools ++ "package_guest_images.S" }, &.{
kernel_image_arg,
dtb_image_arg,
initrd_image_arg,
"-x",
"assembler-with-cpp",
});
Now when I run zig build
I end up getting this error message:
getPath() was called on a GeneratedFile that wasn't built yet.
source package path: /home/ivanv/ts/sel4cp_vmm/examples/simple
Is there a missing Step dependency on step 'run dtc (linux.dtb)'?
The step was created by this stack trace:
I thought it was appropriate to use dtb_image_path.getPath(b)
since after all guest_images
depends on dtb_image_path
(via addStepDependencies
but maybe Iβm wrong) and it needs the full final path in order to compile.
I hope Iβve explained everything, please let me know if I need to add more information. Iβm sure I am just misusing the API but after looking at the autodoc and the standard library source code, I am a bit lost.
Thanks!