In my build system, I want to use a system command. Unfortunately, the way that specific command takes options is not through arguments. Instead, it takes a JSON config file. One of the fields should be the path to a (generated) file, thus a LazyPath
. Is there a clean way to write the LazyPath to a file, and then pass that file as an argument? Thanks.
b.path
is usually given a string literal, but any slice will do the job. It’s not 100% clear what you want to do here, but if it’s reading a relative path out of a file and providing that to b.path
, you can certainly do that.
Sorry for the bad explanation. I have a generated file, which is a LazyPath. Let’s call it “initrd”. I have a command, mkbootimg
, that takes arguments as mkbootimg <config_file> <output>
. The thing is, in the (JSON) config file, I have to specify the path to “initrd”. So, what I want is to write the path of “initrd” into a JSON file, and then pass that JSON file as a parameter. But remember, “initrd” is a lazypath…
Can you specify the path via an argument, cause then you can just pass the lazyPath
using the relevant functions.
If it needs to be in a file then perhaps make a script that writes the path that it takes as an argument.
when running commands from the build system you should always configure inputs and outputs via args or capture stdout/in, that way the build system can use its cache
I would love to use addFileArg
, but unfortunately the only way the program takes that file path is through a JSON file.
I think I’ll do what you said. I’ll write a script and call that. Thanks!
You can adapt this example Zig Build System ⚡ Zig Programming Language
Pass the actual path as input argument to the zig program that writes it to a json file, then pass it an output file too, then get the lazy path to that json output file and pass that to the command that expects the json.