Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor large parts of @bazel_tools//tools/cpp #622

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
srcs = glob(["**"]) + ["//private/cc_toolchain:srcs"],
visibility = ["//visibility:public"],
)

Expand All @@ -24,9 +24,9 @@ bzl_library(
bzl_library(
name = "nixpkgs",
srcs = [
"//private/cc_toolchain:srcs",
"nixpkgs.bzl",
"util.bzl",
"private/get_cpu_value.bzl",
],
deps = [
":bazel_tools",
Expand Down
Empty file added core/private/BUILD.bazel
Empty file.
38 changes: 38 additions & 0 deletions core/private/cc_toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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.
#

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

licenses(["notice"]) # Apache 2.0

filegroup(
name = "empty",
srcs = [],
)

filegroup(
name = "bzl_srcs",
srcs = glob(["**/*.bzl"]),
)

filegroup(
name = "srcs",
srcs = glob(["**"]),
)

filegroup(
name = "lib_cc_configure",
srcs = ["lib_cc_configure.bzl"],
)
142 changes: 142 additions & 0 deletions core/private/cc_toolchain/BUILD.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Copyright 2016 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.

# This becomes the BUILD file for @local_config_cc// under non-BSD unixes.

load(":cc_toolchain_config.bzl", "cc_toolchain_config")
load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config")
load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite")

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

licenses(["notice"]) # Apache 2.0

cc_library(name = "empty_lib")

# Label flag for extra libraries to be linked into every binary.
# TODO(bazel-team): Support passing flag multiple times to build a list.
label_flag(
name = "link_extra_libs",
build_setting_default = ":empty_lib",
)

# The final extra library to be linked into every binary target. This collects
# the above flag, but may also include more libraries depending on config.
cc_library(
name = "link_extra_lib",
deps = [
":link_extra_libs",
],
)

cc_library(
name = "malloc",
)

filegroup(
name = "empty",
srcs = [],
)

filegroup(
name = "cc_wrapper",
srcs = ["cc_wrapper.sh"],
)

filegroup(
name = "validate_static_library",
srcs = ["validate_static_library.sh"],
)

filegroup(
name = "deps_scanner_wrapper",
srcs = ["deps_scanner_wrapper.sh"],
)
filegroup(
name = "compiler_deps",
srcs = glob(["extra_tools/**"], allow_empty = True) + [%{cc_compiler_deps}],
)

# This is the entry point for --crosstool_top. Toolchains are found
# by lopping off the name of --crosstool_top and searching for
# the "${CPU}" entry in the toolchains attribute.
cc_toolchain_suite(
name = "toolchain",
toolchains = {
"%{name}|%{compiler}": ":cc-compiler-%{name}",
"%{name}": ":cc-compiler-%{name}",
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
},
)

cc_toolchain(
name = "cc-compiler-%{name}",
toolchain_identifier = "%{cc_toolchain_identifier}",
toolchain_config = ":%{cc_toolchain_identifier}",
all_files = ":compiler_deps",
ar_files = ":compiler_deps",
as_files = ":compiler_deps",
compiler_files = ":compiler_deps",
dwp_files = ":empty",
linker_files = ":compiler_deps",
objcopy_files = ":empty",
strip_files = ":empty",
supports_header_parsing = 1,
supports_param_files = 1,
module_map = %{modulemap},
)

cc_toolchain_config(
name = "%{cc_toolchain_identifier}",
cpu = "%{target_cpu}",
compiler = "%{compiler}",
toolchain_identifier = "%{cc_toolchain_identifier}",
host_system_name = "%{host_system_name}",
target_system_name = "%{target_system_name}",
target_libc = "%{target_libc}",
abi_version = "%{abi_version}",
abi_libc_version = "%{abi_libc_version}",
cxx_builtin_include_directories = [%{cxx_builtin_include_directories}],
tool_paths = {%{tool_paths}},
compile_flags = [%{compile_flags}],
opt_compile_flags = [%{opt_compile_flags}],
dbg_compile_flags = [%{dbg_compile_flags}],
cxx_flags = [%{cxx_flags}],
link_flags = [%{link_flags}],
link_libs = [%{link_libs}],
opt_link_flags = [%{opt_link_flags}],
unfiltered_compile_flags = [%{unfiltered_compile_flags}],
coverage_compile_flags = [%{coverage_compile_flags}],
coverage_link_flags = [%{coverage_link_flags}],
supports_start_end_lib = %{supports_start_end_lib},
)

# Android tooling requires a default toolchain for the armeabi-v7a cpu.
cc_toolchain(
name = "cc-compiler-armeabi-v7a",
toolchain_identifier = "stub_armeabi-v7a",
toolchain_config = ":stub_armeabi-v7a",
all_files = ":empty",
ar_files = ":empty",
as_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
)

armeabi_cc_toolchain_config(name = "stub_armeabi-v7a")
4 changes: 4 additions & 0 deletions core/private/cc_toolchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Vendored files from `@bazel_tools//tools/cpp` that were removed in Bazel 8

This directory contains files that rules_nixpkgs depends on that once lived in `@bazel_tools`.
Do not add other files here unless needed.
83 changes: 83 additions & 0 deletions core/private/cc_toolchain/armeabi_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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 Starlark cc_toolchain configuration rule"""

load(
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
"feature",
"tool_path",
)

def _impl(ctx):
toolchain_identifier = "stub_armeabi-v7a"
host_system_name = "armeabi-v7a"
target_system_name = "armeabi-v7a"
target_cpu = "armeabi-v7a"
target_libc = "armeabi-v7a"
compiler = "compiler"
abi_version = "armeabi-v7a"
abi_libc_version = "armeabi-v7a"
cc_target_os = None
builtin_sysroot = None
action_configs = []

supports_pic_feature = feature(name = "supports_pic", enabled = True)
supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
features = [supports_dynamic_linker_feature, supports_pic_feature]

cxx_builtin_include_directories = []
artifact_name_patterns = []
make_variables = []

tool_paths = [
tool_path(name = "ar", path = "/bin/false"),
tool_path(name = "compat-ld", path = "/bin/false"),
tool_path(name = "cpp", path = "/bin/false"),
tool_path(name = "dwp", path = "/bin/false"),
tool_path(name = "gcc", path = "/bin/false"),
tool_path(name = "gcov", path = "/bin/false"),
tool_path(name = "ld", path = "/bin/false"),
tool_path(name = "llvm-profdata", path = "/bin/false"),
tool_path(name = "nm", path = "/bin/false"),
tool_path(name = "objcopy", path = "/bin/false"),
tool_path(name = "objdump", path = "/bin/false"),
tool_path(name = "strip", path = "/bin/false"),
]

return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
features = features,
action_configs = action_configs,
artifact_name_patterns = artifact_name_patterns,
cxx_builtin_include_directories = cxx_builtin_include_directories,
toolchain_identifier = toolchain_identifier,
host_system_name = host_system_name,
target_system_name = target_system_name,
target_cpu = target_cpu,
target_libc = target_libc,
compiler = compiler,
abi_version = abi_version,
abi_libc_version = abi_libc_version,
tool_paths = tool_paths,
make_variables = make_variables,
builtin_sysroot = builtin_sysroot,
cc_target_os = cc_target_os,
)

armeabi_cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)
Loading
Loading