Skip to content

Commit 9c62c52

Browse files
authored
Support cross-compilation from macOS for C++ and Java in .bazelrc (#28)
- In .bazelrc: - Add --cpu=k8. Without this, Bazel tries to select darwin_arm64 (or whatever the native platform is). This is still needed because Bazel still doesn't fully support platforms and toolchains for C++. - Add comments explaining what's missing and what to change. - Remove --tls_certificate. Bazel reports an error if it's used. (Should engflow-ca.crt be removed, too?) - In //remote_config/cc: - Generalize armeabi_cc_toolchain_config to stub_cc_toolchain_config and declare a stub for darwin_arm64. This shouldn't be needed in theory, and C++ targets build without it, but Java targets need it. More stubs may be needed for --cpu values on other platforms.
1 parent 6d90aa4 commit 9c62c52

File tree

3 files changed

+59
-23
lines changed

3 files changed

+59
-23
lines changed

.bazelrc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Options common for all EngFlow remote configurations.
12
build:engflow_common --jobs=8
23
build:engflow_common --define=EXECUTOR=remote
34
build:engflow_common --disk_cache=
@@ -8,6 +9,7 @@ build:engflow_common --remote_timeout=3600
89

910
build:engflow_common --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
1011
build:engflow_common --crosstool_top=//remote_config/cc:toolchain
12+
build:engflow_common --cpu=k8
1113
build:engflow_common --extra_execution_platforms=//remote_config/config:platform
1214
build:engflow_common --extra_toolchains=//remote_config/config:cc-toolchain
1315
build:engflow_common --host_platform=//remote_config/config:platform
@@ -17,13 +19,20 @@ build:engflow_common --java_language_version=11
1719

1820
build:without_bytes --experimental_remote_download_outputs=minimal
1921

22+
# Options for a private EngFlow cluster.
23+
# - Change "10.0.0.10:8080" to the actual cluster IP and port.
24+
# - You'll also need to set flags for your authentication method.
25+
# For example, if your cluster uses mTLS authentication, you could add
26+
# the flags below (with correct paths), either here or in ~/.bazelrc:
27+
# build:engflow --tls_client_certificate=/path/to/client.crt
28+
# build:engflow --tls_client_key=/path/to/client.key
2029
build:engflow --config=engflow_common
2130
build:engflow --remote_executor=grpcs://10.0.0.10:8080
22-
build:engflow --tls_certificate=engflow-ca.crt
2331
build:engflow --bes_backend=grpcs://10.0.0.10:8080
2432
build:engflow --bes_lifecycle_events
2533
build:engflow --bes_results_url=https://10.0.0.10:8080/invocation/
2634

35+
# Options for the open source cluster.
2736
build:engflow_oss --config=engflow_common
2837
build:engflow_oss --remote_executor=grpcs://oss-cluster.engflow.com
2938
build:engflow_oss --bes_backend=grpcs://oss-cluster.engflow.com

remote_config/cc/BUILD

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# This becomes the BUILD file for @local_config_cc// under non-BSD unixes.
1616

1717
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
18-
load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config")
18+
load(":stub_cc_toolchain_config.bzl", "stub_cc_toolchain_config")
1919
load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite")
2020

2121
package(default_visibility = ["//visibility:public"])
@@ -54,6 +54,7 @@ cc_toolchain_suite(
5454
"k8": ":cc-compiler-k8",
5555
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
5656
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
57+
"darwin_arm64": ":cc-compiler-darwin_arm64",
5758
},
5859
)
5960

@@ -165,4 +166,27 @@ cc_toolchain(
165166
toolchain_identifier = "stub_armeabi-v7a",
166167
)
167168

