Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ module(
version = "0.0.0",
)

bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.2.13")
bazel_dep(name = "rules_python", version = "1.7.0")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "rules_python", version = "1.9.0")
bazel_dep(name = "rules_shell", version = "0.7.1")
bazel_dep(name = "squashfs-tools", version = "4.7.5")

bazel_dep(name = "aspect_bazel_lib", version = "2.21.2", dev_dependency = True)
bazel_dep(name = "container_structure_test", version = "1.19.1", dev_dependency = True)
bazel_dep(name = "rules_oci", version = "2.2.6", dev_dependency = True)
bazel_dep(name = "rules_pkg", version = "1.1.0", dev_dependency = True)
bazel_dep(name = "bazel_lib", version = "3.2.2", dev_dependency = True)
bazel_dep(name = "container_structure_test", version = "1.22.1", dev_dependency = True)
bazel_dep(name = "rules_oci", version = "2.3.0", dev_dependency = True)
bazel_dep(name = "rules_pkg", version = "1.2.0", dev_dependency = True)
bazel_dep(name = "rules_pycross", version = "0.8.1", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.9.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.8.0", dev_dependency = True)
bazel_dep(name = "with_cfg.bzl", version = "0.10.3", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.8.1", dev_dependency = True)
bazel_dep(name = "with_cfg.bzl", version = "0.14.6", dev_dependency = True)

single_version_override(
module_name = "stardoc",
patches = ["//third_party:stardoc.diff"], # https://github.com/bazelbuild/stardoc/pull/303
version = "0.8.1",
)

rules_appimage = use_extension("//:extensions.bzl", "appimage_ext_dependencies")
use_repo(
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ rules_appimage_deps()

rules_appimage_development_deps()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")

compatibility_proxy_repo()

load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")

rules_shell_dependencies()
Expand Down
66 changes: 36 additions & 30 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def _rules_appimage_workspace_deps():
maybe(
http_archive,
name = "rules_python",
sha256 = "f609f341d6e9090b981b3f45324d05a819fd7a5a56434f849c761971ce2c47da",
strip_prefix = "rules_python-1.7.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.7.0/rules_python-1.7.0.tar.gz",
sha256 = "098ba13578e796c00c853a2161f382647f32eb9a77099e1c88bc5299333d0d6e",
strip_prefix = "rules_python-1.9.0",
url = "https://github.com/bazel-contrib/rules_python/releases/download/1.9.0/rules_python-1.9.0.tar.gz",
)

def rules_appimage_development_deps():
Expand All @@ -75,48 +75,54 @@ def rules_appimage_development_deps():
maybe(
http_archive,
name = "bazel_features",
sha256 = "adc8ddf121917f197f75c5245dfa8d7b1619f10a1002e25062b093b7957f2798",
strip_prefix = "bazel_features-1.37.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.37.0/bazel_features-v1.37.0.tar.gz",
sha256 = "adfdb3cffab3a99a63363d844d559a81965d2b61a6062dd51a3d2478d416768f",
strip_prefix = "bazel_features-1.45.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.45.0/bazel_features-v1.45.0.tar.gz",
)

# jq.bzl is needed by aspect_bazel_lib
# jq.bzl is needed by bazel_lib
maybe(
http_archive,
name = "jq.bzl",
sha256 = "21617eb71fb775a748ef5639131ab943ef39946bd2a4ce96ea60b03f985db0c5",
strip_prefix = "jq.bzl-0.4.0",
url = "https://github.com/bazel-contrib/jq.bzl/releases/download/v0.4.0/jq.bzl-v0.4.0.tar.gz",
sha256 = "e2eab5410b2eecc72f01d73590c58aefeddbb696ddf9d9c34dcee02dd79625ab",
strip_prefix = "jq.bzl-0.6.1",
url = "https://github.com/bazel-contrib/jq.bzl/releases/download/v0.6.1/jq.bzl-v0.6.1.tar.gz",
)

# aspect_bazel_lib is needed by rules_pycross (which is not used by tests in WORKSPACE) and with_cfg.bzl
# bazel_lib is needed by rules_pycross (which is not used by tests in WORKSPACE) and with_cfg.bzl
maybe(
http_archive,
name = "aspect_bazel_lib",
sha256 = "53cadea9109e646a93ed4dc90c9bbcaa8073c7c3df745b92f6a5000daf7aa3da",
strip_prefix = "bazel-lib-2.21.2",
url = "https://github.com/bazel-contrib/bazel-lib/releases/download/v2.21.2/bazel-lib-v2.21.2.tar.gz",
name = "bazel_lib",
sha256 = "3d62bf30b95b71a566d9ebca50ee78d370b12522d244235b41166f65b142705d",
strip_prefix = "bazel-lib-3.2.2",
url = "https://github.com/bazel-contrib/bazel-lib/releases/download/v3.2.2/bazel-lib-v3.2.2.tar.gz",
)
maybe(
http_archive,
name = "platforms",
url = "https://github.com/bazelbuild/platforms/releases/download/1.0.0/platforms-1.0.0.tar.gz",
sha256 = "3384eb1c30762704fbe38e440204e114154086c8fc8a8c2e3e28441028c019a8",
)
maybe(
http_archive,
name = "rules_cc",
sha256 = "472ddca8cec1e64ad78e4f0cabbec55936a3baddbe7bef072764ca91504bd523",
strip_prefix = "rules_cc-0.2.13",
url = "https://github.com/bazelbuild/rules_cc/releases/download/0.2.13/rules_cc-0.2.13.tar.gz",
sha256 = "283fa1cdaaf172337898749cf4b9b1ef5ea269da59540954e51fba0e7b8f277a",
strip_prefix = "rules_cc-0.2.17",
url = "https://github.com/bazelbuild/rules_cc/releases/download/0.2.17/rules_cc-0.2.17.tar.gz",
)
maybe(
http_archive,
name = "rules_oci",
sha256 = "5994ec0e8df92c319ef5da5e1f9b514628ceb8fc5824b4234f2fe635abb8cc2e",
strip_prefix = "rules_oci-2.2.6",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v2.2.6/rules_oci-v2.2.6.tar.gz",
sha256 = "e987cab7a35475cb9c9060fc3f338a1fc8896c240295a3272968b217acefd0cb",
strip_prefix = "rules_oci-2.3.0",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v2.3.0/rules_oci-v2.3.0.tar.gz",
)
maybe(
http_archive,
name = "rules_shell",
sha256 = "e6b87c89bd0b27039e3af2c5da01147452f240f75d505f5b6880874f31036307",
strip_prefix = "rules_shell-0.6.1",
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.6.1/rules_shell-v0.6.1.tar.gz",
sha256 = "3709d1745ba4be4ef054449647b62e424267066eca887bb00dd29242cb8463a0",
strip_prefix = "rules_shell-0.7.1",
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.7.1/rules_shell-v0.7.1.tar.gz",
)
maybe(
http_archive,
Expand All @@ -128,14 +134,14 @@ def rules_appimage_development_deps():
maybe(
http_archive,
name = "with_cfg.bzl",
sha256 = "c8eb6b436415ad283ccc72291542b597934b95f227211837005f2928eb542e6c",
strip_prefix = "with_cfg.bzl-0.10.3",
url = "https://github.com/fmeum/with_cfg.bzl/releases/download/v0.10.3/with_cfg.bzl-v0.10.3.tar.gz",
sha256 = "87852e133c3755a5642fe10543ee20eda700dae14d30d13dac96e22ea5106d07",
strip_prefix = "with_cfg.bzl-0.14.6",
url = "https://github.com/fmeum/with_cfg.bzl/releases/download/v0.14.6/with_cfg.bzl-v0.14.6.tar.gz",
)
maybe(
http_archive,
name = "container_structure_test",
sha256 = "c91a76f7b4949775941f8308ee7676285555ae4756ec1ec990c609c975a55f93",
strip_prefix = "container-structure-test-1.19.3",
url = "https://github.com/GoogleContainerTools/container-structure-test/archive/refs/tags/v1.19.3.tar.gz",
sha256 = "186bb1493ebb3c597e53b2a7abd5460c683c63d404e44a64223d26bb3315841d",
strip_prefix = "container-structure-test-1.22.1",
url = "https://github.com/GoogleContainerTools/container-structure-test/archive/refs/tags/v1.22.1.tar.gz",
)
3 changes: 2 additions & 1 deletion docs/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")
load("@stardoc//stardoc:stardoc_with_diff_test.bzl", "stardoc_with_diff_test", "update_docs")

stardoc_with_diff_test(
name = "defs",
bzl_library_target = "//appimage:defs",
out_label = "defs.md",
)

update_docs(name = "update")
4 changes: 2 additions & 2 deletions docs/defs.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Package your binary into an AppImage.
| <a id="appimage-data"></a>data | Any additional data that will be made available inside the appimage | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="appimage-binary"></a>binary | - | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
| <a id="appimage-build_args"></a>build_args | - | List of strings | optional | `[]` |
| <a id="appimage-env"></a>env | Runtime environment variables. See https://bazel.build/reference/be/common-definitions#common-attributes-tests | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="appimage-env"></a>env | Runtime environment variables. See https://bazel.build/reference/be/common-definitions#common-attributes-tests | <a href="https://bazel.build/rules/lib/core/dict">Dictionary: String -> String</a> | optional | `{}` |


<a id="appimage_test"></a>
Expand All @@ -47,7 +47,7 @@ Package your test target into an AppImage.
| <a id="appimage_test-data"></a>data | Any additional data that will be made available inside the appimage | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="appimage_test-binary"></a>binary | - | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
| <a id="appimage_test-build_args"></a>build_args | - | List of strings | optional | `[]` |
| <a id="appimage_test-env"></a>env | Runtime environment variables. See https://bazel.build/reference/be/common-definitions#common-attributes-tests | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
| <a id="appimage_test-env"></a>env | Runtime environment variables. See https://bazel.build/reference/be/common-definitions#common-attributes-tests | <a href="https://bazel.build/rules/lib/core/dict">Dictionary: String -> String</a> | optional | `{}` |


<a id="appimage_toolchain"></a>
Expand Down
102 changes: 102 additions & 0 deletions third_party/stardoc.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
--- MODULE.bazel
+++ MODULE.bazel
@@ -9,8 +9,9 @@
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_java", version = "8.6.1")
bazel_dep(name = "rules_jvm_external", version = "6.6")
bazel_dep(name = "rules_license", version = "1.0.0")
+bazel_dep(name = "rules_shell", version = "0.7.1")

# Maven artifacts required by Stardoc; keep consistent with deps.bzl
STARDOC_MAVEN_ARTIFACTS = [
"com.beust:jcommander:1.82",
new file mode 100644
--- /dev/null
+++ stardoc/stardoc_with_diff_test.bzl
@@ -0,0 +1,86 @@
+load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
+load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
+load(":stardoc.bzl", "stardoc")
+
+def stardoc_with_diff_test(
+ name,
+ bzl_library_target,
+ out_label,
+ **kwargs):
+ """Creates a stardoc target that can be auto-detected by update_docs to write the generated doc to the source tree and test that it's up to date.
+
+ This is helpful for minimizing boilerplate in repos with lots of stardoc targets.
+
+ Args:
+ name: the name of the stardoc file to be written to the current source directory (.md will be appended to the name). Call bazel run on this target to update the file.
+ bzl_library_target: the label of the `bzl_library` target to generate documentation for
+ out_label: the label of the output MD file
+ **kwargs: additional attributes passed to the stardoc() rule, such as for overriding the templates
+ """
+
+ out_file = out_label.replace("//", "").replace(":", "/")
+
+ # Generate MD from .bzl
+ stardoc(
+ name = out_file.replace("/", "_").replace(".md", "-docgen"),
+ out = out_file.replace(".md", "-docgen.md"),
+ input = bzl_library_target + ".bzl",
+ deps = [bzl_library_target],
+ )
+
+ # Ensure that the generated MD has been updated in the local source tree
+ diff_test(
+ name = out_file.replace("/", "_").replace(".md", "-difftest"),
+ failure_message = "Please run \"bazel run //docs:update\"",
+ # Source file
+ file1 = out_label,
+ # Output from stardoc rule above
+ file2 = out_file.replace(".md", "-docgen.md"),
+ )
+
+def update_docs(
+ name = "update",
+ docs_folder = "docs"):
+ """Creates a sh_binary target which copies over generated doc files to the local source tree.
+
+ This is to be used in tandem with `stardoc_with_diff_test()` to produce a convenient workflow
+ for generating, testing, and updating all doc files as follows:
+
+ ``` bash
+ bazel build //{docs_folder}/... && bazel test //{docs_folder}/... && bazel run //{docs_folder}:update
+ ```
+
+ eg.
+
+ ``` bash
+ bazel build //docs/... && bazel test //docs/... && bazel run //docs:update
+ ```
+
+ Args:
+ name: the name of the sh_binary target
+ docs_folder: the name of the folder containing the doc files in the local source tree
+ """
+ content = ["#!/usr/bin/env bash", "cd ${BUILD_WORKSPACE_DIRECTORY}"]
+ data = []
+ for r in native.existing_rules().values():
+ if r["kind"] == "stardoc":
+ doc_gen = r["out"]
+ if doc_gen.startswith(":"):
+ doc_gen = doc_gen[1:]
+ doc_dest = doc_gen.replace("-docgen.md", ".md")
+ data.append(doc_gen)
+ content.append("cp -fv bazel-bin/{0}/{1} {2}".format(docs_folder, doc_gen, doc_dest))
+
+ update_script = name + ".sh"
+ write_file(
+ name = "gen_" + name,
+ out = update_script,
+ content = content,
+ )
+
+ sh_binary(
+ name = name,
+ srcs = [update_script],
+ data = data,
+ )