1load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 2load("//python:py_test.bzl", "py_test") 3load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility 4load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs") 5load("//sphinxdocs:sphinx_stardoc.bzl", "sphinx_stardoc", "sphinx_stardocs") 6 7# We only build for Linux and Mac because: 8# 1. The actual doc process only runs on Linux 9# 2. Mac is a common development platform, and is close enough to Linux 10# it's feasible to make work. 11# Making CI happy under Windows is too much of a headache, though, so we don't 12# bother with that. 13_TARGET_COMPATIBLE_WITH = select({ 14 "@platforms//os:linux": [], 15 "@platforms//os:macos": [], 16 "//conditions:default": ["@platforms//:incompatible"], 17}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"] 18 19sphinx_docs( 20 name = "docs", 21 srcs = glob( 22 include = [ 23 "*.md", 24 ], 25 ), 26 config = "conf.py", 27 formats = [ 28 "html", 29 ], 30 renamed_srcs = { 31 "//sphinxdocs/inventories:bazel_inventory": "bazel_inventory.inv", 32 }, 33 sphinx = ":sphinx-build", 34 strip_prefix = package_name() + "/", 35 target_compatible_with = _TARGET_COMPATIBLE_WITH, 36 deps = [ 37 ":bzl_function", 38 ":bzl_providers", 39 ":simple_bzl_docs", 40 ], 41) 42 43sphinx_stardocs( 44 name = "simple_bzl_docs", 45 srcs = [ 46 ":bzl_rule_bzl", 47 ":bzl_typedef_bzl", 48 ], 49 target_compatible_with = _TARGET_COMPATIBLE_WITH, 50) 51 52sphinx_stardoc( 53 name = "bzl_function", 54 src = ":bzl_function.bzl", 55 target_compatible_with = _TARGET_COMPATIBLE_WITH, 56 deps = [":func_and_providers_bzl"], 57) 58 59sphinx_stardoc( 60 name = "bzl_providers", 61 src = ":bzl_providers.bzl", 62 prefix = "addprefix_", 63 target_compatible_with = _TARGET_COMPATIBLE_WITH, 64 deps = [":func_and_providers_bzl"], 65) 66 67# A bzl_library with multiple sources 68bzl_library( 69 name = "func_and_providers_bzl", 70 srcs = [ 71 "bzl_function.bzl", 72 "bzl_providers.bzl", 73 ], 74) 75 76bzl_library( 77 name = "bzl_rule_bzl", 78 srcs = ["bzl_rule.bzl"], 79 deps = [":func_and_providers_bzl"], 80) 81 82bzl_library( 83 name = "bzl_typedef_bzl", 84 srcs = ["bzl_typedef.bzl"], 85) 86 87sphinx_build_binary( 88 name = "sphinx-build", 89 tags = ["manual"], # Only needed as part of sphinx doc building 90 deps = [ 91 "//sphinxdocs/src/sphinx_bzl", 92 "@dev_pip//myst_parser", 93 "@dev_pip//sphinx", 94 "@dev_pip//typing_extensions", # Needed by sphinx_stardoc 95 ], 96) 97 98py_test( 99 name = "sphinx_output_test", 100 srcs = ["sphinx_output_test.py"], 101 data = [":docs"], 102 deps = ["@dev_pip//absl_py"], 103) 104