Skip to content

Commit 6dd2ef1

Browse files
AustinSchuhcopybara-github
authored andcommitted
Register both windows compilers to enable cross compilation
Copybara Import from bazelbuild#432 BEGIN_PUBLIC Register both windows compilers to enable cross compilation (bazelbuild#432) There is a perfectly good cross compiler for the other Windows variant (arm64 vs x86). The only problem is that it doesn't get registered by default, so it isn't easily available. Register both of them and let toolchain selection pick the right one automatically. Closes bazelbuild#432 END_PUBLIC COPYBARA_INTEGRATE_REVIEW=bazelbuild#432 from AustinSchuh:windows_cross_compile a738de7 PiperOrigin-RevId: 854483022 Change-Id: Ie366916d725b7e140665686f52f22eeee18a7614
1 parent 67f55bd commit 6dd2ef1

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")
2+
3+
toolchain(
4+
name = "cc-toolchain-arm64_windows",
5+
exec_compatible_with = HOST_CONSTRAINTS,
6+
target_compatible_with = [
7+
"@platforms//cpu:arm64",
8+
"@platforms//os:windows",
9+
],
10+
toolchain = "@local_config_cc//:cc-compiler-arm64_windows",
11+
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
12+
)
13+
14+
toolchain(
15+
name = "cc-toolchain-x64_windows",
16+
exec_compatible_with = HOST_CONSTRAINTS,
17+
target_compatible_with = [
18+
"@platforms//cpu:x86_64",
19+
"@platforms//os:windows",
20+
],
21+
toolchain = "@local_config_cc//:cc-compiler-x64_windows",
22+
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
23+
)
24+
25+
toolchain(
26+
name = "cc-toolchain-armeabi-v7a",
27+
exec_compatible_with = HOST_CONSTRAINTS,
28+
target_compatible_with = [
29+
"@platforms//cpu:armv7",
30+
"@platforms//os:android",
31+
],
32+
toolchain = "@local_config_cc//:cc-compiler-armeabi-v7a",
33+
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
34+
)

cc/private/toolchain/cc_configure.bzl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ def cc_autoconf_toolchains_impl(repository_ctx):
3333
should_detect_cpp_toolchain = "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" not in env or env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] != "1"
3434

3535
if should_detect_cpp_toolchain:
36+
if repository_ctx.os.name.lower().find("windows") != -1:
37+
build_path = "@rules_cc//cc/private/toolchain:BUILD.windows_toolchains.tpl"
38+
else:
39+
build_path = "@rules_cc//cc/private/toolchain:BUILD.toolchains.tpl"
3640
paths = resolve_labels(repository_ctx, [
37-
"@rules_cc//cc/private/toolchain:BUILD.toolchains.tpl",
41+
build_path,
3842
])
43+
3944
repository_ctx.template(
4045
"BUILD",
41-
paths["@rules_cc//cc/private/toolchain:BUILD.toolchains.tpl"],
46+
paths[build_path],
4247
{"%{name}": get_cpu_value(repository_ctx)},
4348
)
4449
else:

0 commit comments

Comments
 (0)