Skip to content

Commit 4b193df

Browse files
authored
Merge pull request #622 from tweag/mp/cc_toolchain_vendoring
vendor large parts of @bazel_tools//tools/cpp
2 parents 0a75d71 + 598f403 commit 4b193df

18 files changed

+4092
-69
lines changed

core/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package(default_visibility = ["//visibility:public"])
44

55
filegroup(
66
name = "srcs",
7-
srcs = glob(["**"]),
7+
srcs = glob(["**"]) + ["//private/cc_toolchain:srcs"],
88
visibility = ["//visibility:public"],
99
)
1010

@@ -24,9 +24,9 @@ bzl_library(
2424
bzl_library(
2525
name = "nixpkgs",
2626
srcs = [
27+
"//private/cc_toolchain:srcs",
2728
"nixpkgs.bzl",
2829
"util.bzl",
29-
"private/get_cpu_value.bzl",
3030
],
3131
deps = [
3232
":bazel_tools",

core/private/BUILD.bazel

Whitespace-only changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2018 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
package(default_visibility = ["//visibility:public"])
17+
18+
licenses(["notice"]) # Apache 2.0
19+
20+
filegroup(
21+
name = "empty",
22+
srcs = [],
23+
)
24+
25+
filegroup(
26+
name = "bzl_srcs",
27+
srcs = glob(["**/*.bzl"]),
28+
)
29+
30+
filegroup(
31+
name = "srcs",
32+
srcs = glob(["**"]),
33+
)
34+
35+
filegroup(
36+
name = "lib_cc_configure",
37+
srcs = ["lib_cc_configure.bzl"],
38+
)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Copyright 2016 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This becomes the BUILD file for @local_config_cc// under non-BSD unixes.
16+
17+
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
18+
load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config")
19+
load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite")
20+
21+
package(default_visibility = ["//visibility:public"])
22+
23+
licenses(["notice"]) # Apache 2.0
24+
25+
cc_library(name = "empty_lib")
26+
27+
# Label flag for extra libraries to be linked into every binary.
28+
# TODO(bazel-team): Support passing flag multiple times to build a list.
29+
label_flag(
30+
name = "link_extra_libs",
31+
build_setting_default = ":empty_lib",
32+
)
33+
34+
# The final extra library to be linked into every binary target. This collects
35+
# the above flag, but may also include more libraries depending on config.
36+
cc_library(
37+
name = "link_extra_lib",
38+
deps = [
39+
":link_extra_libs",
40+
],
41+
)
42+
43+
cc_library(
44+
name = "malloc",
45+
)
46+
47+
filegroup(
48+
name = "empty",
49+
srcs = [],
50+
)
51+
52+
filegroup(
53+
name = "cc_wrapper",
54+
srcs = ["cc_wrapper.sh"],
55+
)
56+
57+
filegroup(
58+
name = "validate_static_library",
59+
srcs = ["validate_static_library.sh"],
60+
)
61+
62+
filegroup(
63+
name = "deps_scanner_wrapper",
64+
srcs = ["deps_scanner_wrapper.sh"],
65+
)
66+
filegroup(
67+
name = "compiler_deps",
68+
srcs = glob(["extra_tools/**"], allow_empty = True) + [%{cc_compiler_deps}],
69+
)
70+
71+
# This is the entry point for --crosstool_top. Toolchains are found
72+
# by lopping off the name of --crosstool_top and searching for
73+
# the "${CPU}" entry in the toolchains attribute.
74+
cc_toolchain_suite(
75+
name = "toolchain",
76+
toolchains = {
77+
"%{name}|%{compiler}": ":cc-compiler-%{name}",
78+
"%{name}": ":cc-compiler-%{name}",
79+
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
80+
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
81+
},
82+
)
83+
84+
cc_toolchain(
85+
name = "cc-compiler-%{name}",
86+
toolchain_identifier = "%{cc_toolchain_identifier}",
87+
toolchain_config = ":%{cc_toolchain_identifier}",
88+
all_files = ":compiler_deps",
89+
ar_files = ":compiler_deps",
90+
as_files = ":compiler_deps",
91+
compiler_files = ":compiler_deps",
92+
dwp_files = ":empty",
93+
linker_files = ":compiler_deps",
94+
objcopy_files = ":empty",
95+
strip_files = ":empty",
96+
supports_header_parsing = 1,
97+
supports_param_files = 1,
98+
module_map = %{modulemap},
99+
)
100+
101+
cc_toolchain_config(
102+
name = "%{cc_toolchain_identifier}",
103+
cpu = "%{target_cpu}",
104+
compiler = "%{compiler}",
105+
toolchain_identifier = "%{cc_toolchain_identifier}",
106+
host_system_name = "%{host_system_name}",
107+
target_system_name = "%{target_system_name}",
108+
target_libc = "%{target_libc}",
109+
abi_version = "%{abi_version}",
110+
abi_libc_version = "%{abi_libc_version}",
111+
cxx_builtin_include_directories = [%{cxx_builtin_include_directories}],
112+
tool_paths = {%{tool_paths}},
113+
compile_flags = [%{compile_flags}],
114+
opt_compile_flags = [%{opt_compile_flags}],
115+
dbg_compile_flags = [%{dbg_compile_flags}],
116+
cxx_flags = [%{cxx_flags}],
117+
link_flags = [%{link_flags}],
118+
link_libs = [%{link_libs}],
119+
opt_link_flags = [%{opt_link_flags}],
120+
unfiltered_compile_flags = [%{unfiltered_compile_flags}],
121+
coverage_compile_flags = [%{coverage_compile_flags}],
122+
coverage_link_flags = [%{coverage_link_flags}],
123+
supports_start_end_lib = %{supports_start_end_lib},
124+
)
125+
126+
# Android tooling requires a default toolchain for the armeabi-v7a cpu.
127+
cc_toolchain(
128+
name = "cc-compiler-armeabi-v7a",
129+
toolchain_identifier = "stub_armeabi-v7a",
130+
toolchain_config = ":stub_armeabi-v7a",
131+
all_files = ":empty",
132+
ar_files = ":empty",
133+
as_files = ":empty",
134+
compiler_files = ":empty",
135+
dwp_files = ":empty",
136+
linker_files = ":empty",
137+
objcopy_files = ":empty",
138+
strip_files = ":empty",
139+
supports_param_files = 1,
140+
)
141+
142+
armeabi_cc_toolchain_config(name = "stub_armeabi-v7a")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Vendored files from `@bazel_tools//tools/cpp` that were removed in Bazel 8
2+
3+
This directory contains files that rules_nixpkgs depends on that once lived in `@bazel_tools`.
4+
Do not add other files here unless needed.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright 2019 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A Starlark cc_toolchain configuration rule"""
16+
17+
load(
18+
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
19+
"feature",
20+
"tool_path",
21+
)
22+
23+
def _impl(ctx):
24+
toolchain_identifier = "stub_armeabi-v7a"
25+
host_system_name = "armeabi-v7a"
26+
target_system_name = "armeabi-v7a"
27+
target_cpu = "armeabi-v7a"
28+
target_libc = "armeabi-v7a"
29+
compiler = "compiler"
30+
abi_version = "armeabi-v7a"
31+
abi_libc_version = "armeabi-v7a"
32+
cc_target_os = None
33+
builtin_sysroot = None
34+
action_configs = []
35+
36+
supports_pic_feature = feature(name = "supports_pic", enabled = True)
37+
supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True)
38+
features = [supports_dynamic_linker_feature, supports_pic_feature]
39+
40+
cxx_builtin_include_directories = []
41+
artifact_name_patterns = []
42+
make_variables = []
43+
44+
tool_paths = [
45+
tool_path(name = "ar", path = "/bin/false"),
46+
tool_path(name = "compat-ld", path = "/bin/false"),
47+
tool_path(name = "cpp", path = "/bin/false"),
48+
tool_path(name = "dwp", path = "/bin/false"),
49+
tool_path(name = "gcc", path = "/bin/false"),
50+
tool_path(name = "gcov", path = "/bin/false"),
51+
tool_path(name = "ld", path = "/bin/false"),
52+
tool_path(name = "llvm-profdata", path = "/bin/false"),
53+
tool_path(name = "nm", path = "/bin/false"),
54+
tool_path(name = "objcopy", path = "/bin/false"),
55+
tool_path(name = "objdump", path = "/bin/false"),
56+
tool_path(name = "strip", path = "/bin/false"),
57+
]
58+
59+
return cc_common.create_cc_toolchain_config_info(
60+
ctx = ctx,
61+
features = features,
62+
action_configs = action_configs,
63+
artifact_name_patterns = artifact_name_patterns,
64+
cxx_builtin_include_directories = cxx_builtin_include_directories,
65+
toolchain_identifier = toolchain_identifier,
66+
host_system_name = host_system_name,
67+
target_system_name = target_system_name,
68+
target_cpu = target_cpu,
69+
target_libc = target_libc,
70+
compiler = compiler,
71+
abi_version = abi_version,
72+
abi_libc_version = abi_libc_version,
73+
tool_paths = tool_paths,
74+
make_variables = make_variables,
75+
builtin_sysroot = builtin_sysroot,
76+
cc_target_os = cc_target_os,
77+
)
78+
79+
armeabi_cc_toolchain_config = rule(
80+
implementation = _impl,
81+
attrs = {},
82+
provides = [CcToolchainConfigInfo],
83+
)

0 commit comments

Comments
 (0)