diff --git a/.bazeliskrc b/.bazeliskrc index e920830..bd4a535 100644 --- a/.bazeliskrc +++ b/.bazeliskrc @@ -1 +1 @@ -USE_BAZEL_VERSION=7.7.0 +USE_BAZEL_VERSION=5.4.1 diff --git a/.bazelrc b/.bazelrc index 7cedb34..7a9655a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,16 +1,8 @@ -# Disable Bazel modules (for now). -common --enable_bzlmod=false - -build --cxxopt='-std=c++17' -build --host_cxxopt='-std=c++17' - # Use a remote build cache that's world-readable. Don't write unless told otherwise. + build --remote_cache=https://storage.googleapis.com/reboot-dev-bazel-remote-cache-reboot-us build --remote_upload_local_results=false # Print full test logs for failed tests. -test --test_output=errors -# To debug errors using the remote cache we need the `--verbose_failures` flag to -# get any useful information whatsoever. -build --verbose_failures +test --test_output=errors diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 3790e29..d73f3a8 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -2,7 +2,7 @@ workspace(name = "com_github_reboot_dev_pyprotoc_plugin") load("//bazel:repos.bzl", "repos") -repos() +repos(external = False) load("//bazel:py_toolchains.bzl", "py_toolchains") diff --git a/bazel/deps.bzl b/bazel/deps.bzl index 0cbe689..510ca54 100644 --- a/bazel/deps.bzl +++ b/bazel/deps.bzl @@ -3,7 +3,7 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") load("@pyprotoc_plugin_pypi//:requirements.bzl", pypi_deps = "install_deps") -def deps(): +def deps(repo_mapping = {}): protobuf_deps() - pypi_deps() + pypi_deps(repo_mapping = repo_mapping) diff --git a/bazel/py_toolchains.bzl b/bazel/py_toolchains.bzl index a80795b..e300d5f 100644 --- a/bazel/py_toolchains.bzl +++ b/bazel/py_toolchains.bzl @@ -2,10 +2,11 @@ load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") -def py_toolchains(): +def py_toolchains(repo_mapping = {}): py_repositories() python_register_toolchains( name = "python3_10_12", python_version = "3.10.12", + repo_mapping = repo_mapping, ) diff --git a/bazel/pypi_repos.bzl b/bazel/pypi_repos.bzl index ebf8407..0647888 100644 --- a/bazel/pypi_repos.bzl +++ b/bazel/pypi_repos.bzl @@ -3,11 +3,12 @@ should be installed later in WORKSPACE file to be accessible. `pip_parse` takes a `requirements_lock` file as input, which is generated by the `bazel run :requirements.update` command.""" +load("@python3_10_12//:defs.bzl", "interpreter") load("@rules_python//python:pip.bzl", "pip_parse") def pypi_repos(): pip_parse( name = "pyprotoc_plugin_pypi", - python_interpreter_target = "@python3_10_12_host//:python", + python_interpreter_target = interpreter, requirements_lock = "@com_github_reboot_dev_pyprotoc_plugin//:requirements_lock.txt", ) diff --git a/bazel/repos.bzl b/bazel/repos.bzl index b10f677..a5cf218 100644 --- a/bazel/repos.bzl +++ b/bazel/repos.bzl @@ -9,26 +9,43 @@ # instructions at https://github.com/reboot-dev/pyprotoc-plugin. ######################################################################## +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -def repos(): - """Adds repositories/archives needed by pyprotoc-plugin.""" +def repos(external = True, repo_mapping = {}): + """Adds repositories/archives needed by pyprotoc-plugin - maybe( - http_archive, + Args: + external: whether or not we're invoking this function as though + though we're an external dependency + repo_mapping: passed through to all other functions that expect/use + repo_mapping, e.g., 'git_repository' + """ + http_archive( name = "rules_python", - sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07", - strip_prefix = "rules_python-1.0.0", - url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz", + sha256 = "9acc0944c94adb23fba1c9988b48768b1bacc6583b52a2586895c5b7491e2e31", + strip_prefix = "rules_python-0.27.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.0/rules_python-0.27.0.tar.gz", + repo_mapping = repo_mapping, ) - maybe( - http_archive, - name = "com_google_protobuf", - sha256 = "955ef3235be41120db4d367be81efe6891c9544b3a71194d80c3055865b26e09", - strip_prefix = "protobuf-29.5", - urls = [ - "https://github.com/protocolbuffers/protobuf/archive/v29.5.tar.gz", - ], - ) + if "com_google_protobuf" not in native.existing_rules(): + git_repository( + name = "com_google_protobuf", + remote = "https://github.com/protocolbuffers/protobuf", + # Release v3.19.4. + # TODO(codingcanuck): Update to a newer release after + # https://github.com/protocolbuffers/protobuf/issues/9688 is fixed. + commit = "22d0e265de7d2b3d2e9a00d071313502e7d4cccf", + shallow_since = "1643340956 -0800", + repo_mapping = repo_mapping, + ) + + if external and "com_github_reboot_dev_pyprotoc_plugin" not in native.existing_rules(): + git_repository( + name = "com_github_reboot_dev_pyprotoc_plugin", + remote = "https://github.com/reboot-dev/pyprotoc-plugin", + commit = "9f7a281670f03b77140c4437ac2a56b86f978af6", + shallow_since = "1649038239 +0000", + repo_mapping = repo_mapping, + ) diff --git a/requirements.in b/requirements.in index 7423a20..9fb21af 100644 --- a/requirements.in +++ b/requirements.in @@ -1,2 +1,2 @@ Jinja2>=3 -protobuf>= 5.29.5 +protobuf>=3 diff --git a/requirements_lock.txt b/requirements_lock.txt index 36a6a0f..63b8c40 100644 --- a/requirements_lock.txt +++ b/requirements_lock.txt @@ -70,14 +70,16 @@ markupsafe==2.1.3 \ --hash=sha256:fec21693218efe39aa7f8599346e90c705afa52c5b31ae019b2e57e8f6542bb2 \ --hash=sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11 # via jinja2 -protobuf==6.32.1 \ - --hash=sha256:2601b779fc7d32a866c6b4404f9d42a3f67c5b9f3f15b4db3cccabe06b95c346 \ - --hash=sha256:2f5b80a49e1eb7b86d85fcd23fe92df154b9730a725c3b38c4e43b9d77018bf4 \ - --hash=sha256:68ff170bac18c8178f130d1ccb94700cf72852298e016a2443bdb9502279e5f1 \ - --hash=sha256:a8a32a84bc9f2aad712041b8b366190f71dde248926da517bde9e832e4412085 \ - --hash=sha256:b00a7d8c25fa471f16bc8153d0e53d6c9e827f0953f3c09aaa4331c718cae5e1 \ - --hash=sha256:b1864818300c297265c83a4982fd3169f97122c299f56a56e2445c3698d34710 \ - --hash=sha256:d0975d0b2f3e6957111aa3935d08a0eb7e006b1505d825f862a1fffc8348e122 \ - --hash=sha256:d8c7e6eb619ffdf105ee4ab76af5a68b60a9d0f66da3ea12d1640e6d8dab7281 \ - --hash=sha256:ee2469e4a021474ab9baafea6cd070e5bf27c7d29433504ddea1a4ee5850f68d +protobuf==4.25.1 \ + --hash=sha256:0bf384e75b92c42830c0a679b0cd4d6e2b36ae0cf3dbb1e1dfdda48a244f4bcd \ + --hash=sha256:0f881b589ff449bf0b931a711926e9ddaad3b35089cc039ce1af50b21a4ae8cb \ + --hash=sha256:1484f9e692091450e7edf418c939e15bfc8fc68856e36ce399aed6889dae8bb0 \ + --hash=sha256:193f50a6ab78a970c9b4f148e7c750cfde64f59815e86f686c22e26b4fe01ce7 \ + --hash=sha256:3497c1af9f2526962f09329fd61a36566305e6c72da2590ae0d7d1322818843b \ + --hash=sha256:57d65074b4f5baa4ab5da1605c02be90ac20c8b40fb137d6a8df9f416b0d0ce2 \ + --hash=sha256:8bdbeaddaac52d15c6dce38c71b03038ef7772b977847eb6d374fc86636fa510 \ + --hash=sha256:a19731d5e83ae4737bb2a089605e636077ac001d18781b3cf489b9546c7c80d6 \ + --hash=sha256:abc0525ae2689a8000837729eef7883b9391cd6aa7950249dcf5a4ede230d5dd \ + --hash=sha256:becc576b7e6b553d22cbdf418686ee4daa443d7217999125c045ad56322dda10 \ + --hash=sha256:ca37bf6a6d0046272c152eea90d2e4ef34593aaa32e8873fc14c16440f22d4b7 # via -r requirements.in diff --git a/rules.bzl b/rules.bzl index 741fec3..e3cde4a 100644 --- a/rules.bzl +++ b/rules.bzl @@ -1,6 +1,6 @@ """Defines rules to create pyprotoc-based bazel rules.""" -load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo") +load("@rules_proto//proto:defs.bzl", "ProtoInfo") def _get_proto_sources(context): proto_files = [ diff --git a/tests/cpp/BUILD.bazel b/tests/cpp/BUILD.bazel index 9913a99..8a20e3f 100644 --- a/tests/cpp/BUILD.bazel +++ b/tests/cpp/BUILD.bazel @@ -1,6 +1,5 @@ -load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library") -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:defs.bzl", "py_binary") load(":cpp_rule.bzl", "cc_generate_library") @@ -55,9 +54,8 @@ cc_library( ], ) -cc_test( +cc_binary( name = "cc_test", - size = "small", srcs = ["cc_generated_test.cc"], deps = [ ":cc_library_generated", diff --git a/tests/python/BUILD.bazel b/tests/python/BUILD.bazel index eac5756..f6d17fd 100644 --- a/tests/python/BUILD.bazel +++ b/tests/python/BUILD.bazel @@ -1,11 +1,10 @@ -load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") -load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") +load("@com_google_protobuf//:protobuf.bzl", "py_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") load(":sample_rule.bzl", "py_sample_library") py_test( name = "library_tests", - size = "small", srcs = [ "library_tests.py", ], @@ -31,7 +30,7 @@ proto_library( py_proto_library( name = "sample_messages_py_proto", - deps = [":sample_messages_proto"], + srcs = ["sample_messages.proto"], ) proto_library( @@ -42,7 +41,8 @@ proto_library( py_proto_library( name = "sample_service_py_proto", - deps = [":sample_messages_proto"], + srcs = ["sample_service.proto"], + deps = [":sample_messages_py_proto"], ) py_sample_library( @@ -62,7 +62,6 @@ py_library( py_test( name = "sample_generated_library_test", - size = "small", srcs = [ "sample_generated_library_test.py", ],