Skip to content

Commit 35fd488

Browse files
committed
WIP: Bzlmod part the one hundred twenty-second
Fixes up more merge errors from before, removes the `kwargs.pop` pattern from the previous commit, and updates dt_patches repos for Bzlmod. Regarding the latter, I extracted the dt_patches/compiler_sources repo from the other two repos to eliminate the duplication. I also had to ensure the module extension emitted the same artifact repos for every Scala version, since `MODULE.bazel` can't use conditional logic. It must include every repo explicitly.
1 parent 823b3ce commit 35fd488

File tree

29 files changed

+10344
-5503
lines changed

29 files changed

+10344
-5503
lines changed

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ use_repo(
9090
dev_deps,
9191
"scala_proto_rules_scalapb_compilerplugin",
9292
"scala_proto_rules_scalapb_protoc_bridge",
93+
"scala_proto_rules_scalapb_protoc_gen", # For Scala 2.12 and above
9394
"scalafmt_default",
9495
)
9596

MODULE.bazel.lock

Lines changed: 1391 additions & 1391 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dt_patches/compiler_sources/.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import ../../.bazelrc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.4.0

dt_patches/compiler_sources/BUILD

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Bazel module ./test/shell/test_examples.sh tests"""
2+
3+
module(name = "compiler_sources")
4+
5+
bazel_dep(name = "rules_scala", repo_name = "io_bazel_rules_scala")
6+
local_path_override(
7+
module_name = "rules_scala",
8+
path = "../..",
9+
)
10+
11+
scala_config = use_extension(
12+
"@io_bazel_rules_scala//scala/extensions:config.bzl",
13+
"scala_config",
14+
)
15+
use_repo(scala_config, "io_bazel_rules_scala_config")
16+

dt_patches/compiler_sources/WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workspace(name = "compiler_sources")
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
load(
2+
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
3+
"default_maven_server_urls",
4+
)
5+
load(
6+
"@io_bazel_rules_scala//scala:scala_maven_import_external.bzl",
7+
"scala_maven_import_external",
8+
)
9+
load(
10+
"@io_bazel_rules_scala//third_party/repositories:scala_2_13.bzl",
11+
_scala_2_version = "scala_version",
12+
)
13+
load(
14+
"@io_bazel_rules_scala//third_party/repositories:scala_3_5.bzl",
15+
_scala_3_version = "scala_version",
16+
)
17+
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")
18+
19+
_IS_SCALA_2 = SCALA_VERSION.startswith("2.")
20+
_IS_SCALA_3 = SCALA_VERSION.startswith("3.")
21+
22+
_SCALA_2_VERSION = SCALA_VERSION if _IS_SCALA_2 else _scala_2_version
23+
_SCALA_3_VERSION = SCALA_VERSION if _IS_SCALA_3 else _scala_3_version
24+
25+
_SCALA_VERSION_ARTIFACTS = {
26+
"scala_compiler": "org.scala-lang:scala3-compiler_3:",
27+
"scala_library": "org.scala-lang:scala3-library_3:",
28+
} if _IS_SCALA_3 else {
29+
"scala_compiler": "org.scala-lang:scala-compiler:",
30+
"scala_library": "org.scala-lang:scala-library:",
31+
}
32+
33+
_SCALA_2_ARTIFACTS = {
34+
"scala_reflect": "org.scala-lang:scala-reflect:",
35+
"scala2_library": "org.scala-lang:scala-library:",
36+
}
37+
38+
_SCALA_3_ARTIFACTS = {
39+
"scala3_interfaces": "org.scala-lang:scala3-interfaces:",
40+
"tasty_core": "org.scala-lang:tasty-core_3:",
41+
}
42+
43+
def versioned_artifacts(scala_version, artifacts):
44+
return {k: v + scala_version for k, v in artifacts.items()}
45+
46+
COMPILER_SOURCES_ARTIFACTS = (
47+
versioned_artifacts(SCALA_VERSION, _SCALA_VERSION_ARTIFACTS) |
48+
versioned_artifacts(_SCALA_2_VERSION, _SCALA_2_ARTIFACTS) |
49+
versioned_artifacts(_SCALA_3_VERSION, _SCALA_3_ARTIFACTS) |
50+
{
51+
"sbt_compiler_interface": "org.scala-sbt:compiler-interface:1.9.6",
52+
"scala_asm": "org.scala-lang.modules:scala-asm:9.7.0-scala-2",
53+
}
54+
)
55+
56+
def import_compiler_source_repos():
57+
for name, artifact in COMPILER_SOURCES_ARTIFACTS.items():
58+
scala_maven_import_external(
59+
name = name,
60+
artifact = artifact,
61+
licenses = ["notice"],
62+
server_urls = default_maven_server_urls(),
63+
)
64+
65+
def _compiler_source_repos_impl(_ctx):
66+
import_compiler_source_repos()
67+
68+
compiler_source_repos = module_extension(
69+
implementation = _compiler_source_repos_impl,
70+
)

dt_patches/test_dt_patches/MODULE.bazel

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
module(name = "scala3_example")
44

5-
source_repos = use_extension("//:extensions.bzl", "compiler_source_repos")
6-
use_repo(
7-
source_repos,
8-
"scala_compiler",
9-
"scala_library",
10-
"scala_reflect",
11-
)
12-
135
bazel_dep(name = "rules_scala", repo_name = "io_bazel_rules_scala")
146
local_path_override(
157
module_name = "rules_scala",
@@ -25,6 +17,32 @@ scala_config.settings(
2517
)
2618
use_repo(scala_config, "io_bazel_rules_scala_config")
2719

20+
bazel_dep(name = "compiler_sources")
21+
local_path_override(
22+
module_name = "compiler_sources",
23+
path = "../compiler_sources",
24+
)
25+
26+
source_repos = use_extension(
27+
"@compiler_sources//:extensions.bzl",
28+
"compiler_source_repos",
29+
)
30+
use_repo(
31+
source_repos,
32+
# Configured for the current Scala version
33+
"scala_compiler",
34+
"scala_library",
35+
# Scala 2 specific
36+
"scala_reflect",
37+
# Scala 3 specific
38+
"scala3_interfaces",
39+
"tasty_core",
40+
# Hardcoded versions
41+
"sbt_compiler_interface",
42+
"scala2_library",
43+
"scala_asm",
44+
)
45+
2846
scala_deps = use_extension(
2947
"@io_bazel_rules_scala//scala/extensions:deps.bzl",
3048
"scala_deps",

0 commit comments

Comments
 (0)