Skip to content

Commit

Permalink
Add a fake cc_toolchain_config rule for our fake cc_toolchain to poin…
Browse files Browse the repository at this point in the history
…t to when Bazel doesn't need C++ toolchain configuration

The toolchain configuration rule we are currently relying on will be removed as part of #8546

RELNOTES: None.
PiperOrigin-RevId: 262952632
  • Loading branch information
scentini authored and copybara-github committed Aug 12, 2019
1 parent 2fc2e2b commit 3fd5129
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
8 changes: 2 additions & 6 deletions tools/cpp/BUILD.empty
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package(default_visibility = ["//visibility:public"])

load("@bazel_tools//tools/cpp:cc_toolchain_config.bzl", "cc_toolchain_config")
load(":cc_toolchain_config.bzl", "cc_toolchain_config")

cc_library(
name = "malloc",
Expand Down Expand Up @@ -47,8 +47,4 @@ cc_toolchain(
strip_files = ":empty",
)

cc_toolchain_config(
name = "local_config",
cpu = "local",
compiler = "compiler",
)
cc_toolchain_config(name = "local_config")
11 changes: 6 additions & 5 deletions tools/cpp/cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,16 @@ def cc_autoconf_impl(repository_ctx, overriden_tools = dict()):
repository_ctx: repository context
overriden_tools: dict of tool paths to use instead of autoconfigured tools
"""
paths = resolve_labels(repository_ctx, [
"@bazel_tools//tools/cpp:cc_toolchain_config.bzl",
])

env = repository_ctx.os.environ
cpu_value = get_cpu_value(repository_ctx)
if "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1":
repository_ctx.symlink(paths["@bazel_tools//tools/cpp:cc_toolchain_config.bzl"], "cc_toolchain_config.bzl")
repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.empty"), "BUILD")
paths = resolve_labels(repository_ctx, [
"@bazel_tools//tools/cpp:BUILD.empty",
"@bazel_tools//tools/cpp:empty_cc_toolchain_config.bzl",
])
repository_ctx.symlink(paths["@bazel_tools//tools/cpp:empty_cc_toolchain_config.bzl"], "cc_toolchain_config.bzl")
repository_ctx.symlink(paths("@bazel_tools//tools/cpp:BUILD.empty"), "BUILD")
elif cpu_value == "freebsd":
paths = resolve_labels(repository_ctx, [
"@bazel_tools//tools/cpp:BUILD.static.freebsd",
Expand Down
42 changes: 42 additions & 0 deletions tools/cpp/empty_cc_toolchain_config.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.

"""A fake C++ toolchain configuration rule"""

def _impl(ctx):
out = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(out, "Fake executable")
return [
cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = "local_linux",
host_system_name = "local",
target_system_name = "local",
target_cpu = "local",
target_libc = "local",
compiler = "compiler",
abi_version = "local",
abi_libc_version = "local",
),
DefaultInfo(
executable = out,
),
]

cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
executable = True,
)

0 comments on commit 3fd5129

Please sign in to comment.