Skip to content

Commit

Permalink
Use java 17, upgrade rules_scala, custom toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Jan 3, 2024
1 parent c18a182 commit bc10591
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 24 deletions.
8 changes: 7 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
common --enable_platform_specific_config

common --jvmopt=-Djava.security.manager=allow
build --java_language_version=17
build --java_runtime_version=remotejdk_17
build --tool_java_language_version=17
build --tool_java_runtime_version=remotejdk_17

common --enable_platform_specific_config
build:windows --cxxopt='/std:c++14'
build:windows --host_cxxopt='/std:c++14'
build:linux --cxxopt='-std=c++14'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ site:

.PHONY: test
test:
$(BAZEL) test //example/... //pkg/... //plugin/... //language/... //rules/... //toolchain/... \
$(BAZEL) test --keep_going //example/... //pkg/... //plugin/... //language/... //rules/... //toolchain/... \
--deleted_packages=//plugin/grpc-ecosystem/grpc-gateway

.PHONY: get
Expand Down
17 changes: 12 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,32 @@ grpc_java_repositories()
# # Golang
# # ----------------------------------------------------

# load("//deps:go_core_deps.bzl", "go_core_deps")
load("//deps:go_core_deps.bzl", "go_core_deps")

# go_core_deps()
go_core_deps()

# ----------------------------------------------------
# Scala
# ----------------------------------------------------

load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(scala_version = "2.12.11")
scala_config(
enable_compiler_dependency_tracking = True,
scala_version = "2.12.18",
)

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")

scala_repositories()

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
register_toolchains(
"//toolchain/scala:default_toolchain",
)

scala_register_toolchains()
# ----------------------------------------------------
# Scala/Maven
# ----------------------------------------------------

# bazel run @maven_scala//:pin, but first comment out the "maven_install_json"
# (put it back once pinned again)
Expand Down
20 changes: 8 additions & 12 deletions deps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,17 @@ filegroup(
urls = ["https://github.com/google/protobuf/releases/download/v3.20.1/protoc-3.20.1-win32.zip"],
)

# Branch: master
# Commit: 2437e40131072cadc1628726775ff00fa3941a4a
# Date: 2021-09-06 10:18:08 +0000 UTC
# URL: https://github.com/bazelbuild/rules_scala/commit/2437e40131072cadc1628726775ff00fa3941a4a
#
# Remove customized ijar code (#1285)
#
# ijar patch was upstreamed and is available since Bazek 4.1.0
# Size: 638431 (638 kB)
# Release: v6.4.0
# TargetCommitish: master
# Date: 2023-12-19 10:42:41 +0000 UTC
# URL: https://github.com/bazelbuild/rules_scala/releases/tag/v6.4.0
# Size: 680962 (681 kB)
proto_dependency(
name = "io_bazel_rules_scala",
repository_rule = "http_archive",
sha256 = "0701ee4e1cfd59702d780acde907ac657752fbb5c7d08a0ec6f58ebea8cd0efb",
strip_prefix = "rules_scala-2437e40131072cadc1628726775ff00fa3941a4a",
urls = ["https://github.com/bazelbuild/rules_scala/archive/2437e40131072cadc1628726775ff00fa3941a4a.tar.gz"],
sha256 = "9a23058a36183a556a9ba7229b4f204d3e68c8c6eb7b28260521016b38ef4e00",
strip_prefix = "rules_scala-6.4.0",
urls = ["https://github.com/bazelbuild/rules_scala/archive/v6.4.0.tar.gz"],
deps = [":bazel_skylib"],
)

Expand Down
12 changes: 12 additions & 0 deletions deps/closure_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ def _maybe(repo_rule, name, **kwargs):
def closure_deps():
"""closure dependency macro
"""
com_google_protobuf_javascript() # via io_bazel_rules_closure
io_bazel_rules_closure() # via <TOP>

def com_google_protobuf_javascript():
_maybe(
http_archive,
name = "com_google_protobuf_javascript",
sha256 = "06fc35c7d35c48bdc99a6ab72211086532d1de2bc4ec28011cde607a4025ea95",
strip_prefix = "protobuf-javascript-e1a52f9a897653985b0649cca17615cb1b0eb3b7",
urls = [
"https://github.com/protocolbuffers/protobuf-javascript/archive/e1a52f9a897653985b0649cca17615cb1b0eb3b7.tar.gz",
],
)

