@@ -18,10 +18,14 @@ load(
18
18
"CC_CONFIG_DIR" ,
19
19
"JAVA_CONFIG_DIR" ,
20
20
"PLATFORM_DIR" ,
21
+ "os_family" ,
21
22
)
22
23
load ("//rules/exec_properties:exec_properties.bzl" , "create_rbe_exec_properties_dict" )
23
24
24
- _CC_TOOLCHAIN = ":cc-compiler-k8"
25
+ _CC_TOOLCHAIN = {
26
+ "Linux" : ":cc-compiler-k8" ,
27
+ "Windows" : ":cc-compiler-x64_windows" ,
28
+ }
25
29
26
30
# Defining a local version of dicts.add in order not to create a dependency on bazel_skylib.
27
31
def _merge_dicts (* dict_args ):
@@ -94,7 +98,7 @@ def create_java_runtime(ctx, java_home):
94
98
False ,
95
99
)
96
100
97
- def create_export_platform (ctx , exec_properties , image_name , name , toolchain_config_spec_name , use_legacy_platform_definition ):
101
+ def create_export_platform (ctx , exec_properties , exec_compatible_with , target_compatible_with , image_name , name , toolchain_config_spec_name , use_legacy_platform_definition ):
98
102
"""Creates a BUILD file (to be exported to output_base) with the cc_toolchain and platform targets.
99
103
100
104
Args:
@@ -103,6 +107,12 @@ def create_export_platform(ctx, exec_properties, image_name, name, toolchain_con
103
107
be used when creating the platform. Will be used only when
104
108
use_legacy_platform_definition == False. This dict must not contain
105
109
"container-image".
110
+ exec_compatible_with: List of constraints to add to the produced
111
+ toolchain/platform targets (e.g., ["@bazel_tools//platforms:linux"] in the
112
+ exec_compatible_with/constraint_values attrs, respectively.
113
+ target_compatible_with: List of constraints to add to the produced
114
+ toolchain target (e.g., ["@bazel_tools//platforms:linux"]) in the
115
+ target_compatible_with attr.
106
116
image_name: the name of the image.
107
117
name: name of rbe_autoconfig repo rule.
108
118
toolchain_config_spec_name: name of the toolchain config spec
@@ -113,10 +123,10 @@ def create_export_platform(ctx, exec_properties, image_name, name, toolchain_con
113
123
if toolchain_config_spec_name :
114
124
cc_toolchain_target += "/" + toolchain_config_spec_name
115
125
cc_toolchain_target += "/bazel_" + ctx .attr .bazel_version
116
- cc_toolchain_target += "/cc" + _CC_TOOLCHAIN
117
- _create_platform (ctx , exec_properties , image_name , name , cc_toolchain_target , use_legacy_platform_definition )
126
+ cc_toolchain_target += "/cc" + _CC_TOOLCHAIN [ os_family ( ctx )]
127
+ _create_platform (ctx , exec_properties , exec_compatible_with , target_compatible_with , image_name , name , cc_toolchain_target , use_legacy_platform_definition )
118
128
119
- def create_external_repo_platform (ctx , exec_properties , image_name , name , use_legacy_platform_definition ):
129
+ def create_external_repo_platform (ctx , exec_properties , exec_compatible_with , target_compatible_with , image_name , name , use_legacy_platform_definition ):
120
130
"""Creates a BUILD file (to be used with configs in the external repo) with the cc_toolchain and platform targets.
121
131
122
132
Args:
@@ -125,15 +135,21 @@ def create_external_repo_platform(ctx, exec_properties, image_name, name, use_le
125
135
be used when creating the platform. Will be used only when
126
136
use_legacy_platform_definition == False. This dict must not contain
127
137
"container-image".
138
+ exec_compatible_with: List of constraints to add to the produced
139
+ toolchain/platform targets (e.g., ["@bazel_tools//platforms:linux"] in the
140
+ exec_compatible_with/constraint_values attrs, respectively.
141
+ target_compatible_with: List of constraints to add to the produced
142
+ toolchain target (e.g., ["@bazel_tools//platforms:linux"]) in the
143
+ target_compatible_with attr.
128
144
image_name: the name of the image.
129
145
name: name of rbe_autoconfig repo rule.
130
146
use_legacy_platform_definition: Whether to create a platform with
131
147
remote_execution_properties (legacy) or with exec_properties.
132
148
"""
133
- cc_toolchain_target = "@" + ctx .attr .name + "//" + CC_CONFIG_DIR + _CC_TOOLCHAIN
134
- _create_platform (ctx , exec_properties , image_name , name , cc_toolchain_target , use_legacy_platform_definition )
149
+ cc_toolchain_target = "@" + ctx .attr .name + "//" + CC_CONFIG_DIR + _CC_TOOLCHAIN [ os_family ( ctx )]
150
+ _create_platform (ctx , exec_properties , exec_compatible_with , target_compatible_with , image_name , name , cc_toolchain_target , use_legacy_platform_definition )
135
151
136
- def create_alias_platform (ctx , exec_properties , image_name , name , toolchain_config_spec_name , use_legacy_platform_definition ):
152
+ def create_alias_platform (ctx , exec_properties , exec_compatible_with , target_compatible_with , image_name , name , toolchain_config_spec_name , use_legacy_platform_definition ):
137
153
"""Creates a BUILD file (pointing to checked in config) with the cc_toolchain and platform targets.
138
154
139
155
Args:
@@ -142,6 +158,12 @@ def create_alias_platform(ctx, exec_properties, image_name, name, toolchain_conf
142
158
be used when creating the platform. Will be used only when
143
159
use_legacy_platform_definition == False. This dict must not contain
144
160
"container-image".
161
+ exec_compatible_with: List of constraints to add to the produced
162
+ toolchain/platform targets (e.g., ["@bazel_tools//platforms:linux"] in the
163
+ exec_compatible_with/constraint_values attrs, respectively.
164
+ target_compatible_with: List of constraints to add to the produced
165
+ toolchain target (e.g., ["@bazel_tools//platforms:linux"]) in the
166
+ target_compatible_with attr.
145
167
image_name: the name of the image.
146
168
name: name of rbe_autoconfig repo rule.
147
169
toolchain_config_spec_name: name of the toolchain config spec.
@@ -153,24 +175,25 @@ def create_alias_platform(ctx, exec_properties, image_name, name, toolchain_conf
153
175
bazel_version = ctx .attr .bazel_version ,
154
176
cc_dir = CC_CONFIG_DIR ,
155
177
config_output_base = ctx .attr .toolchain_config_suite_spec ["output_base" ],
156
- target = _CC_TOOLCHAIN ,
178
+ target = _CC_TOOLCHAIN [ os_family ( ctx )] ,
157
179
toolchain_config_repo = ctx .attr .toolchain_config_suite_spec ["repo_name" ],
158
180
))
159
- _create_platform (ctx , exec_properties , image_name , name , cc_toolchain_target , use_legacy_platform_definition )
181
+ _create_platform (ctx , exec_properties , exec_compatible_with , target_compatible_with , image_name , name , cc_toolchain_target , use_legacy_platform_definition )
160
182
161
183
# Creates a BUILD file with the cc_toolchain and platform targets
162
- def _create_platform (ctx , exec_properties , image_name , name , cc_toolchain_target , use_legacy_platform_definition ):
184
+ def _create_platform (ctx , exec_properties , exec_compatible_with , target_compatible_with , image_name , name , cc_toolchain_target , use_legacy_platform_definition ):
163
185
template = ctx .path (Label ("@bazel_toolchains//rules/rbe_repo:BUILD.platform_legacy.tpl" )) if use_legacy_platform_definition else ctx .path (Label ("@bazel_toolchains//rules/rbe_repo:BUILD.platform.tpl" ))
164
186
exec_compatible_with = ("\" " +
165
- ("\" ,\n \" " ).join (ctx . attr . exec_compatible_with ) +
187
+ ("\" ,\n \" " ).join (exec_compatible_with ) +
166
188
"\" ," )
167
189
target_compatible_with = ("\" " +
168
- ("\" ,\n \" " ).join (ctx . attr . target_compatible_with ) +
190
+ ("\" ,\n \" " ).join (target_compatible_with ) +
169
191
"\" ," )
170
192
193
+ os = os_family (ctx )
171
194
platform_exec_properties = create_rbe_exec_properties_dict (
172
195
container_image = "docker://%s" % image_name ,
173
- os_family = "Linux" ,
196
+ os_family = os ,
174
197
)
175
198
platform_exec_properties = _merge_dicts (platform_exec_properties , exec_properties )
176
199
@@ -181,6 +204,7 @@ def _create_platform(ctx, exec_properties, image_name, name, cc_toolchain_target
181
204
"%{cc_toolchain}" : cc_toolchain_target ,
182
205
"%{exec_compatible_with}" : exec_compatible_with ,
183
206
"%{image_name}" : image_name ,
207
+ "%{os_family}" : os ,
184
208
"%{platform_exec_properties}" : "%s" % platform_exec_properties ,
185
209
"%{target_compatible_with}" : target_compatible_with ,
186
210
},
0 commit comments