Skip to content

Commit 21b1541

Browse files
authored
Add first stardoc API docgen target (#598)
1 parent 5bf6ef7 commit 21b1541

File tree

5 files changed

+230
-603
lines changed

5 files changed

+230
-603
lines changed

WORKSPACE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ swift_rules_extra_dependencies()
1717
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
1818

1919
bazel_skylib_workspace()
20+
21+
# For API doc generation
22+
# This is a dev dependency, users should not need to install it
23+
# so we declare it in the WORKSPACE
24+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
25+
26+
http_archive(
27+
name = "io_bazel_stardoc",
28+
patches = [],
29+
sha256 = "f89bda7b6b696c777b5cf0ba66c80d5aa97a6701977d43789a9aee319eef71e8",
30+
strip_prefix = "stardoc-d93ee5347e2d9c225ad315094507e018364d5a67",
31+
urls = [
32+
"https://github.com/bazelbuild/stardoc/archive/d93ee5347e2d9c225ad315094507e018364d5a67.tar.gz",
33+
],
34+
)

doc/BUILD.bazel

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
2+
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
3+
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
4+
5+
_RULES_SYMBOLS = [
6+
"swift_binary",
7+
"swift_c_module",
8+
"swift_grpc_library",
9+
"swift_import",
10+
"swift_library",
11+
"swift_module_alias",
12+
"swift_proto_library",
13+
"swift_test",
14+
]
15+
16+
write_file(
17+
name = "gen_header",
18+
out = "header.vm",
19+
content = [
20+
"<!-- Generated with Stardoc, Do Not Edit! -->",
21+
"",
22+
"${moduleDocstring}",
23+
"On this page:",
24+
"",
25+
] + [" * [{0}](#{0})".format(r) for r in _RULES_SYMBOLS] + [
26+
"",
27+
],
28+
)
29+
30+
stardoc(
31+
name = "doc",
32+
out = "swift.md",
33+
header_template = ":header.vm",
34+
input = "//swift:swift.bzl",
35+
symbol_names = _RULES_SYMBOLS,
36+
deps = ["//swift"],
37+
)
38+
39+
# To make this test pass, run
40+
# bazel build doc:all && cp bazel-bin/doc/swift.md doc/rules.md
41+
diff_test(
42+
name = "test",
43+
file1 = "swift.md",
44+
file2 = "rules.md",
45+
)

0 commit comments

Comments
 (0)