Skip to content

Commit 7db6236

Browse files
sunjayBhatiawrowe
andauthored
Enable toolchain config generation on Windows (bazelbuild#873)
* WIP - some basic content validation tests added and passing - verify output base contains some expected content Co-authored-by: Sunjay Bhatia <[email protected]> Co-authored-by: William A Rowe Jr <[email protected]> Signed-off-by: Sunjay Bhatia <[email protected]> Signed-off-by: William A Rowe Jr <[email protected]> * Experiment with bazel CI/buildkit to see if it can pull docker images Co-authored-by: William A Rowe Jr <[email protected]> * Refactoring given feedback and to fix tests on Linux * Attempt to exclude Windows tests in CI * More refactors to clean up differences in OS families * Add TODOs for Windows tests * Change defaults for exec_compatible_with and target_compatible_with Have os-specific "default" values * Make buildifier happy with documented arguments * Move sample cc project generation to common locatino for docker config * Make buildifier happy * Bring back checked in sample cc project Co-authored-by: William A Rowe Jr <[email protected]>
1 parent a2b3b36 commit 7db6236

File tree

12 files changed

+340
-74
lines changed

12 files changed

+340
-74
lines changed

.bazelci/presubmit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tasks:
3232
- "--action_env=PATH"
3333
- "--test_output=errors"
3434
- "--verbose_failures"
35+
- "--test_tag_filters=-windows"
3536
rbe_exec_properties:
3637
# Run tests on RBE. These tests run on platforms with various execution
3738
# properties. the tests verify that the approriate properties are set (or not set).
@@ -46,3 +47,4 @@ tasks:
4647
- "--extra_execution_platforms=@rbe_default_exec_properties//config:platform,//tests/rules/exec_properties:platform_privileged_on,//tests/rules/exec_properties:platform_network_enabled,//tests/rules/exec_properties:platform_bespoke_network_enabled,//tests/rules/exec_properties:platform_overridden_network_enabled"
4748
- "--host_platform=@rbe_default_exec_properties//config:platform"
4849
- "--platforms=@rbe_default_exec_properties//config:platform"
50+
- "--test_tag_filters=-windows"

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818
build --host_force_python=PY2
1919
test --host_force_python=PY2
2020
run --host_force_python=PY2
21+
22+
# Defaults to auto which means off for Windows, explicitly enable for sh tests
23+
build --enable_runfiles=yes

WORKSPACE

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ rbe_autoconfig(
268268
use_checked_in_confs = "False",
269269
)
270270

271+
rbe_autoconfig(
272+
name = "rbe_autoconf_generate_windows",
273+
bazel_version = "3.1.0",
274+
create_testdata = True,
275+
digest = "sha256:776f241c2693f3f2187d998dcc98d2b339dcb80c99ef59bccefad0eea6e61284",
276+
registry = "gcr.io",
277+
repository = "envoy-ci/envoy-build-windows",
278+
use_checked_in_confs = "False",
279+
)
280+
271281
rbe_autoconfig(
272282
name = "rbe_autoconf_generate_no_java",
273283
bazel_version = _ubuntu1604_bazel,
@@ -401,6 +411,31 @@ rbe_autoconfig(
401411
use_checked_in_confs = "False",
402412
)
403413

414+
load(
415+
"//tests/rbe_repo:versions.bzl",
416+
gcb_test_toolchain_config_suite_autogen_spec = "TOOLCHAIN_CONFIG_AUTOGEN_SPEC",
417+
)
418+
419+
rbe_autoconfig(
420+
name = "rbe_autoconf_output_base_windows",
421+
bazel_version = "3.1.0",
422+
create_java_configs = False,
423+
create_testdata = True,
424+
digest = "sha256:776f241c2693f3f2187d998dcc98d2b339dcb80c99ef59bccefad0eea6e61284",
425+
export_configs = True,
426+
registry = "gcr.io",
427+
repository = "envoy-ci/envoy-build-windows",
428+
toolchain_config_spec_name = "test_config_dir",
429+
toolchain_config_suite_spec = {
430+
"container_registry": "gcr.io",
431+
"container_repo": "envoy-ci/envoy-build-windows",
432+
"output_base": "rbe-test-output/config/rbe_autoconf_output_base_windows",
433+
"repo_name": rbe_default_repo()["repo_name"],
434+
"toolchain_config_suite_autogen_spec": gcb_test_toolchain_config_suite_autogen_spec,
435+
},
436+
use_checked_in_confs = "False",
437+
)
438+
404439
rbe_autoconfig(
405440
name = "rbe_autoconf_output_base_no_java",
406441
bazel_version = _ubuntu1604_bazel,
@@ -537,11 +572,6 @@ rbe_autoconfig(
537572
},
538573
)
539574

540-
load(
541-
"//tests/rbe_repo:versions.bzl",
542-
gcb_test_toolchain_config_suite_autogen_spec = "TOOLCHAIN_CONFIG_AUTOGEN_SPEC",
543-
)
544-
545575
# This repo should only be used for GCB tests.
546576
# It relies on location of //tests/rbe_repo:blank_versions_test.bzl
547577
# and output_base in toolchain_config_suite_spec to match so that 1st build

rules/rbe_repo.bzl

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,11 @@ were built and can be leveraged by all users of a container.
382382
383383
NOTE 6: KNOWN LIMITATIONS
384384
385-
- This rule can only run in Linux if it needs to generate configs.
385+
- This rule can only run on Linux or Windows if it needs to generate configs.
386386
- This rule uses Bazelisk to run Bazel inside the given container.
387387
The container, thus, must be able to execute the Bazelisk binary
388-
(i.e., container must be capable of running linux-amd releases in
388+
(i.e., Linux or Windows based container must be capable of running
389+
the respective linux-amd or windows-amd releases from
389390
https://github.com/bazelbuild/bazelisk/releases)
390391
- If using export_configs, and you have multiple rbe_autoconfig targets
391392
pointing to the same toolchain_config_suite_spec, these rules should not
@@ -439,6 +440,7 @@ load(
439440
"AUTOCONF_ROOT",
440441
"DOCKER_PATH",
441442
"copy_to_test_dir",
443+
"os_family",
442444
"print_exec_results",
443445
"resolve_image_name",
444446
"resolve_project_root",
@@ -458,15 +460,27 @@ _CONFIG_REPOS = ["local_config_cc"]
458460

459461
_DEFAULT_TOOLCHAIN_CONFIG_SPEC_NAME = "default_toolchain_config_spec_name"
460462

461-
_RBE_UBUNTU_EXEC_COMPAT_WITH = [
462-
"@bazel_tools//platforms:x86_64",
463-
"@bazel_tools//platforms:linux",
464-
"@bazel_tools//tools/cpp:clang",
465-
]
466-
_RBE_UBUNTU_TARGET_COMPAT_WITH = [
467-
"@bazel_tools//platforms:linux",
468-
"@bazel_tools//platforms:x86_64",
469-
]
463+
_EXEC_COMPAT_WITH = {
464+
"Linux": [
465+
"@bazel_tools//platforms:linux",
466+
"@bazel_tools//platforms:x86_64",
467+
"@bazel_tools//tools/cpp:clang",
468+
],
469+
"Windows": [
470+
"@bazel_tools//platforms:windows",
471+
"@bazel_tools//platforms:x86_64",
472+
],
473+
}
474+
_TARGET_COMPAT_WITH = {
475+
"Linux": [
476+
"@bazel_tools//platforms:linux",
477+
"@bazel_tools//platforms:x86_64",
478+
],
479+
"Windows": [
480+
"@bazel_tools//platforms:windows",
481+
"@bazel_tools//platforms:x86_64",
482+
],
483+
}
470484

471485
def _rbe_autoconfig_impl(ctx):
472486
"""Core implementation of _rbe_autoconfig repository rule."""
@@ -494,6 +508,15 @@ def _rbe_autoconfig_impl(ctx):
494508
image_name = resolve_image_name(ctx)
495509
docker_tool_path = None
496510

511+
# Resolve default constraints if none set
512+
target_compatible_with = ctx.attr.target_compatible_with
513+
if not target_compatible_with:
514+
target_compatible_with = _TARGET_COMPAT_WITH[os_family(ctx)]
515+
516+
exec_compatible_with = ctx.attr.exec_compatible_with
517+
if not exec_compatible_with:
518+
exec_compatible_with = _EXEC_COMPAT_WITH[os_family(ctx)]
519+
497520
# Resolve the paths to copy srcs to the container and to
498521
# export configs.
499522
mount_project_root, export_project_root, use_default_project = resolve_project_root(ctx)
@@ -565,6 +588,8 @@ def _rbe_autoconfig_impl(ctx):
565588
create_export_platform(
566589
ctx,
567590
exec_properties = ctx.attr.exec_properties,
591+
exec_compatible_with = exec_compatible_with,
592+
target_compatible_with = target_compatible_with,
568593
image_name = resolve_rbe_original_image_name(ctx, image_name),
569594
name = name,
570595
toolchain_config_spec_name = toolchain_config_spec_name,
@@ -593,6 +618,8 @@ def _rbe_autoconfig_impl(ctx):
593618
create_external_repo_platform(
594619
ctx,
595620
exec_properties = ctx.attr.exec_properties,
621+
exec_compatible_with = exec_compatible_with,
622+
target_compatible_with = target_compatible_with,
596623
image_name = resolve_rbe_original_image_name(ctx, image_name),
597624
name = name,
598625
use_legacy_platform_definition = ctx.attr.use_legacy_platform_definition,
@@ -606,6 +633,8 @@ def _rbe_autoconfig_impl(ctx):
606633
create_alias_platform(
607634
ctx,
608635
exec_properties = ctx.attr.exec_properties,
636+
exec_compatible_with = exec_compatible_with,
637+
target_compatible_with = target_compatible_with,
609638
image_name = resolve_rbe_original_image_name(ctx, image_name),
610639
name = name,
611640
toolchain_config_spec_name = toolchain_config_spec_name,
@@ -748,12 +777,10 @@ _rbe_autoconfig = repository_rule(
748777
"generate the toolchain configs."),
749778
),
750779
"exec_compatible_with": attr.string_list(
751-
default = _RBE_UBUNTU_EXEC_COMPAT_WITH,
752780
doc = ("Optional. The list of constraints that will be added to the " +
753781
"toolchain in its exec_compatible_with attribute (and to " +
754782
"the platform in its constraint_values attr). For " +
755-
"example, [\"@bazel_tools//platforms:linux\"]. Default " +
756-
" is set to values for rbe-ubuntu16-04 container."),
783+
"example, [\"@bazel_tools//platforms:linux\"]."),
757784
),
758785
"exec_properties": attr.string_dict(
759786
doc = (
@@ -818,11 +845,9 @@ _rbe_autoconfig = repository_rule(
818845
doc = ("Optional. The tag of the image to pull, e.g. latest."),
819846
),
820847
"target_compatible_with": attr.string_list(
821-
default = _RBE_UBUNTU_TARGET_COMPAT_WITH,
822848
doc = ("The list of constraints that will be added to the " +
823849
"toolchain in its target_compatible_with attribute. For " +
824-
"example, [\"@bazel_tools//platforms:linux\"]. Default " +
825-
" is set to values for rbe-ubuntu16-04 container."),
850+
"example, [\"@bazel_tools//platforms:linux\"]."),
826851
),
827852
"use_checked_in_confs": attr.string(
828853
default = CHECKED_IN_CONFS_TRY,

rules/rbe_repo/BUILD.platform_legacy.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ platform(
4242
}
4343
properties {
4444
name: "OSFamily"
45-
value: "Linux"
45+
value: "%{os_family}"
4646
}
4747
""",
4848
)

rules/rbe_repo/build_gen.bzl

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ load(
1818
"CC_CONFIG_DIR",
1919
"JAVA_CONFIG_DIR",
2020
"PLATFORM_DIR",
21+
"os_family",
2122
)
2223
load("//rules/exec_properties:exec_properties.bzl", "create_rbe_exec_properties_dict")
2324

24-
_CC_TOOLCHAIN = ":cc-compiler-k8"
25+
_CC_TOOLCHAIN = {
26+
"Linux": ":cc-compiler-k8",
27+
"Windows": ":cc-compiler-x64_windows",
28+
}
2529

2630
# Defining a local version of dicts.add in order not to create a dependency on bazel_skylib.
2731
def _merge_dicts(*dict_args):
@@ -94,7 +98,7 @@ def create_java_runtime(ctx, java_home):
9498
False,
9599
)
96100

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):
98102
"""Creates a BUILD file (to be exported to output_base) with the cc_toolchain and platform targets.
99103
100104
Args:
@@ -103,6 +107,12 @@ def create_export_platform(ctx, exec_properties, image_name, name, toolchain_con
103107
be used when creating the platform. Will be used only when
104108
use_legacy_platform_definition == False. This dict must not contain
105109
"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.
106116
image_name: the name of the image.
107117
name: name of rbe_autoconfig repo rule.
108118
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
113123
if toolchain_config_spec_name:
114124
cc_toolchain_target += "/" + toolchain_config_spec_name
115125
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)
118128

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):
120130
"""Creates a BUILD file (to be used with configs in the external repo) with the cc_toolchain and platform targets.
121131
122132
Args:
@@ -125,15 +135,21 @@ def create_external_repo_platform(ctx, exec_properties, image_name, name, use_le
125135
be used when creating the platform. Will be used only when
126136
use_legacy_platform_definition == False. This dict must not contain
127137
"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.
128144
image_name: the name of the image.
129145
name: name of rbe_autoconfig repo rule.
130146
use_legacy_platform_definition: Whether to create a platform with
131147
remote_execution_properties (legacy) or with exec_properties.
132148
"""
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)
135151

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):
137153
"""Creates a BUILD file (pointing to checked in config) with the cc_toolchain and platform targets.
138154
139155
Args:
@@ -142,6 +158,12 @@ def create_alias_platform(ctx, exec_properties, image_name, name, toolchain_conf
142158
be used when creating the platform. Will be used only when
143159
use_legacy_platform_definition == False. This dict must not contain
144160
"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.
145167
image_name: the name of the image.
146168
name: name of rbe_autoconfig repo rule.
147169
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
153175
bazel_version = ctx.attr.bazel_version,
154176
cc_dir = CC_CONFIG_DIR,
155177
config_output_base = ctx.attr.toolchain_config_suite_spec["output_base"],
156-
target = _CC_TOOLCHAIN,
178+
target = _CC_TOOLCHAIN[os_family(ctx)],
157179
toolchain_config_repo = ctx.attr.toolchain_config_suite_spec["repo_name"],
158180
))
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)
160182

161183
# 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):
163185
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"))
164186
exec_compatible_with = ("\"" +
165-
("\",\n \"").join(ctx.attr.exec_compatible_with) +
187+
("\",\n \"").join(exec_compatible_with) +
166188
"\",")
167189
target_compatible_with = ("\"" +
168-
("\",\n \"").join(ctx.attr.target_compatible_with) +
190+
("\",\n \"").join(target_compatible_with) +
169191
"\",")
170192

193+
os = os_family(ctx)
171194
platform_exec_properties = create_rbe_exec_properties_dict(
172195
container_image = "docker://%s" % image_name,
173-
os_family = "Linux",
196+
os_family = os,
174197
)
175198
platform_exec_properties = _merge_dicts(platform_exec_properties, exec_properties)
176199

@@ -181,6 +204,7 @@ def _create_platform(ctx, exec_properties, image_name, name, cc_toolchain_target
181204
"%{cc_toolchain}": cc_toolchain_target,
182205
"%{exec_compatible_with}": exec_compatible_with,
183206
"%{image_name}": image_name,
207+
"%{os_family}": os,
184208
"%{platform_exec_properties}": "%s" % platform_exec_properties,
185209
"%{target_compatible_with}": target_compatible_with,
186210
},

0 commit comments

Comments
 (0)