Skip to content

Commit

Permalink
Add jmh deps toolchain (bazelbuild#1106)
Browse files Browse the repository at this point in the history
* Add jmh deps toolchain

* Add JMH library deps to toolchain

* Add jmh core to deps toolchain
  • Loading branch information
Vaidas Pilkauskas authored and Borja Lorente committed Nov 26, 2020
1 parent 997c59f commit bd63009
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 9 deletions.
77 changes: 77 additions & 0 deletions jmh/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
load("//scala:providers.bzl", "declare_deps_provider")
load("//jmh/toolchain:toolchain.bzl", "export_toolchain_deps", "jmh_toolchain")

jmh_toolchain(
name = "jmh_toolchain_impl",
visibility = ["//visibility:public"],
)

toolchain(
name = "jmh_toolchain",
toolchain = ":jmh_toolchain_impl",
toolchain_type = "@io_bazel_rules_scala//jmh/toolchain:jmh_toolchain_type",
)

declare_deps_provider(
name = "jmh_core_provider",
deps_id = "jmh_core",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/jmh/jmh_core",
],
)

declare_deps_provider(
name = "jmh_classpath_provider",
deps_id = "jmh_classpath",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple",
"//external:io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3",
],
)

declare_deps_provider(
name = "benchmark_generator_provider",
deps_id = "benchmark_generator",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/jmh/jmh_core",
"//external:io_bazel_rules_scala/dependency/jmh/jmh_generator_asm",
"//external:io_bazel_rules_scala/dependency/jmh/jmh_generator_reflection",
"//src/java/io/bazel/rulesscala/jar",
],
)

declare_deps_provider(
name = "benchmark_generator_runtime_provider",
deps_id = "benchmark_generator_runtime",
visibility = ["//visibility:public"],
deps = [
"//external:io_bazel_rules_scala/dependency/jmh/org_ows2_asm_asm",
],
)

export_toolchain_deps(
name = "jmh_classpath",
deps_id = "jmh_classpath",
visibility = ["//visibility:public"],
)

export_toolchain_deps(
name = "jmh_core",
deps_id = "jmh_core",
visibility = ["//visibility:public"],
)

export_toolchain_deps(
name = "benchmark_generator",
deps_id = "benchmark_generator",
visibility = ["//visibility:public"],
)

export_toolchain_deps(
name = "benchmark_generator_runtime",
deps_id = "benchmark_generator_runtime",
visibility = ["//visibility:public"],
)
9 changes: 5 additions & 4 deletions jmh/jmh.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def jmh_repositories(maven_servers = _default_maven_server_urls()):
actual = "@io_bazel_rules_scala_org_apache_commons_commons_math3//jar",
)

native.register_toolchains("@io_bazel_rules_scala//jmh:jmh_toolchain")

def _scala_generate_benchmark(ctx):
# we use required providers to ensure JavaInfo exists
info = ctx.attr.src[JavaInfo]
Expand Down Expand Up @@ -142,7 +144,7 @@ def scala_benchmark_jmh(**kw):
name = lib,
srcs = srcs,
deps = deps + [
"//external:io_bazel_rules_scala/dependency/jmh/jmh_core",
"@io_bazel_rules_scala//jmh:jmh_core",
],
scalacopts = scalacopts,
resources = kw.get("resources", []),
Expand All @@ -162,7 +164,7 @@ def scala_benchmark_jmh(**kw):
name = compiled_lib,
srcs = ["%s.srcjar" % codegen],
deps = deps + [
"//external:io_bazel_rules_scala/dependency/jmh/jmh_core",
"@io_bazel_rules_scala//jmh:jmh_core",
lib,
],
resource_jars = ["%s_resources.jar" % codegen],
Expand All @@ -171,8 +173,7 @@ def scala_benchmark_jmh(**kw):
scala_binary(
name = name,
deps = [
"//external:io_bazel_rules_scala/dependency/jmh/net_sf_jopt_simple_jopt_simple",
"//external:io_bazel_rules_scala/dependency/jmh/org_apache_commons_commons_math3",
"@io_bazel_rules_scala//jmh:jmh_classpath",
compiled_lib,
],
data = data,
Expand Down
4 changes: 4 additions & 0 deletions jmh/toolchain/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
toolchain_type(
name = "jmh_toolchain_type",
visibility = ["//visibility:public"],
)
36 changes: 36 additions & 0 deletions jmh/toolchain/toolchain.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("//scala/private/toolchain_deps:toolchain_deps.bzl", "expose_toolchain_deps")
load("@io_bazel_rules_scala//scala:providers.bzl", _DepsInfo = "DepsInfo")

def _jmh_toolchain_impl(ctx):
toolchain = platform_common.ToolchainInfo(
dep_providers = ctx.attr.dep_providers,
)
return [toolchain]

jmh_toolchain = rule(
_jmh_toolchain_impl,
attrs = {
"dep_providers": attr.label_list(
default = [
"@io_bazel_rules_scala//jmh:jmh_classpath_provider",
"@io_bazel_rules_scala//jmh:jmh_core_provider",
"@io_bazel_rules_scala//jmh:benchmark_generator_provider",
"@io_bazel_rules_scala//jmh:benchmark_generator_runtime_provider",
],
providers = [_DepsInfo],
),
},
)

def _export_toolchain_deps_impl(ctx):
return expose_toolchain_deps(ctx, "@io_bazel_rules_scala//jmh/toolchain:jmh_toolchain_type")

export_toolchain_deps = rule(
_export_toolchain_deps_impl,
attrs = {
"deps_id": attr.string(
mandatory = True,
),
},
toolchains = ["@io_bazel_rules_scala//jmh/toolchain:jmh_toolchain_type"],
)
7 changes: 2 additions & 5 deletions src/scala/io/bazel/rules_scala/jmh_support/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ scala_library(
srcs = ["BenchmarkGenerator.scala"],
visibility = ["//visibility:public"],
runtime_deps = [
"//external:io_bazel_rules_scala/dependency/jmh/org_ows2_asm_asm",
"//jmh:benchmark_generator_runtime",
],
deps = [
"//external:io_bazel_rules_scala/dependency/jmh/jmh_core",
"//external:io_bazel_rules_scala/dependency/jmh/jmh_generator_asm",
"//external:io_bazel_rules_scala/dependency/jmh/jmh_generator_reflection",
"//src/java/io/bazel/rulesscala/jar",
"//jmh:benchmark_generator",
],
)

Expand Down

0 comments on commit bd63009

Please sign in to comment.