Skip to content

Commit 44bf357

Browse files
laramielcopybara-github
authored andcommitted
Improve bazel os / cpu/ compiler config sets
PiperOrigin-RevId: 651485656 Change-Id: Ie87063e2ad0ea3ebe9a37b3ece5f248489488c85
1 parent b95be26 commit 44bf357

6 files changed

Lines changed: 137 additions & 231 deletions

File tree

BUILD.bazel

Lines changed: 88 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_skylib//lib:selects.bzl", "selects")
2+
load("@tensorstore//bazel:utils.bzl", "emit_os_cpu_compiler_group")
23

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

@@ -13,182 +14,103 @@ exports_files(glob(["*"]))
1314
# actual = "@tensorstore//:{target}".format(target = name),
1415
# )
1516
# for name in [
17+
# "arm64_clang",
18+
# "arm64_gcc_or_clang",
19+
# "arm64_gcc",
20+
# "arm64_mingw_gcc",
21+
# "arm64_msvc",
22+
#
1623
# "linux_arm64_clang",
24+
# "linux_arm64_gcc_or_clang",
1725
# "linux_arm64_gcc",
18-
# "linux_x86_64_clang",
19-
# "linux_x86_64_gcc",
20-
# "windows_x86_64_msvc",
21-
# "windows_x86_64_mingw_gcc",
22-
# "linux_x86_64",
23-
# "macos_x86_64",
24-
# "macos_arm64",
25-
# "windows_x86_64",
2626
# "linux_clang",
27+
# "linux_gcc_or_clang",
2728
# "linux_gcc",
29+
# "linux_x86_64_clang",
30+
# "linux_x86_64_gcc_or_clang",
31+
# "linux_x86_64_gcc",
32+
#
33+
# "macos_arm64_clang",
34+
# "macos_clang",
35+
# "macos_x86_64_clang",
36+
#
37+
# "windows_arm64_mingw_gcc",
38+
# "windows_arm64_msvc",
2839
# "windows_mingw_gcc",
2940
# "windows_msvc",
30-
# "macos_clang",
41+
# "windows_x86_64_mingw_gcc",
42+
# "windows_x86_64_msvc",
43+
#
44+
# "x86_64_clang",
45+
# "x86_64_gcc_or_clang",
46+
# "x86_64_gcc",
47+
# "x86_64_mingw_gcc",
48+
# "x86_64_msvc",
49+
#
3150
# "compiler_msvc",
3251
# "compiler_clang",
3352
# "compiler_regular_gcc",
3453
# "compiler_mingw_gcc",
3554
# "compiler_unknown",
3655
# "compiler_gcc",
37-
# "x86_64",
38-
# "arm64",
39-
# "linux",
40-
# "macos",
41-
# "windows",
42-
#
56+
# "compiler_gcc_or_clang",
4357
# ]
4458
#]
4559
#
4660

