diff --git a/.bazelrc b/.bazelrc index 8f966db78f1..7ea81ad73b4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -22,11 +22,6 @@ run --remote_download_outputs=all coverage --build_runfile_links coverage --nocache_test_results -# Needed by rules_meta. -# Follow https://github.com/fmeum/rules_meta/issues/1#issuecomment-1255828109 -# for updates. -common --incompatible_remove_rule_name_parameter=false - # Get version information into the build. build --workspace_status_command=bazel/get_workspace_status.sh diff --git a/WORKSPACE b/WORKSPACE index 786ee4b130b..05177c8c7de 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -19,6 +19,14 @@ pl_register_cc_toolchains() # Install Pixie Labs Dependencies. pl_deps() +load("@bazel_features//:deps.bzl", "bazel_features_deps") + +bazel_features_deps() + +load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo") + +compatibility_proxy_repo() + # Order is important. Try to go from most basic/primitive to higher level packages. # - go_rules_dependencies # - protobuf_deps @@ -45,6 +53,10 @@ go_register_toolchains() # gazelle:repository_macro go_deps.bzl%pl_go_dependencies pl_go_dependencies() +load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies") + +rules_java_dependencies() + load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() @@ -53,17 +65,34 @@ load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") grpc_deps() -load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config") +load("@io_bazel_rules_scala//scala:deps.bzl", "rules_scala_dependencies") -scala_version = "2.13.6" +rules_scala_dependencies() -scala_config(scala_version = scala_version) +load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config") -load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories") +scala_version = "2.13.16" -scala_repositories() +scala_config(scala_version = scala_version) -load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains") +load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains", "scala_toolchains") + +scala_toolchains( + fetch_sources = True, + twitter_scrooge = { + "libthrift": "@thrift_deps//:org_apache_thrift_libthrift", + # Use scrooge_core_with_finagle to include finagle on the compile classpath + # for generated thrift service code. Must use @px// prefix to reference + # the main workspace from within the generated @rules_scala_toolchains repo. + "scrooge_core": "@px//src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux:scrooge_core_with_finagle", + "scrooge_generator": "@thrift_deps//:com_twitter_scrooge_generator_2_13", + "util_core": "@thrift_deps//:com_twitter_util_core_2_13", + "util_logging": "@thrift_deps//:com_twitter_util_logging_2_13", + "javax_annotation_api": "@thrift_deps//:javax_annotation_javax_annotation_api", + "mustache": "@thrift_deps//:com_github_spullara_mustache_java_compiler", + "scopt": "@thrift_deps//:com_github_scopt_scopt_2_13", + }, +) scala_register_toolchains() @@ -183,26 +212,6 @@ load("@thrift_deps//:defs.bzl", thrift_pinned_maven_install = "pinned_maven_inst thrift_pinned_maven_install() -# twitter_scrooge will use incompatible versions of @scrooge_jars and @thrift_jars. -# These bind statements ensure that the correct versions of finagle libthrift, scrooge core -# and scrooge generator are used to ensure successful compilation. -# See https://github.com/bazelbuild/rules_scala/issues/592 and -# https://github.com/bazelbuild/rules_scala/pull/847 for more details. -bind( - name = "io_bazel_rules_scala/dependency/thrift/scrooge_core", - actual = "//src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux:scrooge_jars", -) - -bind( - name = "io_bazel_rules_scala/dependency/thrift/scrooge_generator", - actual = "//src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux:scrooge_jars", -) - -bind( - name = "io_bazel_rules_scala/dependency/thrift/libthrift", - actual = "//src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux:thrift_jars", -) - # gazelle:repo bazel_gazelle # Gazelle depes need to be loaded last to make sure they don't override our dependencies. # The first one wins when it comes to package declaration. diff --git a/bazel/cc_toolchains/sysroots/images.bzl b/bazel/cc_toolchains/sysroots/images.bzl index a56583f55ba..9de1aa0f603 100644 --- a/bazel/cc_toolchains/sysroots/images.bzl +++ b/bazel/cc_toolchains/sysroots/images.bzl @@ -65,7 +65,6 @@ def _sysroot_variant_image_factory(variant): return _image_from_sysroot_info(ctx, sysroot_toolchain.sysroot) return rule( - name = "sysroot_{variant}_image".format(variant = variant), implementation = _impl, attrs = dicts.add(_container.image.attrs, { "default_image": attr.label(mandatory = True, doc = "Default container_image to use if no sysroot toolchain is found"), diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 0181203778f..89f0e2dbc2b 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -257,10 +257,11 @@ def _pl_deps(): _bazel_repo("rules_python") _bazel_repo("rules_pkg") _bazel_repo("com_github_bazelbuild_buildtools") - _bazel_repo("com_github_fmeum_rules_meta") _bazel_repo("com_google_protobuf_javascript", patches = ["//bazel/external:protobuf_javascript.patch"], patch_args = ["-p1"]) # TODO(ddelnano): Remove patch once grpc-web upgrades to protobuf v30+. _bazel_repo("com_github_grpc_grpcweb", patches = ["//bazel/external:grpc-web_protobuf_v30_support.patch"], patch_args = ["-p1"]) + _bazel_repo("bazel_features") + _bazel_repo("with_cfg.bzl") _com_llvm_lib() _cc_deps() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 6cd59e9f7ac..3b5c832da59 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -15,6 +15,11 @@ # SPDX-License-Identifier: Apache-2.0 REPOSITORY_LOCATIONS = dict( + bazel_features = dict( + sha256 = "07271d0f6b12633777b69020c4cb1eb67b1939c0cf84bb3944dc85cc250c0c01", + strip_prefix = "bazel_features-1.38.0", + urls = ["https://github.com/bazel-contrib/bazel_features/releases/download/v1.38.0/bazel_features-v1.38.0.tar.gz"], + ), bazel_gazelle = dict( sha256 = "d76bf7a60fd8b050444090dfa2837a4eaf9829e1165618ee35dceca5cbdf58d5", urls = [ @@ -81,13 +86,6 @@ REPOSITORY_LOCATIONS = dict( strip_prefix = "tdigest-85e0f70092460e60236821db4c25143768d3da12", urls = ["https://github.com/pixie-io/tdigest/archive/85e0f70092460e60236821db4c25143768d3da12.tar.gz"], ), - com_github_fmeum_rules_meta = dict( - sha256 = "ed3ed909e6e3f34a11d7c2adcc461535975a875fe434719540a4e6f63434a866", - strip_prefix = "rules_meta-0.0.4", - urls = [ - "https://github.com/fmeum/rules_meta/archive/refs/tags/v0.0.4.tar.gz", - ], - ), com_github_gflags_gflags = dict( sha256 = "9e1a38e2dcbb20bb10891b5a171de2e5da70e0a50fff34dd4b0c2c6d75043909", strip_prefix = "gflags-524b83d0264cb9f1b2d134c564ef1aa23f207a41", @@ -439,11 +437,11 @@ REPOSITORY_LOCATIONS = dict( ], ), io_bazel_rules_scala = dict( - sha256 = "6e9191363357d30b144e7306fec74deea2c7f1de63f3ed32028838116c239e8a", + sha256 = "6a900a39bf643c5c9308c8200f9a61e27588dc54a67aa08fcfc798f25add4f7b", urls = [ - "https://github.com/bazelbuild/rules_scala/archive/4ba3780fcba8d26980daff4639abc6f18517308b.tar.gz", + "https://github.com/bazelbuild/rules_scala/releases/download/v7.1.0/rules_scala-v7.1.0.tar.gz", ], - strip_prefix = "rules_scala-4ba3780fcba8d26980daff4639abc6f18517308b", + strip_prefix = "rules_scala-7.1.0", ), org_tensorflow = dict( sha256 = "a640d1f97be316a09301dfc9347e3d929ad4d9a2336e3ca23c32c93b0ff7e5d0", @@ -457,9 +455,9 @@ REPOSITORY_LOCATIONS = dict( manual_license_name = "libc/musl", ), rules_cc = dict( - sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1", - strip_prefix = "rules_cc-0.0.17", - urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz"], + sha256 = "a2fdfde2ab9b2176bd6a33afca14458039023edb1dd2e73e6823810809df4027", + strip_prefix = "rules_cc-0.2.14", + urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.2.14/rules_cc-0.2.14.tar.gz"], ), rules_foreign_cc = dict( sha256 = "6041f1374ff32ba711564374ad8e007aef77f71561a7ce784123b9b4b88614fc", @@ -511,6 +509,12 @@ REPOSITORY_LOCATIONS = dict( ), ) +REPOSITORY_LOCATIONS["with_cfg.bzl"] = dict( + sha256 = "c7af6227d24499438fa0bb96fe4034e163d8c807b06f7c0645f3654448268b84", + strip_prefix = "with_cfg.bzl-0.11.0", + urls = ["https://github.com/fmeum/with_cfg.bzl/releases/download/v0.11.0/with_cfg.bzl-v0.11.0.tar.gz"], +) + # To modify one of the forked repos below: # 1. Make the changes to the repo and push the changes to the `pixie` on github. # 2. Update the commit below to point to the commit hash of the new `pixie` branch. diff --git a/bazel/thrift.bzl b/bazel/thrift.bzl index 3b535d8a078..f370029d4c6 100644 --- a/bazel/thrift.bzl +++ b/bazel/thrift.bzl @@ -14,25 +14,29 @@ # # SPDX-License-Identifier: Apache-2.0 -load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge") load("@rules_jvm_external//:defs.bzl", "maven_install") def thrift_deps(scala_version): - twitter_scrooge() + # twitter_scrooge is now set up via scala_toolchains(twitter_scrooge = {...}) in WORKSPACE - finagle_version = "22.7.0" + finagle_version = "24.2.0" scala_minor_version = ".".join(scala_version.split(".")[:2]) maven_install( name = "thrift_deps", artifacts = [ + # Finagle dependencies (needed for generated service code) "com.twitter:finagle-thriftmux_%s:%s" % (scala_minor_version, finagle_version), + "com.twitter:finagle-thrift_%s:%s" % (scala_minor_version, finagle_version), "com.twitter:finagle-mux_%s:%s" % (scala_minor_version, finagle_version), "com.twitter:finagle-core_%s:%s" % (scala_minor_version, finagle_version), + "com.twitter:finagle-http_%s:%s" % (scala_minor_version, finagle_version), + # Scrooge dependencies (needed for code generation toolchain) "com.twitter:scrooge-core_%s:%s" % (scala_minor_version, finagle_version), "com.twitter:scrooge-generator_%s:%s" % (scala_minor_version, finagle_version), - "com.twitter:finagle-http_%s:%s" % (scala_minor_version, finagle_version), - "org.apache.thrift:libthrift:0.10.0", + "com.twitter:util-core_%s:%s" % (scala_minor_version, finagle_version), + "com.twitter:util-logging_%s:%s" % (scala_minor_version, finagle_version), + # Logging "org.slf4j:slf4j-api:1.7.36", "ch.qos.logback:logback-core:1.2.10", "ch.qos.logback:logback-classic:1.2.10", diff --git a/bazel/toolchain_transitions.bzl b/bazel/toolchain_transitions.bzl index 5578af5dada..e1e402a479d 100644 --- a/bazel/toolchain_transitions.bzl +++ b/bazel/toolchain_transitions.bzl @@ -14,30 +14,15 @@ # # SPDX-License-Identifier: Apache-2.0 -load("@com_github_fmeum_rules_meta//meta:defs.bzl", "meta") +load("@with_cfg.bzl", "with_cfg") load("//bazel/test_runners/qemu_with_kernel:runner.bzl", "qemu_with_kernel_interactive_runner") -java_graal_binary = meta.wrap_with_transition( - native.java_binary, - { - "java_runtime_version": meta.replace_with("remotejdk_openjdk_graal_17"), - }, - executable = True, -) +java_graal_binary, _java_graal_binary_internal = with_cfg(native.java_binary).set( + "java_runtime_version", "remotejdk_openjdk_graal_17").build() -cc_clang_binary = meta.wrap_with_transition( - native.cc_binary, - { - "@//bazel/cc_toolchains:compiler": meta.replace_with("clang"), - "@//bazel/cc_toolchains:libc_version": meta.replace_with("glibc2_36"), - }, - executable = True, -) +cc_clang_binary, _cc_clang_binary_internal = with_cfg(native.cc_binary).set( + Label("@//bazel/cc_toolchains:compiler"), "clang").set( + Label("@//bazel/cc_toolchains:libc_version"), "glibc2_36").build() -qemu_interactive_runner = meta.wrap_with_transition( - qemu_with_kernel_interactive_runner, - { - "@//bazel/cc_toolchains:libc_version": meta.replace_with("glibc2_36"), - }, - executable = True, -) +qemu_interactive_runner, _qemu_interactive_runner_internal = with_cfg(qemu_with_kernel_interactive_runner).set( + Label("@//bazel/cc_toolchains:libc_version"), "glibc2_36").build() diff --git a/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/BUILD.bazel index 178fb5dd354..39dfa989c20 100644 --- a/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/BUILD.bazel +++ b/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/BUILD.bazel @@ -67,6 +67,19 @@ thrift_library( srcs = glob(["**/*.thrift"]), ) +# Scrooge core with finagle dependencies bundled. +# This is used as the scrooge_core for the toolchain, so that the generated +# service code has access to finagle classes at compile time. +scala_library( + name = "scrooge_core_with_finagle", + visibility = ["//visibility:public"], + exports = [ + "@thrift_deps//:com_twitter_finagle_core_2_13", + "@thrift_deps//:com_twitter_finagle_thrift_2_13", + "@thrift_deps//:com_twitter_scrooge_core_2_13", + ], +) + scala_library( name = "scrooge_jars", visibility = ["//visibility:public"], @@ -81,6 +94,31 @@ scala_library( ], ) +# Runtime dependencies for generated scrooge code (for downstream consumers) +scala_library( + name = "scrooge_runtime_deps", + visibility = ["//visibility:public"], + exports = [ + "@thrift_deps//:com_twitter_finagle_core_2_13", + "@thrift_deps//:com_twitter_finagle_thrift_2_13", + "@thrift_deps//:com_twitter_scrooge_core_2_13", + "@thrift_deps//:org_apache_thrift_libthrift", + ], +) + +# Full finagle dependencies for Server/Client scala files +scala_library( + name = "finagle_deps", + visibility = ["//visibility:public"], + exports = [ + "@thrift_deps//:com_twitter_finagle_core_2_13", + "@thrift_deps//:com_twitter_finagle_http_2_13", + "@thrift_deps//:com_twitter_finagle_mux_2_13", + "@thrift_deps//:com_twitter_finagle_thrift_2_13", + "@thrift_deps//:com_twitter_finagle_thriftmux_2_13", + ], +) + scala_library( name = "thrift_jars", visibility = ["//visibility:public"], @@ -91,6 +129,9 @@ scala_library( scrooge_scala_library( name = "thriftmux_scrooge", + exports = [ + ":scrooge_runtime_deps", + ], deps = [ ":thrift_library", ], @@ -110,6 +151,7 @@ scala_binary( srcs = glob(["**/*.scala"]), main_class = "Server", deps = [ + ":finagle_deps", ":thriftmux_scrooge", ], ) @@ -119,6 +161,7 @@ scala_binary( srcs = glob(["**/*.scala"]), main_class = "Client", deps = [ + ":finagle_deps", ":thriftmux_scrooge", ], ) @@ -144,6 +187,7 @@ scala_image( ], main_class = "Server", deps = [ + ":finagle_deps", ":logging", ":thriftmux_scrooge", ],