Skip to content

Commit 127449e

Browse files
restingbullBencodes
authored andcommitted
[bzlmod] Stop relying on initialize.release.bzl (bazelbuild#1127)
* [bzlmod] Stop relying on initialize.release.bzl * [release] Separate bzlmod dev extensions from release extensions In order to simplify the dependency tree for the rules kotlin bootstrap, bzlmod_setup needed to be separated from the release. The reason for this is twofold: kotlin_repositories in development call kt_configure which configures released_rules_kotlin. Since bzlmod_setup is also used to load released_rules_kotlin this become a dependency cycle. Second, we don't want to load released_rules_koltin in the release module, as it is a development dependency. (whoops.) This also allows dropping a few extra bits of configuration that are unnecessary for the release.
1 parent 0c29c35 commit 127449e

File tree

4 files changed

+74
-47
lines changed

4 files changed

+74
-47
lines changed

src/main/starlark/core/repositories/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ release_archive(
2020
srcs = [
2121
"BUILD.com_github_google_ksp.bazel",
2222
"BUILD.com_github_jetbrains_kotlin.bazel",
23-
"bzlmod_setup.bzl",
23+
"bzlmod_impl.bzl",
2424
"compiler.bzl",
2525
"ksp.bzl",
2626
"versions.bzl",
2727
],
2828
src_map = {
2929
"initialize.release.bzl": "initialize.bzl",
3030
"BUILD.release.bazel": "BUILD.bazel",
31+
"bzlmod_setup.release.bzl": "bzlmod_setup.bzl",
3132
},
3233
deps = [
3334
"//src/main/starlark/core/repositories/kotlin:pkg",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def configure_modules_and_repositories(modules, kotlin_repositories, kotlinc_version, ksp_version):
2+
kotlinc = None
3+
ksp = None
4+
for mod in modules:
5+
for override in mod.tags.kotlinc_version:
6+
if kotlinc:
7+
fail("Only one kotlinc_version is supported right now!")
8+
kotlinc = kotlinc_version(release = override.version, sha256 = override.sha256)
9+
for override in mod.tags.ksp_version:
10+
if ksp:
11+
fail("Only one ksp_version is supported right now!")
12+
ksp = ksp_version(release = override.version, sha256 = override.sha256)
13+
14+
kotlin_repositories_args = dict(is_bzlmod = True)
15+
if kotlinc:
16+
kotlin_repositories_args["compiler_release"] = kotlinc
17+
if ksp:
18+
kotlin_repositories_args["ksp_compiler_release"] = ksp
19+
20+
kotlin_repositories(**kotlin_repositories_args)
21+
22+
_version_tag = tag_class(
23+
attrs = {
24+
"version": attr.string(mandatory = True),
25+
"sha256": attr.string(mandatory = True),
26+
},
27+
)
28+
29+
tag_classes = {
30+
"kotlinc_version": _version_tag,
31+
"ksp_version": _version_tag,
32+
}
Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,22 @@
11
"""Definitions for bzlmod module extensions."""
22

3-
load(
4-
"@bazel_tools//tools/build_defs/repo:http.bzl",
5-
"http_archive",
6-
)
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
74
load(
85
"//src/main/starlark/core/repositories:initialize.release.bzl",
96
_kotlin_repositories = "kotlin_repositories",
107
_kotlinc_version = "kotlinc_version",
118
_ksp_version = "ksp_version",
129
)
13-
load(
14-
"//src/main/starlark/core/repositories:versions.bzl",
15-
_versions = "versions",
16-
)
17-
18-
_version_tag = tag_class(
19-
attrs = {
20-
"version": attr.string(mandatory = True),
21-
"sha256": attr.string(mandatory = True),
22-
},
23-
)
24-
25-
def _extra_repositories():
26-
# This tarball intentionally does not have a SHA256 because the upstream URL can change without notice
27-
# For more context: https://github.com/bazelbuild/bazel-toolchains/blob/0c1f7c3c5f9e63f1e0ee91738b964937eea2d3e0/WORKSPACE#L28-L32
28-
http_archive(
29-
name = "buildkite_config",
30-
urls = _versions.RBE.URLS,
31-
)
10+
load("//src/main/starlark/core/repositories:versions.bzl", _versions = "versions")
11+
load(":bzlmod_impl.bzl", "configure_modules_and_repositories", "tag_classes")
3212

3313
def _rules_kotlin_extensions_impl(mctx):
34-
kotlinc_version = None
35-
ksp_version = None
36-
for mod in mctx.modules:
37-
for override in mod.tags.kotlinc_version:
38-
if kotlinc_version:
39-
fail("Only one kotlinc_version is supported right now!")
40-
kotlinc_version = _kotlinc_version(release = override.version, sha256 = override.sha256)
41-
for override in mod.tags.ksp_version:
42-
if ksp_version:
43-
fail("Only one ksp_version is supported right now!")
44-
ksp_version = _ksp_version(release = override.version, sha256 = override.sha256)
45-
46-
_kotlin_repositories_args = dict(is_bzlmod = True)
47-
if kotlinc_version:
48-
_kotlin_repositories_args["compiler_release"] = kotlinc_version
49-
if ksp_version:
50-
_kotlin_repositories_args["ksp_compiler_release"] = ksp_version
51-
_kotlin_repositories(**_kotlin_repositories_args)
14+
configure_modules_and_repositories(
15+
mctx.modules,
16+
_kotlin_repositories,
17+
_kotlinc_version,
18+
_ksp_version,
19+
)
5220

5321
_versions.use_repository(
5422
name = "released_rules_kotlin",
@@ -63,12 +31,14 @@ def _rules_kotlin_extensions_impl(mctx):
6331
],
6432
)
6533

66-
_extra_repositories()
34+
# This tarball intentionally does not have a SHA256 because the upstream URL can change without notice
35+
# For more context: https://github.com/bazelbuild/bazel-toolchains/blob/0c1f7c3c5f9e63f1e0ee91738b964937eea2d3e0/WORKSPACE#L28-L32
36+
http_archive(
37+
name = "buildkite_config",
38+
urls = _versions.RBE.URLS,
39+
)
6740

6841
rules_kotlin_extensions = module_extension(
6942
implementation = _rules_kotlin_extensions_impl,
70-
tag_classes = {
71-
"kotlinc_version": _version_tag,
72-
"ksp_version": _version_tag,
73-
},
43+
tag_classes = tag_classes,
7444
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
load(
2+
"//src/main/starlark/core/repositories:initialize.bzl",
3+
_kotlin_repositories = "kotlin_repositories",
4+
_kotlinc_version = "kotlinc_version",
5+
_ksp_version = "ksp_version",
6+
)
7+
load(
8+
":bzlmod_impl.bzl",
9+
"configure_modules_and_repositories",
10+
"tag_classes",
11+
)
12+
13+
def _rules_kotlin_extensions_impl(mctx):
14+
configure_modules_and_repositories(
15+
mctx.modules,
16+
_kotlin_repositories,
17+
_kotlinc_version,
18+
_ksp_version,
19+
)
20+
21+
rules_kotlin_extensions = module_extension(
22+
implementation = _rules_kotlin_extensions_impl,
23+
tag_classes = tag_classes,
24+
)

0 commit comments

Comments
 (0)