Suppose I am writing a custom Bazel rule for foo-compiler
.
The user provides a list of source-files to the rule:
foo_library(
name = "hello",
srcs = [ "A.foo", "B.foo" ],
)
To build this without Bazel, the steps would be:
- Create a config file
config.json
that lists the sources:
{
"srcs": [ "./A.foo", "./B.foo" ]
}
- Place the config alongside the sources:
$ ls .
A.foo
B.foo
config.json
- Call
foo-compiler
in that directory:
$ foo-compiler .
Now, in my Bazel rule implementation I can declare a file like this:
config_file = ctx.actions.declare_file("config.json")
ctx.actions.write(
output = config_file,
content = json_for_srcs(ctx.files.srcs),
)
The file is created and it has the right content.
However, Bazel does not place config.json
alongside the srcs
.
Is there a way to tell Bazel where to place the file?
Or perhaps I need to copy each source-file alongside the config?