# Writing a Bazel rule set

DevFeed: [Writing a Bazel rule set](<https://devfeed.tech/articles/writing-a-bazel-rule-set-21771.md>)

Original publisher: [Read original article](<https://enoent.fr/posts/creating-a-blog-with-bazel/04-writing-bazel-rule-set/>)

Author: Marc Plano-Lesay

Published: 2020-05-16T04:55:00Z

Content type: tutorial

Language: en

Sources: [Marc Plano-Lesay](<https://devfeed.tech/sources/marc-plano-lesay.md>)

Topics: [bazel](<https://devfeed.tech/topics/bazel.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [Java](<https://devfeed.tech/topics/java.md>), [SVG](<https://devfeed.tech/topics/svg.md>)

Tags: [bazel](<https://devfeed.tech/tags/bazel.md>), [cli](<https://devfeed.tech/tags/cli.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [java](<https://devfeed.tech/tags/java.md>), [plantuml](<https://devfeed.tech/tags/plantuml.md>), [svg](<https://devfeed.tech/tags/svg.md>)

## AI overview

A tutorial on writing and testing a Bazel rule set to run PlantUML as a command-line tool. It covers PlantUML inputs and outputs, Java JAR execution, configuration files, SVG and PNG generation, and challenges from platform-dependent font rendering and non-hermetic metadata.

## Source excerpt

This post will cover two things: How to run an arbitrary tool with Bazel (in this case, PlantUML, a tool to generate diagrams), by writing a rule set How to test this rule set. It should be mentioned that while I was working on this rule set, it became more and more apparent PlantUML is not a great candidate for this kind of integration, as its output is platform-dependent (the font rendering). Despite that, it's still a simple tool and as such its integration is simple, albeit not perfect (the rendering tests I wrote need to run on the same platform every time). PlantUML usage PlantUML is a tool that takes a text input looking like this: @startuml Alice -> Bob: SYN @enduml And outputs an image looking like this: sequenceDiagram Alice->>Bob: SYN PlantUML sample output PlantUML has multiple way of being invoked (CLI, GUI, as well as a lot of integrations with different tools), but we'll go with the easiest: a one-shot CLI invocation. It takes as inputs: A text file, representing a diagram An optional configuration file, giving control over the output It then outputs a single image file, which can be of different formats (we'll just cover SVG and PNG in this article, but adding support for other formats is trivial). PlantUML ships as a JAR file, which needs to be run with Java. An invocation generating the sample image above would look like that: java -jar plantuml.jar -tpng -p < 'mysource.puml' > 'dir/myoutput.png' Pretty straightforward: run the JAR, with a single option for the image type, pipe the content of the input file and get the output file back. The -p flag is the short form of -pipe, which we're using as using pipes is the only way of properly controlling the output path (without that, PlantUML tries to be smart and places the output next to the input). With a configuration file: java -jar plantuml.jar -tpng -config config.puml -p < 'mysource.puml' > 'dir/myoutput.png' Simple enough, right? Well, not really. PlantUML actually integrates some metadata in th