chore: add example for plantuml
diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 3b912b5..af2b6c5 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel
@@ -1 +1,9 @@ # exports_files(["doxygen"]) +load("@doxygen//:doxygen.bzl", "doxygen") + +doxygen( + name = "doxygen", + srcs = ["//:README.md"], + project_brief = "Root folder example", + project_name = "root", +)
diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel index 3a4d7a1..0ef1489 100644 --- a/examples/MODULE.bazel +++ b/examples/MODULE.bazel
@@ -10,6 +10,16 @@ bazel_dep(name = "aspect_bazel_lib", version = "2.10.0") bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "rules_python", version = "1.2.0") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "rules_java", version = "8.15.1") + +http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") +http_file( + name = "plantuml_file", + urls = ["https://github.com/plantuml/plantuml/releases/download/v1.2025.4/plantuml-1.2025.4.jar"], + sha256 = "26518e14a3a04100cd76c0d96cab2d1171f36152215edd9790a28d20268200c1", + downloaded_file_path = "plantuml.jar", +) pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") pip.parse(
diff --git a/examples/plantuml/BUILD.bazel b/examples/plantuml/BUILD.bazel new file mode 100644 index 0000000..0e5e93e --- /dev/null +++ b/examples/plantuml/BUILD.bazel
@@ -0,0 +1,27 @@ +load("@doxygen//:doxygen.bzl", "doxygen") +load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file") + +# This is highly advised to avoid chasing the jar file who knows where +# Instead, we copy it in the OUTDIR folder +copy_file( + name = "plantuml", + src = "@plantuml_file//file", + out = "plantuml.jar", + allow_symlink = False, + is_executable = False, +) + +doxygen( + name = "doxygen", + srcs = [ + "lib.h", + ":plantuml", + ], + plantuml_jar_path = "$(OUTDIR)", + project_brief = "Example project for doxygen", + project_name = "Plantuml example", + tools = [ + # Using the java executable from `rules_java` + "@rules_java//toolchains:current_java_runtime", + ], +)
diff --git a/examples/plantuml/README.md b/examples/plantuml/README.md new file mode 100644 index 0000000..0589ffa --- /dev/null +++ b/examples/plantuml/README.md
@@ -0,0 +1,59 @@ +# Plantuml example + +This is an example of how to use the `doxygen` alongside `plantuml` to generate UML diagrams for C++ classes. +You will need to provide the `plantuml.jar` file to the rule, as well as the `java` executable. + +The JAR can be downloaded from the [plantuml releases page](https://github.com/plantuml/plantuml/releases). + +```bzl +# We will use the Java toolchain from rules_java to run the JAR +bazel_dep(name = "rules_java", version = "8.15.1") + + +http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") +http_file( + name = "plantuml_file", + urls = ["https://github.com/plantuml/plantuml/releases/download/v1.2025.4/plantuml-1.2025.4.jar"], + sha256 = "26518e14a3a04100cd76c0d96cab2d1171f36152215edd9790a28d20268200c1", + downloaded_file_path = "plantuml.jar", +) +``` + +## Using the JAR + +Since the location of the JAR can be difficult to determine, we recommend copying it to the `OUTDIR` folder using the `copy_file` rule from `aspect_bazel_lib`. + +```bzl +load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file") + +# This is highly advised to avoid chasing the jar file who knows where +# Instead, we copy it in the OUTDIR folder +copy_file( + name = "plantuml", + src = "@plantuml_file//file", + out = "plantuml.jar", + allow_symlink = False, + is_executable = False, +) +``` + +Lastly, you can use the `doxygen` rule as follows: + +```bzl +load("@doxygen//:doxygen.bzl", "doxygen") + +doxygen( + name = "doxygen", + srcs = [ + "lib.h", + ":plantuml", + ], + plantuml_jar_path = "$(OUTDIR)", + project_brief = "Example project for doxygen", + project_name = "Plantuml example", + tools = [ + # Using the java executable from `rules_java` + "@rules_java//toolchains:current_java_runtime", + ], +) +```
diff --git a/examples/plantuml/lib.h b/examples/plantuml/lib.h new file mode 100644 index 0000000..4dd0ecf --- /dev/null +++ b/examples/plantuml/lib.h
@@ -0,0 +1,22 @@ +/** + * @file lib.h + * @author Ernesto Casablanca (casablancaernesto@gmail.com) + * @copyright 2024 + */ +#pragma once + +/** + * @brief Add two integers + * + * Who knows what the result will be? + * In the meantime, look at the graph! + * @startuml "Insightful diagram" width=5cm + * Alice -> Bob : Hello + * @enduml + * @note This function is very complex. Use it with caution. + * @warning The result can be greater than the maximum value that can be stored! + * @param a First integer + * @param b Second integer + * @return Sum of a and b + */ +int add(int a, int b);