Skip to content

#641 Upgrade deps/Kotlin/JVM/C++/Bazel/bzlmod. #640

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bzl-examples/
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.2
7.6.1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ build
local.properties
*.iml
/bazel-*
MODULE.bazel.lock
*/bin/*
34 changes: 34 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module(
name = "com_github_grpc_grpc_kotlin",
version = "2.1.0",
)

bazel_dep(name = "protobuf", repo_name = "com_google_protobuf", version = "30.2")
bazel_dep(name = "rules_kotlin", repo_name = "io_bazel_rules_kotlin", version = "2.1.3")
bazel_dep(name = "rules_java", version = "8.11.0")
bazel_dep(name = "rules_jvm_external", version = "6.7")
bazel_dep(name = "grpc-java", repo_name = "io_grpc_grpc_java", version = "1.71.0")

grpc_kotlin_maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
grpc_kotlin_maven.install(
name = "grpc_kotlin_maven",
# Rerun whenever adding new artifacts.
# $ REPIN=1 bazelisk run @grpc_kotlin_maven//:pin
artifacts = [
"com.google.jimfs:jimfs:1.3.0",
"com.google.truth:truth:1.4.2",
"com.google.truth.extensions:truth-proto-extension:1.4.2",
"com.google.protobuf:protobuf-java:4.30.2",
"com.google.protobuf:protobuf-kotlin:4.30.2",
"com.google.guava:guava:33.3.1-android",
"com.squareup:kotlinpoet:1.14.2",
"junit:junit:4.13.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1",
"org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.10.1",
],
fetch_sources = False,
lock_file = "//:grpc_kotlin_maven_install.json",
generate_compat_repositories = True,
strict_visibility = True,
)
use_repo(grpc_kotlin_maven, "grpc_kotlin_maven")
70 changes: 0 additions & 70 deletions WORKSPACE

This file was deleted.

6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ subprojects {
version = rootProject.version

tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
sourceCompatibility = JavaVersion.VERSION_17.toString()
targetCompatibility = JavaVersion.VERSION_17.toString()
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

Expand Down
1 change: 1 addition & 0 deletions bzl-examples/bzlmod/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
1 change: 1 addition & 0 deletions bzl-examples/bzlmod/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.6.1
2 changes: 2 additions & 0 deletions bzl-examples/bzlmod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bazel-*
MODULE.bazel.lock
16 changes: 16 additions & 0 deletions bzl-examples/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@aspect_rules_lint//format:defs.bzl", "format_multirun")
load("@rules_java//java:defs.bzl", "java_binary")

java_binary(
name = "ktfmt",
main_class = "com.facebook.ktfmt.cli.Main",
runtime_deps = ["@ktfmt//jar"],
)

format_multirun(
name = "format",
kotlin = ":ktfmt",
protocol_buffer = "@rules_buf_toolchains//:buf",
starlark = "@buildifier_prebuilt//:buildifier",
visibility = ["//visibility:public"],
)
41 changes: 41 additions & 0 deletions bzl-examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module(
name = "bzlmod",
version = "1.0",
)

bazel_dep(name = "protobuf", version = "30.2")
bazel_dep(name = "rules_kotlin", version = "2.1.3")
bazel_dep(name = "com_github_grpc_grpc_kotlin", version = "0.0.0")
bazel_dep(name = "rules_jvm_external", version = "6.7")
bazel_dep(name = "aspect_rules_lint", version = "1.3.4")
bazel_dep(name = "rules_java", version = "8.11.0")
bazel_dep(name = "buildifier_prebuilt", version = "8.0.3")
bazel_dep(name = "rules_buf", version = "0.3.0")

local_path_override(
module_name = "com_github_grpc_grpc_kotlin",
path = "../../",
)

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
# Rerun whenever adding new artifacts.
# $ REPIN=1 bazelisk run @maven//:pin
artifacts = [
"com.google.truth:truth:1.4.2",
"junit:junit:4.13.2",
"com.google.truth.extensions:truth-proto-extension:1.4.4",
"io.grpc:grpc-testing:1.71.0",
],
fetch_sources = False,
generate_compat_repositories = True,
lock_file = "//:maven_install.json",
strict_visibility = True,
)
use_repo(maven, "maven", "grpc_kotlin_maven")

install_ktfmt = use_extension("//:extensions.bzl", "install_ktfmt")
use_repo(install_ktfmt, "ktfmt")

buf = use_extension("@rules_buf//buf:extensions.bzl", "buf")
use_repo(buf, "rules_buf_toolchains")
6 changes: 6 additions & 0 deletions bzl-examples/bzlmod/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@aspect_rules_lint//format:repositories.bzl", "fetch_ktfmt")

def _install_ktfmt_impl(module_ctx):
fetch_ktfmt()

install_ktfmt = module_extension(_install_ktfmt_impl)
31 changes: 31 additions & 0 deletions bzl-examples/bzlmod/java/io/grpc/examples/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@com_github_grpc_grpc_kotlin//:kt_jvm_grpc.bzl", "kt_jvm_grpc_library", "kt_jvm_proto_library")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

package(default_visibility = ["//javatests/io/grpc/examples/bzlmod:__subpackages__"])

proto_library(
name = "fibonacci_proto",
srcs = ["fibonacci.proto"],
deps = [],
)

kt_jvm_proto_library(
name = "fibonacci_kt_proto",
deps = [":fibonacci_proto"],
)

kt_jvm_grpc_library(
name = "fibonacci_kt_grpc",
srcs = [":fibonacci_proto"],
deps = [":fibonacci_kt_proto"],
)

kt_jvm_library(
name = "fibonacci",
srcs = ["Fibonacci.kt"],
deps = [
":fibonacci_kt_grpc",
":fibonacci_kt_proto",
],
)
19 changes: 19 additions & 0 deletions bzl-examples/bzlmod/java/io/grpc/examples/bzlmod/Fibonacci.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.grpc.examples.bzlmod

/** A simple implementation of a Fibonacci service. */
class Fibonacci : FibonacciServiceGrpcKt.FibonacciServiceCoroutineImplBase() {
override suspend fun query(request: QueryRequest): QueryResponse {
if (request.nth <= 1) {
return queryResponse { nthFibonacci = request.nth }
}
var prv = 0L
var cur = 1L
var nxt = 1L
for (i in 2..request.nth) {
prv = cur
cur = nxt
nxt = (prv + cur) % request.mod
}
return queryResponse { nthFibonacci = cur }
}
}
20 changes: 20 additions & 0 deletions bzl-examples/bzlmod/java/io/grpc/examples/bzlmod/fibonacci.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

