Skip to content

Commit

Permalink
Add a compiler_flag rule that exposes the value of the "compiler" fie…
Browse files Browse the repository at this point in the history
…ld of CROSSTOOL

RELNOTES: None
PiperOrigin-RevId: 198295290
  • Loading branch information
scentini authored and Copybara-Service committed May 28, 2018
1 parent eca7b81 commit 8044286
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,7 @@ filegroup(
name = "crosstool_lib",
srcs = ["crosstool_lib.bzl"],
)

load(":compiler_flag.bzl", "compiler_flag")

compiler_flag(name = "compiler")
28 changes: 28 additions & 0 deletions tools/cpp/compiler_flag.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2018 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.

"""Rule that allows select() to differentiate between compilers."""

load("//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")

def _compiler_flag_impl(ctx):
toolchain = find_cpp_toolchain(ctx)
return [config_common.FeatureFlagInfo(value = toolchain.compiler)]

compiler_flag = rule(
implementation = _compiler_flag_impl,
attrs = {
"_cc_toolchain": attr.label(default=Label("//tools/cpp:current_cc_toolchain")),
}
)
1 change: 1 addition & 0 deletions tools/cpp/toolchain_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _make_legacy_toolchain(ctx):
ar_executable = _get_cpp_toolchain_attr(ctx, "ar_executable"),
strip_executable = _get_cpp_toolchain_attr(ctx, "strip_executable"),
ld_executable = _get_cpp_toolchain_attr(ctx, "ld_executable"),
compiler = _get_cpp_toolchain_attr(ctx, "compiler"),
)

def find_cpp_toolchain(ctx):
Expand Down

0 comments on commit 8044286

Please sign in to comment.