Skip to content

Commit 9656130

Browse files
authored
Merge pull request #23 from TendTo/fix/bazel7
fix: restore support for Bazel 7
2 parents 3266640 + f160095 commit 9656130

File tree

5 files changed

+160
-16
lines changed

5 files changed

+160
-16
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,30 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest, windows-latest, macos-latest]
17-
subdir: [base, kwargs, doxyfile, latex, nested, custom, awesome, substitutions]
17+
bazel: [7.0.0, 8.0.0]
18+
subdir:
19+
[
20+
base,
21+
kwargs,
22+
doxyfile,
23+
latex,
24+
nested,
25+
custom,
26+
awesome,
27+
substitutions,
28+
]
29+
exclude:
30+
# In substitution example we use `string_keyed_label_dict`, which is not supported in bazel 7.0.0
31+
- bazel: 7.0.0
32+
subdir: substitutions
1833
runs-on: ${{ matrix.os }}
1934

2035
steps:
2136
- uses: actions/checkout@v4
37+
- name: Create .bazelversion file
38+
working-directory: examples
39+
run: echo "${{ matrix.bazel }}" > .bazelversion
40+
shell: bash
2241
- name: Build ${{ matrix.subdir }}
2342
run: bazel build //${{ matrix.subdir }}:doxygen
2443
working-directory: examples
@@ -35,7 +54,17 @@ jobs:
3554
strategy:
3655
matrix:
3756
os: [ubuntu-latest, windows-latest, macos-latest]
38-
subdir: [base, kwargs, doxyfile, latex, nested, custom, awesome, substitutions]
57+
subdir:
58+
[
59+
base,
60+
kwargs,
61+
doxyfile,
62+
latex,
63+
nested,
64+
custom,
65+
awesome,
66+
substitutions,
67+
]
3968
runs-on: ${{ matrix.os }}
4069

4170
steps:
@@ -66,10 +95,15 @@ jobs:
6695
strategy:
6796
matrix:
6897
os: [ubuntu-latest, windows-latest, macos-latest]
98+
bazel: [7.0.0, 8.0.0]
6999
subdir: [base]
70100
runs-on: ${{ matrix.os }}
71101
steps:
72102
- uses: actions/checkout@v4
103+
- name: Create .bazelversion file
104+
working-directory: examples
105+
run: echo "${{ matrix.bazel }}" > .bazelversion
106+
shell: bash
73107
- name: Install doxygen
74108
uses: ssciwr/doxygen-install@v1
75109
- name: Enable use of windows doxygen by decommenting the module extension line
@@ -115,10 +149,15 @@ jobs:
115149
strategy:
116150
matrix:
117151
os: [ubuntu-latest, windows-latest, macos-latest]
152+
bazel: [7.0.0, 8.0.0]
118153
subdir: [base]
119154
runs-on: ${{ matrix.os }}
120155
steps:
121156
- uses: actions/checkout@v4
157+
- name: Create .bazelversion file
158+
working-directory: examples
159+
run: echo "${{ matrix.bazel }}" > .bazelversion
160+
shell: bash
122161
- name: Install doxygen
123162
uses: ssciwr/doxygen-install@v1
124163
with:
@@ -177,11 +216,16 @@ jobs:
177216
strategy:
178217
matrix:
179218
os: [ubuntu-latest, windows-latest, macos-latest]
219+
bazel: [7.0.0, 8.0.0]
180220
subdir: [root, submodule1, submodule2]
181221
runs-on: ${{ matrix.os }}
182222

183223
steps:
184224
- uses: actions/checkout@v4
225+
- name: Create .bazelversion file
226+
working-directory: examples
227+
run: echo "${{ matrix.bazel }}" > .bazelversion
228+
shell: bash
185229
- name: Build submodules/${{ matrix.subdir }}
186230
run: bazel build //:doxygen
187231
working-directory: examples/submodules/${{ matrix.subdir }}
@@ -192,4 +236,4 @@ jobs:
192236
fail: true
193237
- name: Check doxygen version in produced index.html
194238
run: grep "Doxygen $DEFAULT_DOXYGEN_VERSION" examples/submodules/${{ matrix.subdir }}/bazel-bin/html/index.html
195-
shell: bash
239+
shell: bash

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.2.2]
9+
10+
### Added
11+
12+
- CI tests for both Bazel 7 and 8
13+
14+
### Fix
15+
16+
- Remove dependency on `@bazel_tools//tools/build_defs/repo` to support Bazel 7.0.0 [#22](https://github.com/TendTo/rules_doxygen/issues/22) (thanks to @filmil)
17+
- Remove unnecessary `get_auth`
18+
19+
### Changed
20+
21+
- Made documentation clearer
22+
823
## [2.2.1]
924

1025
### Fix
@@ -73,7 +88,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7388
### Added
7489

7590
- Support for system-wide doxygen installation. This allows the rule to run on mac os, but loses hermeticity. Can be enabled by using doxygen version `0.0.0`.
76-
- Testes for the new feature in the CI pipeline
91+
- Tests for the new feature in the CI pipeline
7792
- Local repository rule for doxygen
7893

7994
### Changed

docs/extensions_doc.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,50 @@
22

33
Repository rule for downloading the correct version of doxygen using module extensions.
44

5+
<a id="get_default_canonical_id"></a>
6+
7+
## get_default_canonical_id
8+
9+
<pre>
10+
load("@rules_doxygen//:extensions.bzl", "get_default_canonical_id")
11+
12+
get_default_canonical_id(<a href="#get_default_canonical_id-repository_ctx">repository_ctx</a>, <a href="#get_default_canonical_id-urls">urls</a>)
13+
</pre>
14+
15+
Returns the default canonical id to use for downloads.
16+
17+
Copied from [@bazel_tools//tools/build_defs/repo:cache.bzl](https://github.com/bazelbuild/bazel/blob/dbb05116a07429ec3524bcf7252cedbb11269bea/tools/build_defs/repo/cache.bzl)
18+
to avoid a dependency on the whole `@bazel_tools` package, since its visibility changed from private to public between Bazel 7.0.0 and 8.0.0.
19+
20+
Returns `""` (empty string) when Bazel is run with
21+
`--repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0`.
22+
23+
e.g.
24+
```python
25+
load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id")
26+
# ...
27+
repository_ctx.download_and_extract(
28+
url = urls,
29+
integrity = integrity
30+
canonical_id = get_default_canonical_id(repository_ctx, urls),
31+
),
32+
```
33+
34+
35+
**PARAMETERS**
36+
37+
38+
| Name | Description | Default Value |
39+
| :------------- | :------------- | :------------- |
40+
| <a id="get_default_canonical_id-repository_ctx"></a>repository_ctx | The repository context of the repository rule calling this utility function. | none |
41+
| <a id="get_default_canonical_id-urls"></a>urls | A list of URLs matching what is passed to `repository_ctx.download` and `repository_ctx.download_and_extract`. | none |
42+
43+
**RETURNS**
44+
45+
The canonical ID to use for the download, or an empty string if
46+
`BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID` is set to `0`.
47+
48+
549
<a id="doxygen_repository"></a>
650

751
## doxygen_repository
@@ -75,7 +119,7 @@ doxygen_repository(
75119
<pre>
76120
doxygen_extension = use_extension("@rules_doxygen//:extensions.bzl", "doxygen_extension")
77121
doxygen_extension.configuration(<a href="#doxygen_extension.configuration-executable">executable</a>, <a href="#doxygen_extension.configuration-platform">platform</a>, <a href="#doxygen_extension.configuration-sha256">sha256</a>, <a href="#doxygen_extension.configuration-version">version</a>)
78-
doxygen_extension.repository()
122+
doxygen_extension.repository(<a href="#doxygen_extension.repository-name">name</a>)
79123
</pre>
80124

81125
Module extension for declaring the doxygen configurations to use.
@@ -84,7 +128,7 @@ The resulting repository will have the following targets:
84128
- `@doxygen//:doxygen.bzl`, containing the doxygen macro used to generate the documentation.
85129
- `@doxygen//:Doxyfile.template`, default Doxyfile template used to generate the Doxyfile.
86130

87-
The extension will create a default configuration for all platforms with the version `1.12.0` of Doxygen.
131+
The extension will create a default configuration for all platforms with the version `1.13.2` of Doxygen.
88132
You can override this value with a custom one for each supported platform, i.e. _windows_, _mac_, _mac-arm_, _linux_ and _linux-arm_.
89133

90134
```bzl
@@ -230,8 +274,8 @@ use_repo(doxygen_extension, "doxygen")
230274

231275
| Name | Description | Type | Mandatory | Default |
232276
| :------------- | :------------- | :------------- | :------------- | :------------- |
233-
| <a id="doxygen_extension.configuration-executable"></a>executable | The doxygen executable to use. If set, no download will take place and the provided doxygen executable will be used. Mutually exclusive with `version`. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
234-
| <a id="doxygen_extension.configuration-platform"></a>platform | The target platform for the doxygen binary. Available options are (windows, mac, mac-arm, linux, linux-arm). If not specified, it will select the platform it is currently running on. | String | optional | `""` |
277+
| <a id="doxygen_extension.configuration-executable"></a>executable | Target pointing to the doxygen executable to use. If set, no download will take place and the provided doxygen executable will be used. Mutually exclusive with `version`. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |
278+
| <a id="doxygen_extension.configuration-platform"></a>platform | The platform this configuration applies to. Available options are (windows, mac, mac-arm, linux, linux-arm). If not specified, the configuration will apply to the platform it is currently running on. | String | optional | `""` |
235279
| <a id="doxygen_extension.configuration-sha256"></a>sha256 | The sha256 hash of the doxygen archive. If not specified, an all-zero hash will be used. | String | optional | `""` |
236280
| <a id="doxygen_extension.configuration-version"></a>version | The version of doxygen to use. If set to `0.0.0`, the doxygen executable will be assumed to be available from the PATH. Mutually exclusive with `executable`. | String | optional | `""` |
237281

@@ -243,5 +287,6 @@ use_repo(doxygen_extension, "doxygen")
243287

244288
| Name | Description | Type | Mandatory | Default |
245289
| :------------- | :------------- | :------------- | :------------- | :------------- |
290+
| <a id="doxygen_extension.repository-name"></a>name | The name of the repository the extension will create. Useful if you don't use 'rules_doxygen' as a dev_dependency, since it will avoid name collision for module depending on yours. Can only be specified once. Defaults to 'doxygen'. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
246291

247292

examples/substitutions/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ make_var_substitution = rule(
8383
)
8484
```
8585
86+
> [!IMPORTANT]
87+
> The `string_keyed_label_dict` attribute is not available in bazel 7.0.0.
88+
> As an alternative, you can use two lists, one for the keys (strings) and one for the values (labels).
89+
8690
Finally, the substitution rule can be used as a toolchain in the doxygen rule.
8791
8892
All configurations using the make variable syntax will be replaced with the values defined in the make_var_substitution rule.

extensions.bzl

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
"""Repository rule for downloading the correct version of doxygen using module extensions."""
22

3-
load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id")
4-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "get_auth")
3+
def get_default_canonical_id(repository_ctx, urls):
4+
"""Returns the default canonical id to use for downloads.
5+
6+
Copied from [@bazel_tools//tools/build_defs/repo:cache.bzl](https://github.com/bazelbuild/bazel/blob/dbb05116a07429ec3524bcf7252cedbb11269bea/tools/build_defs/repo/cache.bzl)
7+
to avoid a dependency on the whole `@bazel_tools` package, since its visibility changed from private to public between Bazel 7.0.0 and 8.0.0.
8+
9+
Returns `""` (empty string) when Bazel is run with
10+
`--repo_env=BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID=0`.
11+
12+
e.g.
13+
```python
14+
load("@bazel_tools//tools/build_defs/repo:cache.bzl", "get_default_canonical_id")
15+
# ...
16+
repository_ctx.download_and_extract(
17+
url = urls,
18+
integrity = integrity
19+
canonical_id = get_default_canonical_id(repository_ctx, urls),
20+
),
21+
```
22+
23+
Args:
24+
repository_ctx: The repository context of the repository rule calling this utility
25+
function.
26+
urls: A list of URLs matching what is passed to `repository_ctx.download` and
27+
`repository_ctx.download_and_extract`.
28+
29+
Returns:
30+
The canonical ID to use for the download, or an empty string if
31+
`BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID` is set to `0`.
32+
"""
33+
DEFAULT_CANONICAL_ID_ENV = "BAZEL_HTTP_RULES_URLS_AS_DEFAULT_CANONICAL_ID"
34+
if repository_ctx.os.environ.get(DEFAULT_CANONICAL_ID_ENV) == "0":
35+
return ""
36+
37+
# Do not sort URLs to prevent the following scenario:
38+
# 1. http_archive with urls = [B, A] created.
39+
# 2. Successful fetch from B results in canonical ID "A B".
40+
# 3. Order of urls is flipped to [A, B].
41+
# 4. Fetch would reuse cache entry for "A B", even though A may be broken (it has never been
42+
# fetched before).
43+
return " ".join(urls)
544

645
def _get_current_platform(ctx):
746
"""
@@ -91,7 +130,6 @@ def _doxygen_repository(ctx):
91130
sha256 = sha256,
92131
type = "zip",
93132
canonical_id = get_default_canonical_id(ctx, [url]),
94-
auth = get_auth(ctx, [url]),
95133
)
96134

97135
# Copy the doxygen executable (and dll) to the repository
@@ -107,7 +145,6 @@ def _doxygen_repository(ctx):
107145
output = download_output,
108146
sha256 = sha256,
109147
canonical_id = get_default_canonical_id(ctx, [url]),
110-
auth = get_auth(ctx, [url]),
111148
)
112149

113150
# Mount the dmg file
@@ -128,7 +165,6 @@ def _doxygen_repository(ctx):
128165
sha256 = sha256,
129166
type = "tar.gz",
130167
canonical_id = get_default_canonical_id(ctx, [url]),
131-
auth = get_auth(ctx, [url]),
132168
stripPrefix = "doxygen-%s" % doxygen_version,
133169
)
134170

@@ -284,11 +320,11 @@ def _doxygen_extension_impl(ctx):
284320
_doxygen_configuration_tag = tag_class(attrs = {
285321
"version": attr.string(doc = "The version of doxygen to use. If set to `0.0.0`, the doxygen executable will be assumed to be available from the PATH. Mutually exclusive with `executable`."),
286322
"sha256": attr.string(doc = "The sha256 hash of the doxygen archive. If not specified, an all-zero hash will be used."),
287-
"platform": attr.string(doc = "The target platform for the doxygen binary. Available options are (windows, mac, mac-arm, linux, linux-arm). If not specified, it will select the platform it is currently running on."),
288-
"executable": attr.label(doc = "The doxygen executable to use. If set, no download will take place and the provided doxygen executable will be used. Mutually exclusive with `version`."),
323+
"platform": attr.string(doc = "The platform this configuration applies to. Available options are (windows, mac, mac-arm, linux, linux-arm). If not specified, the configuration will apply to the platform it is currently running on."),
324+
"executable": attr.label(doc = "Target pointing to the doxygen executable to use. If set, no download will take place and the provided doxygen executable will be used. Mutually exclusive with `version`."),
289325
})
290326
_doxygen_repository_tag = tag_class(attrs = {
291-
"name": attr.string(doc = "The name of the repository the extension will create. Useful if you don't use 'rules_doxygen' as a dev_dependency, since it will avoid name collision for module depending on yours. Must be the same for all configurations. Defaults to 'doxygen'.", mandatory = True),
327+
"name": attr.string(doc = "The name of the repository the extension will create. Useful if you don't use 'rules_doxygen' as a dev_dependency, since it will avoid name collision for module depending on yours. Can only be specified once. Defaults to 'doxygen'.", mandatory = True),
292328
})
293329

294330
doxygen_extension = module_extension(

0 commit comments

Comments
 (0)