Skip to content

Commit 854d86b

Browse files
authored
Merge pull request #9640 from protocolbuffers/toolchainCleanup
Toolchain cleanups
2 parents 40cb0e4 + faae704 commit 854d86b

File tree

2 files changed

+9
-37
lines changed

2 files changed

+9
-37
lines changed

toolchain/BUILD

-29
Original file line numberDiff line numberDiff line change
@@ -41,95 +41,70 @@ cc_toolchain_suite(
4141

4242
cc_toolchain_config(
4343
name = "linux-aarch_64-config",
44-
bit_flag = "-m64",
45-
cpp_flag = "-lstdc++",
4644
sysroot = "/opt/manylinux/2014/aarch64",
4745
linker_path = "/usr/bin/ld",
4846
target_cpu = "aarch64",
4947
target_full_name = "aarch64-linux-gnu",
50-
toolchain_name = "linux_aarch_64",
5148
)
5249

5350
cc_toolchain_config(
5451
name = "linux-ppcle_64-config",
55-
bit_flag = "-m64",
56-
cpp_flag = "-lstdc++",
5752
linker_path = "/usr/bin/ld",
5853
sysroot = "/opt/manylinux/2014/ppc64le",
5954
target_cpu = "ppc64",
6055
target_full_name = "powerpc64le-linux-gnu",
61-
toolchain_name = "linux_ppcle_64",
6256
)
6357

6458
cc_toolchain_config(
6559
name = "linux-s390_64-config",
66-
bit_flag = "-m64",
67-
cpp_flag = "-lstdc++",
6860
linker_path = "/usr/bin/ld",
6961
sysroot = "/opt/manylinux/2014/s390x",
7062
target_cpu = "systemz",
7163
target_full_name = "s390x-linux-gnu",
72-
toolchain_name = "linux_s390_64",
7364
)
7465

7566
cc_toolchain_config(
7667
name = "linux-x86_32-config",
77-
bit_flag = "-m32",
78-
cpp_flag = "-lstdc++",
7968
linker_path = "/usr/bin/ld",
8069
sysroot = "/opt/manylinux/2014/i686",
8170
target_cpu = "x86_32",
8271
target_full_name = "i386-linux-gnu",
83-
toolchain_name = "linux_x86_32",
8472
)
8573

8674
cc_toolchain_config(
8775
name = "linux-x86_64-config",
88-
bit_flag = "-m64",
89-
cpp_flag = "-lstdc++",
9076
linker_path = "/usr/bin/ld",
9177
sysroot = "/opt/manylinux/2014/x86_64",
9278
target_cpu = "x86_64",
9379
target_full_name = "x86_64-linux-gnu",
94-
toolchain_name = "linux_x86_64",
9580
)
9681

9782
cc_toolchain_config(
9883
name = "osx-aarch_64-config",
99-
bit_flag = "-m64",
100-
cpp_flag = "-lc++",
10184
extra_compiler_flags = [
10285
"-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1",
10386
"-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include"
10487
],
105-
extra_include = "/usr/include",
10688
linker_path = "/usr/tools",
10789
sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx",
10890
target_cpu = "aarch64",
10991
target_full_name = "aarch64-apple-macosx11.3",
110-
toolchain_name = "osx_aarch_64",
11192
)
11293

11394
cc_toolchain_config(
11495
name = "osx-x86_64-config",
115-
bit_flag = "-m64",
116-
cpp_flag = "-lc++",
11796
extra_compiler_flags = [
11897
"-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include/c++/v1",
11998
"-I/usr/tools/apple_sdks/xcode_13_0/macosx/usr/include"
12099
],
121-
extra_include = "/usr/include",
122100
linker_path = "/usr/tools",
123101
sysroot = "/usr/tools/apple_sdks/xcode_13_0/macosx",
124102
target_cpu = "x86_64",
125103
target_full_name = "x86_64-apple-macosx11.3",
126-
toolchain_name = "osx_x86_64",
127104
)
128105

129106
cc_toolchain_config(
130107
name = "win32-config",
131-
bit_flag = "-m32",
132-
cpp_flag = "-lstdc++",
133108
extra_compiler_flags = [
134109
"-isystem/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++",
135110
"-isystem/usr/lib/gcc/i686-w64-mingw32/8.3-posix/include/c++/i686-w64-mingw32",
@@ -144,13 +119,10 @@ cc_toolchain_config(
144119
sysroot = "/usr/i686-w64-mingw32",
145120
target_cpu = "x86_32",
146121
target_full_name = "i686-w64-mingw32",
147-
toolchain_name = "i686-w64-mingw32",
148122
)
149123

150124
cc_toolchain_config(
151125
name = "win64-config",
152-
bit_flag = "-m64",
153-
cpp_flag = "-lstdc++",
154126
extra_compiler_flags = [
155127
"-isystem/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/",
156128
"-isystem/usr/lib/gcc/x86_64-w64-mingw32/8.3-posix/include/c++/x86_64-w64-mingw32",
@@ -163,5 +135,4 @@ cc_toolchain_config(
163135
sysroot = "/usr/x86_64-w64-mingw32",
164136
target_cpu = "x86_64",
165137
target_full_name = "x86_64-w64-mingw32",
166-
toolchain_name = "x86_64-w64-mingw32",
167138
)

toolchain/cc_toolchain_config.bzl

+9-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ all_compile_actions = [
2828
]
2929

3030
def _impl(ctx):
31-
if 'mingw' in ctx.attr.target_full_name:
31+
if "mingw" in ctx.attr.target_full_name:
3232
artifact_name_patterns = [
3333
artifact_name_pattern(
3434
category_name = "executable",
@@ -96,7 +96,7 @@ def _impl(ctx):
9696
flag_group(
9797
flags = [
9898
"-B" + ctx.attr.linker_path,
99-
ctx.attr.cpp_flag,
99+
"-lstdc++",
100100
"--target=" + ctx.attr.target_full_name,
101101
] + ctx.attr.extra_linker_flags,
102102
),
@@ -105,7 +105,7 @@ def _impl(ctx):
105105
],
106106
)
107107

108-
if 'osx' in ctx.attr.target_full_name:
108+
if "osx" in ctx.attr.target_full_name:
109109
sysroot_action_set = all_link_actions
110110
else:
111111
sysroot_action_set = all_link_actions + all_compile_actions
@@ -129,6 +129,10 @@ def _impl(ctx):
129129
],
130130
)
131131

132+
if ctx.attr.target_cpu == "x86_32":
133+
bit_flag = "-m32"
134+
else:
135+
bit_flag = "-m64"
132136
compiler_flags = feature(
133137
name = "default_compile_flags",
134138
enabled = True,
@@ -138,7 +142,7 @@ def _impl(ctx):
138142
flag_groups = [
139143
flag_group(
140144
flags = [
141-
ctx.attr.bit_flag,
145+
bit_flag,
142146
"-Wall",
143147
"-no-canonical-prefixes",
144148
"--target=" + ctx.attr.target_full_name,
@@ -170,24 +174,21 @@ def _impl(ctx):
170174
target_cpu = ctx.attr.target_cpu,
171175
target_libc = ctx.attr.target_cpu,
172176
target_system_name = ctx.attr.target_full_name,
173-
toolchain_identifier = ctx.attr.toolchain_name,
177+
toolchain_identifier = ctx.attr.target_full_name,
174178
tool_paths = tool_paths,
175179
)
176180

177181
cc_toolchain_config = rule(
178182
implementation = _impl,
179183
attrs = {
180184
"abi_version": attr.string(default = "local"),
181-
"bit_flag": attr.string(mandatory = True, values = ["-m32", "-m64"]),
182-
"cpp_flag": attr.string(mandatory = True),
183185
"extra_compiler_flags": attr.string_list(),
184186
"extra_include": attr.string(mandatory = False),
185187
"extra_linker_flags": attr.string_list(),
186188
"linker_path": attr.string(mandatory = True),
187189
"sysroot": attr.string(mandatory = False),
188190
"target_cpu": attr.string(mandatory = True, values = ["aarch64", "ppc64", "systemz", "x86_32", "x86_64"]),
189191
"target_full_name": attr.string(mandatory = True),
190-
"toolchain_name": attr.string(mandatory = True),
191192
},
192193
provides = [CcToolchainConfigInfo],
193194
)

0 commit comments

Comments
 (0)