Skip to content

Commit

Permalink
Compile Apple tools as fat binaries if possible
Browse files Browse the repository at this point in the history
The Apple toolchain has 2 native binaries that are inputs to every
single action. Because of this if you want to share caches between Apple
Silicon machines and Intel machines, you either need to force them to be
x86_64 binaries and suffer the performance loss on Apple Silicon
machiens, or use fat binaries so the sha's match on both architectures,
which is what this change does. These binaries are so small that the
size impact of this doesn't matter. Since Apple Silicon support requires
Xcode 12 this falls back to compiling the single architecture binary if
it fails, under the assumption that means you're on Xcode 11 or lower.
We don't have a better indication at this point of what Xcode version
you're using, so this seems like a fine workaround until Xcode 12 is the
minimum supported version.
  • Loading branch information
keith committed May 9, 2021
1 parent 8a42645 commit 519c82f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tools/cpp/osx_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def _get_escaped_xcode_cxx_inc_directories(repository_ctx, cc, xcode_toolchains)

return include_dirs

def _compile_cc_file(repository_ctx, src_name, out_name):
def _compile_cc_file(repository_ctx, src_name, out_name, multi_arch = True):
env = repository_ctx.os.environ
arch_args = ["-arch", "arm64", "-arch", "x86_64"] if multi_arch else []
xcrun_result = repository_ctx.execute([
"env",
"-i",
Expand All @@ -70,8 +71,12 @@ def _compile_cc_file(repository_ctx, src_name, out_name):
"-o",
out_name,
src_name,
], 30)
if (xcrun_result.return_code != 0):
] + arch_args, 30)

# TODO: Remove multi_arch once Xcode 12 is the minimum supported version
if multi_arch and xcrun_result.return_code != 0:
_compile_cc_file(repository_ctx, src_name, out_name, False)
elif (xcrun_result.return_code != 0):
error_msg = (
"return code {code}, stderr: {err}, stdout: {out}"
).format(
Expand Down

0 comments on commit 519c82f

Please sign in to comment.