#add output file to step.run

1 messages · Page 1 of 1 (latest)

mystic spade
#

I have this tool invocation:

const lemon_run = b.addRunArtifact(lemon);
lemon_run.addArg("-q"); lemon_run.addFileArg(b.path("parser/parser.y"));

Lemon does not support overwriting the output file. it is hardcoded to be inputname with a differet suffix. how do i explain to the build system that this file will be created and use it later? I want something like addOutputFileArg but don't actually append an argument

floral sierra
#

although if lemon has an option that prints it to stdout instead of writing it to a file, you can use that along with lemon_run.captureStdOut()
that could be a good option

mystic spade
#

don't I have to declare the dependency between the tool running and the file being generated?

floral sierra
#

yeah addOutputFileArg doesnt seem to even set up a dependency or anything like that

mystic spade
floral sierra
#

that’s already done for you with the addFileArg(b.path(“parser/parse.y”)) line

#

it already depends on that path now

#

the output doesnt matter for that

mystic spade
mystic spade
floral sierra
#

only if a step your user runs depends on them
the install step is the default step that runs when you do just zig build

floral sierra
mystic spade
mystic spade
#
    const lemon_run = b.addRunArtifact(lemon);
    lemon_run.addArg("-q");
    lemon_run.addFileArg(b.path("parser/parser.y"));
    lemon_run.addArg("#"); // trickery
    const parser_c = lemon_run.addOutputFileArg("parser.c");
    const parser_h = lemon_run.addOutputFileArg("parser.h");

I tried this btw it doesnt work lol

floral sierra
#

with WriteFile.addCopyFile

floral sierra
mystic spade
#

i'm not sure how exactly i can use b.addWriteFile to achieve this

floral sierra
#

and then write_files.getDirectory() will return the directory those files were put into

mystic spade
#

parser/parser.c? But I dont want build artifacts in my source directory. is there a way around this?

floral sierra
#

I guess you could delete those files after you copy them but idk how well supported that is in the build.zig

#

or you could copy the parser.y file into cache using this same strategy and then the parser.c and parser.h will be in that same directory in cache
I have no clue if that’s allowed though, im not sure that the build system expects anything but build steps to modify the cache directory

#

I dont see why it wouldnt work just feels a bit icky

#

another idea is that you can compile lemon from source and just patch it to allow adding a output file
which is annoying, sure, but you can PR it and itll be a lot more ergonomic and idiomatic

#

(you can compile it in the build.zig and use the package manager to fetch the source, so it shouldnt be too annoying)

#

hm
looks like you can use the -d parameter to specify the output directory

#

you can definitely use that

mystic spade
floral sierra
#

actually no, hm
Step.Run doesnt seem to have a way to add an output directory
seems like an oversight

mystic spade
floral sierra
#

yeah sorry, not sure how youd be able to do this