168-
armeabi_cc_toolchain_config(name = "stub_armeabi-v7a")
169+
stub_cc_toolchain_config(
170+
name = "stub_armeabi-v7a",
171+
cpu_name = "armeabi-v7a",
172+
)
173+
174+
cc_toolchain(
175+
name = "cc-compiler-darwin_arm64",
176+
all_files = ":empty",
177+
ar_files = ":empty",
178+
as_files = ":empty",
179+
compiler_files = ":empty",
180+
dwp_files = ":empty",
181+
linker_files = ":empty",
182+
objcopy_files = ":empty",
183+
strip_files = ":empty",
184+
supports_param_files = 1,
185+
toolchain_config = ":stub_darwin_arm64",
186+
toolchain_identifier = "stub_darwin_arm64",
187+
)
188+
189+
stub_cc_toolchain_config(
190+
name = "stub_darwin_arm64",
191+
cpu_name = "darwin_arm64",
192+
)

remote_config/cc/armeabi_cc_toolchain_config.bzl renamed to remote_config/cc/stub_cc_toolchain_config.bzl

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ load(
2121
)
2222

2323
def _impl(ctx):
24-
toolchain_identifier = "stub_armeabi-v7a"
25-
host_system_name = "armeabi-v7a"
26-
target_system_name = "armeabi-v7a"
27-
target_cpu = "armeabi-v7a"
28-
target_libc = "armeabi-v7a"
24+
toolchain_identifier = "stub_" + ctx.attr.cpu_name
25+
host_system_name = ctx.attr.cpu_name
26+
target_system_name = ctx.attr.cpu_name
27+
target_cpu = ctx.attr.cpu_name
28+
target_libc = ctx.attr.cpu_name
2929
compiler = "compiler"
30-
abi_version = "armeabi-v7a"
31-
abi_libc_version = "armeabi-v7a"
30+
abi_version = ctx.attr.cpu_name
31+
abi_libc_version = ctx.attr.cpu_name
3232
cc_target_os = None
3333
builtin_sysroot = None
3434
action_configs = []
@@ -41,18 +41,19 @@ def _impl(ctx):
4141
artifact_name_patterns = []
4242
make_variables = []
4343

44+
stub_tool_name = "/DONOTUSE/stub/" + ctx.attr.cpu_name
4445
tool_paths = [
45-
tool_path(name = "ar", path = "/bin/false"),
46-
tool_path(name = "compat-ld", path = "/bin/false"),
47-
tool_path(name = "cpp", path = "/bin/false"),
48-
tool_path(name = "dwp", path = "/bin/false"),
49-
tool_path(name = "gcc", path = "/bin/false"),
50-
tool_path(name = "gcov", path = "/bin/false"),
51-
tool_path(name = "ld", path = "/bin/false"),
52-
tool_path(name = "nm", path = "/bin/false"),
53-
tool_path(name = "objcopy", path = "/bin/false"),
54-
tool_path(name = "objdump", path = "/bin/false"),
55-
tool_path(name = "strip", path = "/bin/false"),
46+
tool_path(name = "ar", path = stub_tool_name),
47+
tool_path(name = "compat-ld", path = stub_tool_name),
48+
tool_path(name = "cpp", path = stub_tool_name),
49+
tool_path(name = "dwp", path = stub_tool_name),
50+
tool_path(name = "gcc", path = stub_tool_name),
51+
tool_path(name = "gcov", path = stub_tool_name),
52+
tool_path(name = "ld", path = stub_tool_name),
53+
tool_path(name = "nm", path = stub_tool_name),
54+
tool_path(name = "objcopy", path = stub_tool_name),
55+
tool_path(name = "objdump", path = stub_tool_name),
56+
tool_path(name = "strip", path = stub_tool_name),
5657
]
5758

5859
return cc_common.create_cc_toolchain_config_info(
@@ -75,8 +76,10 @@ def _impl(ctx):
7576
cc_target_os = cc_target_os,
7677
)
7778

78-
armeabi_cc_toolchain_config = rule(
79+
stub_cc_toolchain_config = rule(
7980
implementation = _impl,
80-
attrs = {},
81+
attrs = {
82+
"cpu_name": attr.string(mandatory = True),
83+
},
8184
provides = [CcToolchainConfigInfo],
8285
)

0 commit comments

Comments
 (0)