-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Bzlmod #1006
Add support for Bzlmod #1006
Changes from 19 commits
12e6f03
02ad06e
d6e5d19
781359e
455015a
70cf62c
dfb5464
ea7ad7d
2d07f24
271f22a
627a52b
46fbfa8
a1669bc
636e03d
4975273
721c106
a55ca44
82d139a
5b12b2d
cc2c072
679d6d2
8284083
6f9aeae
fb8d889
ce9fe55
fea5064
55b8bac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module( | ||
name = "io_bazel_rules_kotlin", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you call this just "rules_kotlin"? This is what gets exported to BCR: https://github.com/bazelbuild/bazel-central-registry/tree/main/modules So "io_bazel_" prefix would be a precedent. "repo_name = " attribute controls how this can be used, that is what you need in the |
||
version = "1.8.1", | ||
compatibility_level = 1, | ||
repo_name = "io_bazel_rules_kotlin", | ||
) | ||
|
||
bazel_dep(name = "platforms", version = "0.0.6") | ||
bazel_dep(name = "bazel_skylib", version = "1.3.0") | ||
bazel_dep(name = "rules_java", version = "6.4.0") | ||
bazel_dep(name = "rules_python", version = "0.24.0") | ||
bazel_dep(name = "rules_cc", version = "0.0.8") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
rules_kotlin_extensions = use_extension("//src/main/starlark/core/repositories:bzlmod_setup.bzl", "rules_kotlin_extensions") | ||
use_repo( | ||
rules_kotlin_extensions, | ||
"build_bazel_rules_android", | ||
"buildkite_config", | ||
"com_github_google_ksp", | ||
"com_github_jetbrains_kotlin", | ||
"com_github_pinterest_ktlint", | ||
"kt_java_stub_template", | ||
) | ||
|
||
register_toolchains("//kotlin/internal:default_toolchain") | ||
|
||
# Development dependencies | ||
|
||
bazel_dep(name = "rules_jvm_external", version = "4.4.2") | ||
|
||
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") | ||
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.1", | ||
"com.google.auto.service:auto-service-annotations:1.0.1", | ||
"com.google.auto.value:auto-value:1.10.1", | ||
"com.google.auto.value:auto-value-annotations:1.10.1", | ||
"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", version = "0.7.0") | ||
bazel_dep(name = "stardoc", version = "0.5.6", repo_name = "io_bazel_stardoc") | ||
bazel_dep(name = "rules_proto", version = "5.3.0-21.7") | ||
|
||
register_toolchains("@io_bazel_rules_kotlin//kotlin/internal:default_toolchain") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module(name = "trival-example") | ||
|
||
bazel_dep(name = "rules_java", version = "6.4.0") | ||
bazel_dep(name = "io_bazel_rules_kotlin") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
local_path_override( | ||
module_name = "io_bazel_rules_kotlin", | ||
path = "../..", | ||
) | ||
|
||
bazel_dep(name = "rules_jvm_external", version = "4.4.2") | ||
|
||
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") | ||
maven.install( | ||
artifacts = [ | ||
"com.expedia:graphql-kotlin:1.0.0-RC5", | ||
"com.expedia:graphql-kotlin-schema-generator:1.0.0-RC5", | ||
"com.expedia:graphql-kotlin-federation:1.0.0-RC5", | ||
"com.graphql-java:graphql-java:13.0", | ||
"org.opentest4j:opentest4j:1.1.1", | ||
"org.apiguardian:apiguardian-api:1.0.0", | ||
"org.junit.platform:junit-platform-commons:1.4.2", | ||
"org.junit.jupiter:junit-jupiter-api:5.4.2", | ||
"org.junit.jupiter:junit-jupiter-params:5.4.2", | ||
"org.apache.logging.log4j:log4j-core:2.16.0", | ||
], | ||
repositories = [ | ||
"https://maven-central.storage.googleapis.com/repos/central/data/", | ||
"https://repo1.maven.org/maven2", | ||
], | ||
) | ||
use_repo(maven, "maven") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"""Definitions for bzlmod module extensions.""" | ||
|
||
load( | ||
"@bazel_tools//tools/build_defs/repo:http.bzl", | ||
"http_archive", | ||
) | ||
load( | ||
"//src/main/starlark/core/repositories:initialize.bzl", | ||
_kotlin_repositories = "kotlin_repositories", | ||
_kotlinc_version = "kotlinc_version", | ||
_ksp_version = "ksp_version", | ||
) | ||
load( | ||
"//src/main/starlark/core/repositories:versions.bzl", | ||
_versions = "versions", | ||
) | ||
|
||
_kotlinc_version_tag = tag_class( | ||
attrs = { | ||
"version": attr.string( | ||
mandatory = True, | ||
default = _versions.KOTLIN_CURRENT_COMPILER_RELEASE.version, | ||
), | ||
"sha256": attr.string( | ||
mandatory = True, | ||
default = _versions.KOTLIN_CURRENT_COMPILER_RELEASE.sha256, | ||
), | ||
}, | ||
) | ||
|
||
_ksp_version_tag = tag_class( | ||
attrs = { | ||
"version": attr.string( | ||
mandatory = True, | ||
default = _versions.KSP_CURRENT_COMPILER_PLUGIN_RELEASE.version, | ||
), | ||
"sha256": attr.string( | ||
mandatory = True, | ||
default = _versions.KSP_CURRENT_COMPILER_PLUGIN_RELEASE.sha256, | ||
), | ||
}, | ||
) | ||
|
||
def _extra_repositories(): | ||
# TODO(bencodes) This really needs to be a development dependency | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left a TODO here to move this out into a development dependency. I'll do another pass once this is merged to get these dependencies into better shape so that we can do a production-ready release of rules_kotlin. |
||
# This tarball intentionally does not have a SHA256 because the upstream URL can change without notice | ||
# For more context: https://github.com/bazelbuild/bazel-toolchains/blob/0c1f7c3c5f9e63f1e0ee91738b964937eea2d3e0/WORKSPACE#L28-L32 | ||
http_archive( | ||
name = "buildkite_config", | ||
urls = _versions.RBE.URLS, | ||
) | ||
|
||
def _rules_kotlin_extensions_impl(mctx): | ||
kotlinc_version = None | ||
ksp_version = None | ||
for mod in mctx.modules: | ||
for override in mod.tags.kotlinc_version: | ||
if kotlinc_version: | ||
fail("Only one kotlinc_version is supported right now!") | ||
kotlinc_version = _kotlinc_version(release = override.version, sha256 = override.sha256) | ||
for override in mod.tags.ksp_version: | ||
if ksp_version: | ||
fail("Only one ksp_version is supported right now!") | ||
ksp_version = _ksp_version(release = override.version, sha256 = override.sha256) | ||
|
||
_kotlin_repositories_args = dict(bzlmod = True) | ||
if kotlinc_version: | ||
_kotlin_repositories_args["compiler_release"] = kotlinc_version | ||
if ksp_version: | ||
_kotlin_repositories_args["ksp_compiler_release"] = ksp_version | ||
_kotlin_repositories(**_kotlin_repositories_args) | ||
|
||
_extra_repositories() | ||
|
||
rules_kotlin_extensions = module_extension( | ||
implementation = _rules_kotlin_extensions_impl, | ||
tag_classes = { | ||
"kotlinc_version": _kotlinc_version_tag, | ||
"ksp_version": _ksp_version_tag, | ||
}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling Bzlmod by default for
rules_kotlin