47-
# Combined os / cpu / compiler settings
48-
#
49-
# :linux_arm64_clang
50-
# :linux_arm64_gcc
51-
# :linux_x86_64_clang
52-
# :linux_x86_64_gcc
53-
# :windows_x86_64_msvc
54-
# :windows_x86_64_mingw_gcc
55-
selects.config_setting_group(
56-
name = "linux_arm64_clang",
57-
match_all = [
58-
":compiler_clang",
59-
":linux",
60-
":arm64",
61-
],
62-
)
63-
64-
selects.config_setting_group(
65-
name = "linux_arm64_gcc",
66-
match_all = [
67-
":compiler_gcc",
68-
":linux",
69-
":arm64",
70-
],
71-
)
72-
73-
selects.config_setting_group(
74-
name = "linux_x86_64_clang",
75-
match_all = [
76-
":compiler_clang",
77-
":linux",
78-
":x86_64",
79-
],
80-
)
81-
82-
selects.config_setting_group(
83-
name = "linux_x86_64_gcc",
84-
match_all = [
85-
":compiler_gcc",
86-
":linux",
87-
":x86_64",
88-
],
89-
)
90-
91-
selects.config_setting_group(
92-
name = "windows_x86_64_msvc",
93-
match_all = [
94-
":compiler_msvc",
95-
":windows",
96-
":x86_64",
97-
],
98-
)
99-
100-
selects.config_setting_group(
101-
name = "windows_x86_64_mingw_gcc",
102-
match_all = [
103-
":compiler_mingw_gcc",
104-
":x86_64",
105-
],
106-
)
107-
108-
# Combined os / cpu settings
109-
#
110-
# :linux_x86_64
111-
# :macos_x86_64
112-
# :macos_arm64
113-
# :windows_x86_64
114-
selects.config_setting_group(
115-
name = "linux_x86_64",
116-
match_all = [
117-
":linux",
118-
":x86_64",
119-
],
120-
)
121-
122-
selects.config_setting_group(
123-
name = "macos_x86_64",
124-
match_all = [
125-
":macos",
126-
":x86_64",
127-
],
128-
)
129-
130-
selects.config_setting_group(
131-
name = "macos_arm64",
132-
match_all = [
133-
":macos",
134-
":arm64",
135-
],
136-
)
137-
138-
selects.config_setting_group(
139-
name = "windows_x86_64",
140-
match_all = [
141-
":windows",
142-
":x86_64",
143-
],
144-
)
145-
146-
# Combined os / compiler settings
147-
# :linux_clang
148-
# :linux_gcc
149-
# :windows_mingw_gcc
150-
# :windows_msvc
151-
# :macos_clang
152-
153-
selects.config_setting_group(
154-
name = "linux_clang",
155-
match_all = [
156-
":compiler_clang",
157-
":linux",
158-
],
159-
)
160-
161-
selects.config_setting_group(
162-
name = "linux_gcc",
163-
match_all = [
164-
":compiler_gcc",
165-
":linux",
166-
],
167-
)
168-
169-
selects.config_setting_group(
170-
name = "windows_mingw_gcc",
171-
match_all = [
172-
":compiler_mingw_gcc",
173-
":linux",
174-
],
175-
)
176-
177-
selects.config_setting_group(
178-
name = "windows_msvc",
179-
match_all = [
180-
":compiler_msvc",
181-
":windows",
182-
],
183-
)
184-
185-
selects.config_setting_group(
186-
name = "macos_clang",
187-
match_all = [
188-
":compiler_clang",
189-
":macos",
190-
],
191-
)
61+
[
62+
emit_os_cpu_compiler_group(os, cpu, compiler)
63+
for os in [
64+
"macos",
65+
None,
66+
]
67+
for cpu in [
68+
"x86_64",
69+
"arm64",
70+
None,
71+
]
72+
for compiler in [
73+
"clang",
74+
None,
75+
]
76+
]
77+
78+
[
79+
emit_os_cpu_compiler_group(os, cpu, compiler)
80+
for os in [
81+
"linux",
82+
None,
83+
]
84+
for cpu in [
85+
"x86_64",
86+
"arm64",
87+
None,
88+
]
89+
for compiler in [
90+
"clang",
91+
"gcc",
92+
"gcc_or_clang",
93+
None,
94+
]
95+
]
96+
97+
[
98+
emit_os_cpu_compiler_group(os, cpu, compiler)
99+
for os in [
100+
"windows",
101+
None,
102+
]
103+
for cpu in [
104+
"x86_64",
105+
"arm64",
106+
None,
107+
]
108+
for compiler in [
109+
"msvc",
110+
"mingw_gcc",
111+
None,
112+
]
113+
]
192114

193115
# Compiler selection
194116
#
@@ -243,36 +165,10 @@ selects.config_setting_group(
243165
],
244166
)
245167

246-
# Cpu settings
247-
#
248-
# :arm64
249-
# :x86_64
250-
config_setting(
251-
name = "x86_64",
252-
constraint_values = ["@platforms//cpu:x86_64"],
253-
)
254-
255-
config_setting(
256-
name = "arm64",
257-
constraint_values = ["@platforms//cpu:arm64"],
258-
)
259-
260-
# Os settings
261-
#
262-
# :linux
263-
# :macos
264-
# :windows
265-
config_setting(
266-
name = "linux",
267-
constraint_values = ["@platforms//os:linux"],
268-
)
269-
270-
config_setting(
271-
name = "macos",
272-
constraint_values = ["@platforms//os:macos"],
273-
)
274-
275-
config_setting(
276-
name = "windows",
277-
constraint_values = ["@platforms//os:windows"],
168+
selects.config_setting_group(
169+
name = "compiler_gcc_or_clang",
170+
match_any = [
171+
":compiler_gcc",
172+
":compiler_clang",
173+
],
278174
)

bazel/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ Contains build targets used by Starlark files in the bazel/ directory.
1919
package(default_visibility = ["//visibility:public"])
2020

2121
licenses(["notice"])
22+
23+
filegroup(
24+
name = "_bazel_sources",
25+
srcs = glob(["*.bzl"]),
26+
)

bazel/utils.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,21 @@ def package_relative_path(path):
5858
if path == "":
5959
path = "."
6060
return path
61+
62+
# Used to emit combined settings for os / cpu / compiler.
63+
def emit_os_cpu_compiler_group(os, cpu, compiler):
64+
n = [x for x in [os, cpu, compiler] if x != None]
65+
if len(n) < 2:
66+
return
67+
name = "_".join(n)
68+
69+
if native.existing_rule(name) == None:
70+
m = [
71+
"@platforms//os:" + os if os != None else None,
72+
"@platforms//cpu:" + cpu if cpu != None else None,
73+
":compiler_" + compiler if compiler != None else None,
74+
]
75+
selects.config_setting_group(
76+
name = name,
77+
match_all = [x for x in m if x != None],
78+
)

0 commit comments

Comments
 (0)