Skip to content

Commit

Permalink
Wrap proto_lang_toolchain into a macro creating a toolchain
Browse files Browse the repository at this point in the history
Issue: #179
PiperOrigin-RevId: 566975629
  • Loading branch information
A Googler authored and Blaze Rules Copybara committed Sep 20, 2023
1 parent bb745f9 commit 673e59e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
15 changes: 3 additions & 12 deletions proto/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

"""Starlark rules for building protocol buffers."""

load("//proto:proto_lang_toolchain.bzl", _proto_lang_toolchain = "proto_lang_toolchain")
load("//proto/private:native.bzl", "NativeProtoInfo", "native_proto_common")
load("//proto/private/rules:proto_descriptor_set.bzl", _proto_descriptor_set = "proto_descriptor_set")

Expand All @@ -26,18 +27,6 @@ def _add_migration_tag(attrs):
attrs["tags"] = [_MIGRATION_TAG]
return attrs

def proto_lang_toolchain(**attrs):
"""Bazel proto_lang_toolchain rule.
https://docs.bazel.build/versions/master/be/protocol-buffer.html#proto_lang_toolchain
Args:
**attrs: Rule attributes
"""

# buildifier: disable=native-proto
native.proto_lang_toolchain(**_add_migration_tag(attrs))

def proto_library(**attrs):
"""Bazel proto_library rule.
Expand All @@ -52,6 +41,8 @@ def proto_library(**attrs):

proto_descriptor_set = _proto_descriptor_set

proto_lang_toolchain = _proto_lang_toolchain

# Encapsulates information provided by `proto_library`.
#
# https://docs.bazel.build/versions/master/skylark/lib/ProtoInfo.html
Expand Down
42 changes: 42 additions & 0 deletions proto/proto_lang_toolchain.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2019 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""proto_lang_toolchain rule"""

def proto_lang_toolchain(*, name, toolchain_type = None, exec_compatible_with = [], target_compatible_with = [], **attrs):
"""Creates a proto_lang_toolchain and corresponding toolchain target.
Toolchain target is only created when toolchain_type is set.
https://docs.bazel.build/versions/master/be/protocol-buffer.html#proto_lang_toolchain
Args:
name: name of the toolchain
toolchain_type: The toolchain type
exec_compatible_with: ([constraints]) List of constraints the prebuild binaries is compatible with.
target_compatible_with: ([constraints]) List of constraints the target libraries are compatible with.
**attrs: Rule attributes
"""

# buildifier: disable=native-proto
native.proto_lang_toolchain(name = name, **attrs)

if toolchain_type:
native.toolchain(
name = name + "_toolchain",
toolchain_type = toolchain_type,
exec_compatible_with = exec_compatible_with,
target_compatible_with = target_compatible_with,
toolchain = name,
)

0 comments on commit 673e59e

Please sign in to comment.