Skip to content
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

Support bzlmod #902

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ tasks:
macos:
test_targets:
- "//:all_tests"
ubuntu2004_bzlmod:
bazel: last_green
platform: ubuntu2004
build_flags:
- "--enable_bzlmod"
test_targets:
- "//:all_tests"
build_targets:
- "//:rules_kotlin_release"
example-android:
name: "Example - Android"
platform: ubuntu1804
Expand Down
16 changes: 4 additions & 12 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("//src/main/starlark/release:packager.bzl", "release_archive")
load("//src/main/starlark/core/repositories:versions.bzl", "versions")
load("//kotlin:lint.bzl", "ktlint_config")

exports_files([
Expand Down Expand Up @@ -52,20 +51,13 @@ test_suite(
],
)

[
release_archive(
name = version,
deps = [
"@%s//:pkg" % version,
],
)
for version in versions.CORE
]

# Release target.
release_archive(
name = "rules_kotlin_release",
srcs = ["%s.tgz" % v for v in versions.CORE],
srcs = [
"MODULE.bazel",
"WORKSPACE.bzlmod",
],
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
"WORKSPACE.release.bazel": "WORKSPACE",
Expand Down
12 changes: 0 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ The `rules_kotlin` runtime is comprised of multiple repositories. The end user w
versioned feature sub-repositories. Currently, the delegation is managed by using well known names (e.g. core lives in `@io_bazel_rules_kotlin_configured`),
a necessity while the initial repository can be named arbitrarily. Future development intends to remove this restriction.

### Versioning

To cope with API churn, the release archive can configure different rule attributes for depending on the chosen kotlin version.
Each major release of kotlin (1.4, 1.5) has a specific sub-repository under [src/main/starlark](src/main/starlark). The naming convention for these
is `rkt_<major>_<minor>` ([r]elease [k]o[t]lin).

The version is selected by the [kotlin_repositories](src/main/starlark/repositories/initialize.release.bzl) rule during initialization.
New versions of kotlin that change the API should be added to [versions.bzl](src/main/starlark/repositories/versions.bzl), under `CORE` following the
existing naming convention.

Multiple versions of kotlin are not currently handled.(_help wanted_)

## Idioms and Styles
TBD

Expand Down
66 changes: 66 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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")


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ kt_compiler_plugin(
"annotation": "plugin.allopen.OpenForTesting",
},
deps = [
"@com_github_jetbrains_kotlin//:allopen-compiler-plugin",
"@rules_kotlin//kotlin/compiler:allopen-compiler-plugin",
],
)

Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-associat

**Notes:**
* The kotlin test library is not added implicitly, it is available with the label
`@com_github_jetbrains_kotlin//:kotlin-test`.
`@rules_kotlin//kotlin/compiler:kotlin-test`.


**ATTRIBUTES**
Expand Down Expand Up @@ -330,7 +330,7 @@ kt_compiler_plugin(<a href="#kt_compiler_plugin-name">name</a>, <a href="#kt_com
"annotation": "plugin.OpenForTesting",
},
deps = [
"@com_github_jetbrains_kotlin//:allopen-compiler-plugin",
"@rules_kotlin//kotlin/compiler:allopen-compiler-plugin",
],
)

Expand Down Expand Up @@ -485,7 +485,7 @@ This macro registers the kotlin toolchain.
## kotlin_repositories

<pre>
kotlin_repositories(<a href="#kotlin_repositories-compiler_repository_name">compiler_repository_name</a>, <a href="#kotlin_repositories-compiler_release">compiler_release</a>, <a href="#kotlin_repositories-configured_repository_name">configured_repository_name</a>)
kotlin_repositories(<a href="#kotlin_repositories-compiler_repository_name">compiler_repository_name</a>, <a href="#kotlin_repositories-compiler_release">compiler_release</a>)
</pre>

Call this in the WORKSPACE file to setup the Kotlin rules.
Expand All @@ -497,6 +497,5 @@ Call this in the WORKSPACE file to setup the Kotlin rules.
| :------------- | :------------- | :------------- |
| <a id="kotlin_repositories-compiler_repository_name"></a>compiler_repository_name | for the kotlinc compiler repository. | <code>"com_github_jetbrains_kotlin"</code> |
| <a id="kotlin_repositories-compiler_release"></a>compiler_release | version provider from versions.bzl. | <code>struct()</code> |
| <a id="kotlin_repositories-configured_repository_name"></a>configured_repository_name | for the default versioned kt_* rules repository. If None, no versioned repository is created. | <code>"io_bazel_rules_kotlin_configured"</code> |