package io.grpc.examples.bzlmod;

option java_multiple_files = true;
option java_outer_classname = "FibonacciProtos";
option java_package = "io.grpc.examples.bzlmod";

message QueryRequest {
int64 nth = 1;
int64 mod = 2;
}

message QueryResponse {
int64 nth_fibonacci = 1;
}

service FibonacciService {
rpc Query(QueryRequest) returns (QueryResponse);
}
16 changes: 16 additions & 0 deletions bzl-examples/bzlmod/javatests/io/grpc/examples/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test")

kt_jvm_test(
name = "FibonacciTest",
srcs = ["FibonacciTest.kt"],
deps = [
"//java/io/grpc/examples/bzlmod:fibonacci",
"//java/io/grpc/examples/bzlmod:fibonacci_kt_grpc",
"//java/io/grpc/examples/bzlmod:fibonacci_kt_proto",
artifact("com.google.truth:truth"),
artifact("com.google.truth.extensions:truth-proto-extension"),
artifact("junit:junit"),
artifact("io.grpc:grpc-testing"),
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.grpc.examples.bzlmod

import com.google.common.truth.Truth.assertThat
import com.google.common.truth.extensions.proto.ProtoTruth.assertThat
import io.grpc.inprocess.InProcessChannelBuilder
import io.grpc.inprocess.InProcessServerBuilder
import io.grpc.testing.GrpcCleanupRule
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(JUnit4::class)
class FibonacciTest {
@get:Rule val grpcCleanup = GrpcCleanupRule()

private lateinit var stub: FibonacciServiceGrpcKt.FibonacciServiceCoroutineStub

@Before
fun setUp() {
val serverName = InProcessServerBuilder.generateName()

grpcCleanup.register(
InProcessServerBuilder.forName(serverName)
.directExecutor()
.addService(Fibonacci())
.build()
.start())

stub =
FibonacciServiceGrpcKt.FibonacciServiceCoroutineStub(
grpcCleanup.register(
InProcessChannelBuilder.forName(serverName).directExecutor().build()))
}

@Test
fun query_succeeds() {
runBlocking {
val response =
stub.query(
queryRequest {
nth = 20
mod = 1000000007
})
assertThat(response).isEqualTo(queryResponse { nthFibonacci = 6765 })
}
}
}
Loading
Loading