def io_bazel_rules_closure():
_maybe(
http_archive,
Expand Down
6 changes: 3 additions & 3 deletions deps/scala_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def io_bazel_rules_scala():
_maybe(
http_archive,
name = "io_bazel_rules_scala",
sha256 = "0701ee4e1cfd59702d780acde907ac657752fbb5c7d08a0ec6f58ebea8cd0efb",
strip_prefix = "rules_scala-2437e40131072cadc1628726775ff00fa3941a4a",
sha256 = "9a23058a36183a556a9ba7229b4f204d3e68c8c6eb7b28260521016b38ef4e00",
strip_prefix = "rules_scala-6.4.0",
urls = [
"https://github.com/bazelbuild/rules_scala/archive/2437e40131072cadc1628726775ff00fa3941a4a.tar.gz",
"https://github.com/bazelbuild/rules_scala/archive/v6.4.0.tar.gz",
],
)
1 change: 0 additions & 1 deletion example/thing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ proto_scala_library(
"@maven_scala//:com_google_protobuf_protobuf_java",
"@maven_scala//:com_thesamet_scalapb_lenses_2_12",
"@maven_scala//:com_thesamet_scalapb_scalapb_runtime_2_12",
"@protoapis//google/protobuf:timestamp_proto_scala_library",
],
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/rule/rules_scala/scala_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (s *scalaLibraryRule) Imports(c *config.Config, r *rule.Rule, file *rule.Fi
func (s *scalaLibraryRule) Resolve(c *config.Config, ix *resolve.RuleIndex, r *rule.Rule, imports []string, from label.Label) {
imports = s.options.filterImports(imports)

resolveFn := protoc.ResolveDepsAttr("deps", s.options.resolveWKTs)
resolveFn := protoc.ResolveDepsAttr("deps", !s.options.resolveWKTs)
resolveFn(c, ix, r, imports, from)

if unresolvedDeps, ok := r.PrivateAttr(protoc.UnresolvedDepsPrivateKey).(map[string]error); ok {
Expand Down
1 change: 1 addition & 0 deletions rules/private/proto_repository_tools_srcs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ PROTO_REPOSITORY_TOOLS_SRCS = [
"@build_stack_rules_proto//rules/scala:BUILD.bazel",
"@build_stack_rules_proto//rules/ts:BUILD.bazel",
"@build_stack_rules_proto//toolchain:BUILD.bazel",
"@build_stack_rules_proto//toolchain/scala:BUILD.bazel",
"@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/config:config.go",
"@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/config:constants.go",
"@build_stack_rules_proto//vendor/github.com/bazelbuild/bazel-gazelle/flag:flag.go",
Expand Down
90 changes: 90 additions & 0 deletions toolchain/scala/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
load("@io_bazel_rules_scala//scala:scala_toolchain.bzl", "scala_toolchain")

toolchain(
name = "default_toolchain",
toolchain = "minimal_direct_source_deps",
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
visibility = ["//visibility:public"],
)

scala_toolchain(
name = "minimal_direct_source_deps",
compiler_deps_mode = "error",
dependency_mode = "direct",
dependency_tracking_method = "ast-plus",
scalac_jvm_flags = [
"-Djava.security.manager=allow",
],
strict_deps_mode = "error",
unused_dependency_checker_mode = "error",
)

# toolchain(
# name = "testing_toolchain",
# toolchain = ":testing_toolchain_with_junit_and_scalatest_impl",
# toolchain_type = "@io_bazel_rules_scala//testing/toolchain:testing_toolchain_type",
# visibility = ["//visibility:public"],
# )

# scala_testing_toolchain(
# name = "testing_toolchain_with_junit_and_scalatest_impl",
# dep_providers = [
# ":junit_classpath_provider",
# ":scalatest_classpath_provider",
# ],
# visibility = ["//visibility:public"],
# )

# declare_deps_provider(
# name = "junit_classpath_provider",
# deps_id = "junit_classpath",
# visibility = ["//visibility:public"],
# deps = [
# "@maven//:junit_junit",
# "@maven//:org_hamcrest_hamcrest",
# "@maven//:org_hamcrest_hamcrest_core",
# ],
# )

# declare_deps_provider(
# name = "scalatest_classpath_provider",
# deps_id = "scalatest_classpath",
# visibility = ["//visibility:public"],
# deps = [
# "@maven//:org_scalactic_scalactic_2_12",
# "@maven//:org_scalamock_scalamock_2_12",
# "@maven//:org_scalatest_scalatest_2_12",
# ],
# )

# filegroup(
# name = "jacocorunner",
# srcs = ["@bazel_jacocorunner//:jar"],
# visibility = ["//visibility:public"],
# )

# genrule(
# name = "jacocorunner_jar",
# srcs = [":jacocorunner"],
# outs = ["jacocorunner.jar"],
# cmd = "cp $< $@",
# )

# # NOTE: this target is named in a patch file for io_bazel_rules_scala to
# # synchronize the version of the jacocorunner used by the scala instrumenter
# # (compile-time) and during the coverage tests (runtime).
# java_import(
# name = "global_jacocorunner",
# jars = [":jacocorunner.jar"],
# visibility = ["//visibility:public"],
# )

# create_base_image_with_core_deps(
# arch_shortname = "arm64",
# base_image = "//bazel_tools:java_arm64",
# )

# create_base_image_with_core_deps(
# arch_shortname = "amd64",
# base_image = "//bazel_tools:java",
# )

0 comments on commit bc10591

Please sign in to comment.