Skip to content

Commit

Permalink
bazel: Migrate from WORKSPACE to bzlmod (nanopb#950)
Browse files Browse the repository at this point in the history
The bazel build system is migrating to a new way of
defining modules. To support this, nanopb bazel
build rules have been updated.

Co-authored-by: Mark Hill <markleehill@gmail.com>
  • Loading branch information
2 people authored and PetteriAimonen committed Apr 19, 2024
1 parent 671672b commit f6187b0
Show file tree
Hide file tree
Showing 13 changed files with 2,632 additions and 64 deletions.
1 change: 1 addition & 0 deletions .bazelignore
@@ -0,0 +1 @@
tests/bazel_workspace_support
3 changes: 3 additions & 0 deletions .gitattributes
@@ -0,0 +1,3 @@
# Auto-generated files that don't need human review.
MODULE.bazel.lock linguist-generated=true
extra/requirements_lock.txt linguist-generated=true
2 changes: 1 addition & 1 deletion .github/workflows/bazel.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-11]
os: [ubuntu-20.04, macos-14]

steps:
- uses: actions/checkout@v2
Expand Down
15 changes: 13 additions & 2 deletions BUILD.bazel
@@ -1,5 +1,8 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:defs.bzl", "py_binary")

# Note: if you are still using WORKSPACE, you will need to patch this file to use the following instead
# load("@python_3_11//:defs.bzl", "py_binary")
load("@python_versions//3.11:defs.bzl", "py_binary")
load("@nanopb_pypi//:requirements.bzl", "requirement")
load("@rules_proto_grpc//:defs.bzl", "proto_plugin")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
Expand Down Expand Up @@ -82,13 +85,21 @@ proto_library(
deps = ["@com_google_protobuf//:descriptor_proto"],
)

py_proto_library(
name = "descriptor_py_proto",
srcs = [
"generator/proto/google/protobuf/descriptor.proto",
],
include = "generator/proto",
)

py_proto_library(
name = "nanopb_py_proto",
srcs = [
"generator/proto/nanopb.proto",
],
include = "generator/proto",
deps = ["@com_google_protobuf//:protobuf_python"],
deps = [":descriptor_py_proto"],
)

cc_nanopb_proto_library(
Expand Down
38 changes: 38 additions & 0 deletions MODULE.bazel
@@ -0,0 +1,38 @@
module(
name = "nanopb",
version = "0.4.9",
)

bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_python", version = "0.31.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "protobuf", version = "23.1", repo_name = "com_google_protobuf")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")

PYTHON_VERSION = "3.11"

# No need for this since rules_python already creates our version.
# python.toolchain(python_version = PYTHON_VERSION)
use_repo(python, "python_versions")

use_repo(pip, "nanopb_pypi")
pip.parse(
hub_name = "nanopb_pypi",
python_version = PYTHON_VERSION,
requirements_lock = "@nanopb//:extra/requirements_lock.txt",
)

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_proto_grpc",
sha256 = "c0d718f4d892c524025504e67a5bfe83360b3a982e654bc71fed7514eb8ac8ad",
strip_prefix = "rules_proto_grpc-4.6.0",
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/4.6.0.tar.gz"],
)

register_toolchains("@rules_proto_grpc//protobuf:protoc_toolchain")

0 comments on commit f6187b0

Please sign in to comment.