forked from bazelbuild/rules_proto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
proto_toolchain
and expose values of command-line flags on it
Working towards bazelbuild/bazel#10005
- Loading branch information
Showing
5 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
# Intentionally left empty (for now). | ||
load("//proto:defs.bzl", "proto_toolchain") | ||
|
||
toolchain_type( | ||
name = "toolchain", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
proto_toolchain( | ||
name = "default_toolchain_impl", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
toolchain( | ||
name = "default_toolchain", | ||
toolchain = ":default_toolchain_impl", | ||
toolchain_type = "@rules_proto//proto:toolchain", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intentionally left empty (for now). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 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. | ||
|
||
load("//proto/private:native.bzl", "native_proto_common") | ||
|
||
_has_protoc_key = "has_protoc_do_not_use_or_we_will_break_you_without_mercy" | ||
_protoc_key = "protoc_do_not_use_or_we_will_break_you_without_mercy" | ||
_protocopt_key = "protocopt_do_not_use_or_we_will_break_you_without_mercy" | ||
_strict_deps_key = "strict_deps_do_not_use_or_we_will_break_you_without_mercy" | ||
|
||
def _proto_toolchain_impl(ctx): | ||
config = ctx.fragments.proto | ||
return [ | ||
platform_common.ToolchainInfo( | ||
compiler = ctx.attr._compiler.files_to_run, | ||
compiler_options = getattr(config, _protocopt_key, []), | ||
strict_deps = getattr(config, _strict_deps_key, "ERROR"), | ||
), | ||
] | ||
|
||
def _compiler_default_value(): | ||
"""Returns the value of `--proto_compiler`, or it's default value in case | ||
Bazel does not support accessing the actual value. | ||
Returns: The value of `--proto_compiler`. | ||
""" | ||
|
||
if not hasattr(native_proto_common, _has_protoc_key): | ||
# Use a sane default in case the value of `--proto_compiler` is not | ||
# available. | ||
return "@com_google_protobuf//:protoc" | ||
|
||
return configuration_field("proto", _protoc_key) | ||
|
||
proto_toolchain = rule( | ||
implementation = _proto_toolchain_impl, | ||
attrs = { | ||
# Currently configured by `--proto_compiler`. | ||
"_compiler": attr.label( | ||
mandatory = False, | ||
executable = True, | ||
cfg = "host", | ||
default = _compiler_default_value(), | ||
), | ||
}, | ||
fragments = [ | ||
"proto", | ||
], | ||
provides = [ | ||
platform_common.ToolchainInfo, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters