How to Create a Persistent Worker for Bazel

A little Q&A

cc -c monster.c
cc -c frail.c
cc -c weird.c
cc -c args.c
cc -c tpyos.c
...

Let’s get started

ctx.actions.run(
inputs = [input_file, ...],
outputs = [output_file],
mnemonic = "MyCompiler",
executable = my_compiler,
arguments = [
"--option1", "--option2", input_file, "-o", output_file
]
)
args_file = ctx.actions.write(
ctx.label.name + ".args", # the name of the args file
"\n".join([ # the contents of the args file
"--option1", "--option2", input_file, "-o", output_file
])
)
ctx.actions.run(
inputs = ...,
outputs = ...,
mnemonic = "MyCompiler",
executable = my_compiler,
arguments = [@args_file],
execution_requirements = { "supports-workers": "1" }
)
my_compiler --persistent_worker
ctx.actions.run(
inputs = ...,
outputs = ...,
mnemonic = "MyCompiler",
executable = my_compiler,
arguments = ["--maxmem=4G", @args_file],
execution_requirements = { "supports-workers": "1" }
)
my_compiler --maxmem=4G --persistent_worker
bazel --strategy=MyCompiler=worker //my:target
INFO: Created new non-sandboxed Javac worker (id 6), logging to /private/var/tmp/_bazel_mikemorearty/f2cd96704fd64e248571bccff6f9ab48/bazel-workers/worker-6-Javac.log

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store