2 changes: 1 addition & 1 deletion examples/android/libKtAndroid/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kt_compiler_plugin(
id = "org.jetbrains.kotlin.serialization",
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:kotlinx-serialization-compiler-plugin",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/src/allopen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kt_compiler_plugin(
},
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:allopen-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:allopen-compiler-plugin",
],
)

Expand Down
6 changes: 3 additions & 3 deletions examples/plugin/src/allopennoarg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kt_compiler_plugin(
},
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:allopen-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:allopen-compiler-plugin",
],
)

Expand All @@ -23,7 +23,7 @@ kt_compiler_plugin(
},
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:noarg-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:noarg-compiler-plugin",
],
)

Expand Down Expand Up @@ -64,7 +64,7 @@ kt_jvm_test(
test_class = "plugin.allopennoarg.UserHasNoargConstructorTest",
deps = [
":user",
"@com_github_jetbrains_kotlin//:kotlin-reflect",
"@io_bazel_rules_kotlin//kotlin/compiler:kotlin-reflect",
"@maven//:junit_junit",
],
)
4 changes: 2 additions & 2 deletions examples/plugin/src/noarg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kt_compiler_plugin(
},
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:noarg-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:noarg-compiler-plugin",
],
)

Expand All @@ -35,7 +35,7 @@ kt_jvm_test(
test_class = "plugin.noarg.UserHasNoargConstructorTest",
deps = [
":user",
"@com_github_jetbrains_kotlin//:kotlin-reflect",
"@io_bazel_rules_kotlin//kotlin/compiler:kotlin-reflect",
"@maven//:junit_junit",
],
)
4 changes: 2 additions & 2 deletions examples/plugin/src/parcelize/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kt_compiler_plugin(
id = "org.jetbrains.kotlin.parcelize",
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:parcelize-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:parcelize-compiler-plugin",
],
)

Expand All @@ -21,7 +21,7 @@ kt_jvm_library(
],
visibility = ["//visibility:public"],
exports = [
"@com_github_jetbrains_kotlin//:parcelize-runtime",
"@io_bazel_rules_kotlin//kotlin/compiler:parcelize-runtime",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/src/sam_with_receiver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ kt_compiler_plugin(
},
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:sam-with-receiver-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:sam-with-receiver-compiler-plugin",
],
)

Expand Down
2 changes: 1 addition & 1 deletion examples/plugin/src/serialization/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ kt_compiler_plugin(
id = "org.jetbrains.kotlin.serialization",
stubs_phase = True,
deps = [
"@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin",
"@io_bazel_rules_kotlin//kotlin/compiler:kotlinx-serialization-compiler-plugin",
],
)

Expand Down
32 changes: 32 additions & 0 deletions examples/trivial/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module(
name = "trival-example"
)

bazel_dep(name = "rules_java", version = "5.1.0")

bazel_dep(name = "rules_kotlin", repo_name = "io_bazel_rules_kotlin")
archive_override(module_name = "rules_kotlin", urls = ["file:../../bazel-bin/rules_kotlin_release.tgz"])
#local_path_override(module_name = "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")

1 change: 1 addition & 0 deletions kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ release_archive(
"BUILD.release.bazel": "BUILD.bazel",
},
deps = [
"//kotlin/compiler:pkg",
"//kotlin/internal:pkg",
],
)
Expand Down
28 changes: 28 additions & 0 deletions kotlin/compiler/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2020 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", "kt_configure_compiler")
load("//src/main/starlark/release:packager.bzl", "release_archive")

package(default_visibility = ["//visibility:public"])

# Configures the compiler
kt_configure_compiler()

release_archive(
name = "pkg",
srcs = glob(["*.bzl"]),
src_map = {
"BUILD.release.bazel": "BUILD.bazel",
},
)
19 changes: 19 additions & 0 deletions kotlin/compiler/BUILD.release.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2020 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", "kt_configure_compiler")

package(default_visibility = ["//visibility:public"])

# Configures the compiler
kt_configure_compiler()
Loading