Skip to content

Commit

Permalink
Merge pull request #74 from lucidsoftware/bzlmod-migration
Browse files Browse the repository at this point in the history
Migrate to Bzlmod
  • Loading branch information
jadenPete authored Dec 6, 2024
2 parents ceef5c1 + 5de9438 commit d9e701d
Show file tree
Hide file tree
Showing 80 changed files with 3,146 additions and 2,452 deletions.
1 change: 1 addition & 0 deletions .bazelrc_shared
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ test --test_output=all

common:rules --disk_cache=.bazel_cache
common:tests --disk_cache=../.bazel_cache
common:tests --@rules_scala_annex//rules/scala:scala-toolchain=test_zinc_2_13
12 changes: 4 additions & 8 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load(
"@rules_java//toolchains:default_java_toolchain.bzl",
"DEFAULT_TOOLCHAIN_CONFIGURATION",
"default_java_toolchain",
)
load("//rules/scalafmt:register_toolchain.bzl", "register_scalafmt_toolchain")

default_java_toolchain(
name = "repository_default_toolchain_21",
Expand All @@ -14,11 +14,7 @@ default_java_toolchain(
target_version = "21",
)

buildifier(
name = "buildifier",
)

buildifier(
name = "buildifier_check",
mode = "check",
register_scalafmt_toolchain(
name = "annex_scalafmt",
config = ".scalafmt.conf",
)
29 changes: 17 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,32 @@ $ ./scripts/format.sh

## Maven deps

[rules_jvm_external](https://github.com/bazel-contrib/rules_jvm_external) is used to generate maven deps. If you need to change
dependencies, modify `maven_install` in the following different `workspace.bzl` files
[rules_jvm_external](https://github.com/bazel-contrib/rules_jvm_external) is used to resolve Maven
dependencies. If you need to change dependencies, add your artifacts to the `annex*.install` calls
in [`MODULE.bazel`](MODULE.bazel) or [`tests/MODULE.bazel`](tests/MODULE.bazel).

```
rules/scala/workspace.bzl
rules/scala_proto/workspace.bzl
rules/scalafmt/workspace.bzl
tests/workspace.bzl
```
To reference the dependency, use the `name` attribute of the `maven_install` rule as the repository name and the versionless dependency as the target. E.g. `@<maven_install_name>//:<versionless_dependency>`.
To reference the dependency, use the `name` attribute of the `annex*.install` call as the
repository name and the versionless dependency as the target. E.g.
`@<maven_install_name>//:<versionless_dependency>`.

For example, if you'd like to add `org.scala-sbt:compiler-interface:1.2.1` as a dependency, simply add it to the `artifacts` list in `maven_install` with the attribute `name = "annex"`, and then refer to it with `@annex//:org_scala_sbt_compiler_interface`.
For example, if you'd like to add `org.scala-sbt:compiler-interface:1.2.1` as a dependency, simply
add it to the `artifacts` list of the `maven.install` call, and then refer to it with
`@annex//:org_scala_sbt_compiler_interface`.

```
maven_install(
```starlark
annex.install(
name = "annex",
artifacts = [
...,
"org.scala-sbt:compiler-interface:1.2.1",
...,
],
fetch_sources = True,
lock_file = "//:annex_install.json",
repositories = [
"https://repo.maven.apache.org/maven2",
"https://maven-central.storage-download.googleapis.com/maven2",
"https://mirror.bazel.build/repo1.maven.org/maven2",
],
)
```
Expand Down
153 changes: 147 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,147 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
module(name = "rules_scala_annex")

bazel_dep(name = "bazel_skylib", version = "1.7.1")

bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)

bazel_dep(name = "rules_java", version = "7.12.2")
bazel_dep(name = "rules_jvm_external", version = "6.5")

bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.7.1", dev_dependency = True)

register_toolchains(
"//:annex_scalafmt",
"//:repository_default_toolchain_21_definition",
"//rules/scala_proto:scalapb_scala_proto_toolchain",
"//src/main/scala:annex_bootstrap_2_13",
"//src/main/scala:annex_bootstrap_3",
"//src/main/scala:annex_zinc_2_13",
"//src/main/scala:annex_zinc_3",
)

# Please ensure these stay up-to-date with the versions in `/rules/scala/versions.bzl`,
# `/tests/MODULE.bazel`, and `/MODULE.bazel`. Unfortunately, `MODULE.bazel` files can't call `load`,
# so we have to copy them here.
scala_2_12_version = "2.12.19"

scala_2_13_version = "2.13.15"

scala_3_version = "3.5.2"

scalapb_version = "0.11.17"

zinc_version = "1.10.4"

annex = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
annex.install(
name = "annex",
artifacts = [
"ch.epfl.scala:bloop-frontend_2.12:1.0.0",
"com.thesamet.scalapb:lenses_2.13:{}".format(scalapb_version),
"com.thesamet.scalapb:scalapb-runtime_2.13:{}".format(scalapb_version),
"net.sourceforge.argparse4j:argparse4j:0.8.1",
"org.jacoco:org.jacoco.core:0.7.5.201505241946",
"org.scala-lang:scala-compiler:{}".format(scala_2_13_version),
"org.scala-lang:scala-library:{}".format(scala_2_13_version),
"org.scala-lang:scala-reflect:{}".format(scala_2_13_version),
"org.scala-lang:scala3-compiler_3:{}".format(scala_3_version),
"org.scala-lang:scala3-library_3:{}".format(scala_3_version),
"org.scala-sbt:compiler-interface:{}".format(zinc_version),
"org.scala-sbt:io_2.13:1.10.1",
"org.scala-sbt:test-interface:1.0",
"org.scala-sbt:util-interface:{}".format(zinc_version),
"org.scala-sbt:util-logging_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-apiinfo_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-classpath_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-compile-core_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-core_2.13:{}".format(zinc_version),
"org.scala-sbt:zinc-persist_2.13:{}".format(zinc_version),
],
fetch_sources = True,
lock_file = "//:annex_install.json",
repositories = [
"https://repo.maven.apache.org/maven2",
"https://maven-central.storage-download.googleapis.com/maven2",
"https://mirror.bazel.build/repo1.maven.org/maven2",
],
)

# The compiler bridge has a dependency on compiler-interface, which has a dependency on the Scala 2
# library. We need to set this to neverlink = True to avoid this the Scala 2 library being pulled
# onto the Scala 3, and other Scala versions like 2.12, compiler classpath during runtime.
annex.artifact(
name = "annex",
artifact = "scala3-sbt-bridge",
group = "org.scala-lang",
neverlink = True,
version = scala_3_version,
)

# The compiler bridge has a dependency on compiler-interface, which has a dependency on the Scala 2
# library. We need to set this to neverlink = True to avoid this the Scala 2 library being pulled
# onto the Scala 3, and other Scala versions like 2.12, compiler classpath during runtime.
annex.artifact(
name = "annex",
artifact = "compiler-bridge_2.13",
group = "org.scala-sbt",
neverlink = True,
version = zinc_version,
)
use_repo(annex, "annex")

annex_scalafmt = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
annex_scalafmt.install(
name = "annex_scalafmt",
artifacts = [
"org.scalameta:parsers_2.13:4.9.7",
"org.scalameta:metaconfig-core_2.13:0.13.0",
"org.scalameta:scalafmt-core_2.13:3.8.2",
],
fetch_sources = True,
lock_file = "//:annex_scalafmt_install.json",
repositories = [
"https://repo.maven.apache.org/maven2",
"https://maven-central.storage-download.googleapis.com/maven2",
"https://mirror.bazel.build/repo1.maven.org/maven2",
],
)
use_repo(annex_scalafmt, "annex_scalafmt")

annex_proto = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
annex_proto.install(
name = "annex_proto",
artifacts = [
"com.github.os72:protoc-jar:3.11.4",
"com.thesamet.scalapb:compilerplugin_2.13:0.11.17",
"com.thesamet.scalapb:protoc-bridge_2.13:0.9.7",
],
fetch_sources = True,
lock_file = "//:annex_proto_install.json",
repositories = [
"https://repo.maven.apache.org/maven2",
"https://maven-central.storage-download.googleapis.com/maven2",
"https://mirror.bazel.build/repo1.maven.org/maven2",
],
)
use_repo(annex_proto, "annex_proto")

java_launcher_version = "7.4.1"

java_launcher_template_sha = "ee4aa47ae5e639632c67be5cc0ccbc4e941a67a1b884a1ce0c4329357a4b62b2"

java_stub_template_url = (
"raw.githubusercontent.com/bazelbuild/bazel/" +
java_launcher_version +
"/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" +
"java_stub_template.txt"
)

http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")

http_file(
name = "anx_java_stub_template",
sha256 = java_launcher_template_sha,
urls = ["https://%s" % java_stub_template_url],
)
Loading

0 comments on commit d9e701d

Please sign in to comment.