Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Bencodes committed Sep 8, 2023
1 parent 8d79e6a commit 12e6f03
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ buildifier:
warnings: "-confusing-name,-constant-glob,-duplicated-name,-function-docstring,-function-docstring-args,-function-docstring-header,-module-docstring,-name-conventions,-no-effect,-constant-glob,-provider-params,-print,-rule-impl-return,-bzl-visibility,-unnamed-macro,-uninitialized,-unreachable"
tasks:
ubuntu1804:
build_flags:
- "--enable_bzlmod=false"
test_targets:
- "//:all_tests"
build_targets:
- "//:rules_kotlin_release"
macos:
test_flags:
- "--enable_bzlmod=false"
test_targets:
- "//:all_tests"
ubuntu2004_bzlmod:
platform: ubuntu2004
build_flags:
- "--enable_bzlmod"
test_targets:
- "//:all_tests"
build_targets:
Expand Down
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
common --enable_bzlmod=true

build --strategy=KotlinCompile=worker
build --test_output=all
build --verbose_failures
Expand Down
61 changes: 61 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module(
name = "rules_kotlin",
version = "1.8.0",
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_android", version = "0.1.1", repo_name = "build_bazel_rules_android")
bazel_dep(name = "rules_python", version = "0.24.0")

kt = use_extension("//src/main/starlark/core/repositories:bzlmod_setup.bzl", "kt_bzlmod_ext")
use_repo(kt, "com_github_google_ksp", "com_github_jetbrains_kotlin", "com_github_pinterest_ktlint", "kt_java_stub_template", "buildkite_config")

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", version = "0.7.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.5.3", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7", dev_dependency = True)
Empty file added WORKSPACE.bzlmod
Empty file.
34 changes: 34 additions & 0 deletions examples/trivial/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module(
name = "trival-example",
)

bazel_dep(name = "rules_java", version = "6.4.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")
Empty file.
66 changes: 66 additions & 0 deletions src/main/starlark/core/repositories/bzlmod_setup.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# 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(":ksp.bzl", "ksp_compiler_plugin_repository")
load(":versions.bzl", "versions")
load("//kotlin/internal:defs.bzl", _KSP_COMPILER_PLUGIN_REPO = "KSP_COMPILER_PLUGIN_REPO", _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,
)

ksp_repository_name = _KSP_COMPILER_PLUGIN_REPO
ksp_compiler_release = versions.KSP_CURRENT_COMPILER_PLUGIN_RELEASE
ksp_compiler_plugin_repository(
name = ksp_repository_name,
urls = [url.format(version = ksp_compiler_release.version) for url in ksp_compiler_release.url_templates],
sha256 = ksp_compiler_release.sha256,
strip_version = ksp_compiler_release.version,
)

http_file(
name = "kt_java_stub_template",
urls = [("https://raw.githubusercontent.com/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,
)

# 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_file(
name = "buildkite_config",
urls = versions.RBE.URLS,
)

kt_bzlmod_ext = module_extension(
implementation = _kt_configure_impl,
)

0 comments on commit 12e6f03

Please sign in to comment.