From 39ec8e661da954eb23d6746822b414274b50675d Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Fri, 24 May 2024 11:18:19 -0700 Subject: [PATCH] feat: wire up protobuf if requested --- scaffold.yaml | 7 ++++- {{ .ProjectSnake }}/.bazelrc | 3 ++ {{ .ProjectSnake }}/MODULE.bazel | 14 +++++++-- {{ .ProjectSnake }}/requirements.txt | 2 +- {{ .ProjectSnake }}/requirements_lock.txt | 31 +++++++------------ .../tools/toolchains/BUILD.bazel | 14 +++++++++ 6 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 {{ .ProjectSnake }}/tools/toolchains/BUILD.bazel diff --git a/scaffold.yaml b/scaffold.yaml index 9c47a15..4f94b10 100644 --- a/scaffold.yaml +++ b/scaffold.yaml @@ -39,6 +39,11 @@ questions: message: Setup version stamping? description: "Read more: https://blog.aspect.build/versioning-releases-from-a-monorepo" confirm: true + - name: protobuf + prompt: + message: Setup Protocol Buffers? + description: "Install rules_proto; see https://github.com/bazelbuild/rules_proto/discussions/213" + confirm: true features: - value: "{{ .Scaffold.lint }}" @@ -71,6 +76,7 @@ presets: lint: true langs: ['JavaScript & TypeScript', 'Python'] stamp: true + protobuf: true js: lint: true langs: ['JavaScript & TypeScript'] @@ -78,5 +84,4 @@ presets: lint: true langs: ['Python'] minimal: - lint: false langs: [] diff --git a/{{ .ProjectSnake }}/.bazelrc b/{{ .ProjectSnake }}/.bazelrc index 9746e4f..2059aca 100644 --- a/{{ .ProjectSnake }}/.bazelrc +++ b/{{ .ProjectSnake }}/.bazelrc @@ -21,6 +21,9 @@ common --@aspect_rules_ts//ts:default_to_tsc_transpiler # --config=release common:release --stamp --workspace_status_command=./tools/workspace_status.sh {{ end }} +{{- if .Scaffold.protobuf }} +common --incompatible_enable_proto_toolchain_resolution +{{ end }} # Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`. # This file should appear in `.gitignore` so that settings are not shared with team members. This diff --git a/{{ .ProjectSnake }}/MODULE.bazel b/{{ .ProjectSnake }}/MODULE.bazel index 1466681..b9f55d8 100644 --- a/{{ .ProjectSnake }}/MODULE.bazel +++ b/{{ .ProjectSnake }}/MODULE.bazel @@ -1,10 +1,16 @@ bazel_dep(name = "aspect_bazel_lib", version = "2.7.6") +{{- if .Scaffold.lint }} bazel_dep(name = "aspect_rules_lint", version = "0.21.0") +{{- end }} +{{- if .Scaffold.protobuf }} +bazel_dep(name = "rules_proto", version = "6.0.0") +bazel_dep(name = "toolchains_protoc", version = "0.2.4") +{{- end}} bazel_dep(name = "rules_multitool", version = "0.7.1") {{- if .Computed.javascript }} bazel_dep(name = "aspect_rules_js", version = "2.0.0-rc1") bazel_dep(name = "aspect_rules_ts", version = "3.0.0-rc0") -{{- end}} +{{- end }} {{- if .Computed.python }} bazel_dep(name = "rules_python", version = "0.32.2") bazel_dep(name = "aspect_rules_py", version = "0.7.3") @@ -50,4 +56,8 @@ pip.parse( python_version = "3.9", ) use_repo(pip, "pip") -{{- end}} +{{- end }} + +{{- if .Scaffold.protobuf }} +register_toolchains("//tools/toolchains:all", dev_dependency = True) +{{- end }} \ No newline at end of file diff --git a/{{ .ProjectSnake }}/requirements.txt b/{{ .ProjectSnake }}/requirements.txt index 160d236..24c39e9 100644 --- a/{{ .ProjectSnake }}/requirements.txt +++ b/{{ .ProjectSnake }}/requirements.txt @@ -3,4 +3,4 @@ # direct and indirect dependencies are pinned. # Therefore we only need to constrain versions in this file when some ranges # of dependency versions are not compatible. -requests +protobuf diff --git a/{{ .ProjectSnake }}/requirements_lock.txt b/{{ .ProjectSnake }}/requirements_lock.txt index 6de93b3..0b06b05 100644 --- a/{{ .ProjectSnake }}/requirements_lock.txt +++ b/{{ .ProjectSnake }}/requirements_lock.txt @@ -4,23 +4,16 @@ # # bazel run //:requirements.update # -certifi==2023.7.22 \ - --hash=sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082 \ - --hash=sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9 - # via requests -charset-normalizer==2.1.1 \ - --hash=sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845 \ - --hash=sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f - # via requests -idna==3.7 \ - --hash=sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc \ - --hash=sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0 - # via requests -requests==2.32.0 \ - --hash=sha256:f2c3881dddb70d056c5bd7600a4fae312b2a300e39be6a118d30b90bd27262b5 \ - --hash=sha256:fa5490319474c82ef1d2c9bc459d3652e3ae4ef4c4ebdd18a21145a47ca4b6b8 +protobuf==5.26.0 \ + --hash=sha256:2c334550e1cb4efac5c8a3987384bf13a4334abaf5ab59e40479e7b70ecd6b19 \ + --hash=sha256:6ee9d1aa02f951c5ce10bf8c6cfb7604133773038e33f913183c8b5201350600 \ + --hash=sha256:7e47c57303466c867374a17b2b5e99c5a7c8b72a94118e2f28efb599f19b4069 \ + --hash=sha256:82f5870d74c99addfe4152777bdf8168244b9cf0ac65f8eccf045ddfa9d80d9b \ + --hash=sha256:8eef61a90631c21b06b4f492a27e199a269827f046de3bb68b61aa84fcf50905 \ + --hash=sha256:a49b6c5359bf34fb7bf965bf21abfab4476e4527d822ab5289ee3bf73f291159 \ + --hash=sha256:ca825f4eecb8c342d2ec581e6a5ad1ad1a47bededaecd768e0d3451ae4aaac2b \ + --hash=sha256:dfd29f6eb34107dccf289a93d44fb6b131e68888d090b784b691775ac84e8213 \ + --hash=sha256:e184175276edc222e2d5e314a72521e10049938a9a4961fe4bea9b25d073c03f \ + --hash=sha256:efd4f5894c50bd76cbcfdd668cd941021333861ed0f441c78a83d8254a01cc9f \ + --hash=sha256:f9ecc8eb6f18037e0cbf43256db0325d4723f429bca7ef5cd358b7c29d65f628 # via -r requirements.txt -urllib3==1.26.18 \ - --hash=sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07 \ - --hash=sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0 - # via requests diff --git a/{{ .ProjectSnake }}/tools/toolchains/BUILD.bazel b/{{ .ProjectSnake }}/tools/toolchains/BUILD.bazel new file mode 100644 index 0000000..86ac7d9 --- /dev/null +++ b/{{ .ProjectSnake }}/tools/toolchains/BUILD.bazel @@ -0,0 +1,14 @@ +{{- if .Scaffold.protobuf }} +load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") + +{{- if .Computed.python }} +# Configure protoc to have the right arguments for generating Python stubs. +proto_lang_toolchain( + name = "protoc_py_toolchain", + command_line = "--python_out=%s", + progress_message = "Generating Python proto_library %{label}", + runtime = "@pip//protobuf", + toolchain_type = "@rules_python//python/proto:toolchain_type", +) +{{- end}} +{{- end}} \ No newline at end of file