From f867852e98f1bfbc57f44196b2b5b8578bd08449 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 11 Sep 2019 14:55:17 -0700 Subject: [PATCH] Add explicit -sdk argument to xcrun calls Xcode 11 (and possibly earlier versions) has a bug where, when you don't pass `-sdk macosx`, it can either pick the global `/Library/Developer/CommandLineTools` SDK path, or the SDK path bundled within Xcode itself. This seems to depend on if you have other versions of Xcode installed, and which versions of the command line tools you have installed. Passing `-sdk macosx` seems to always force it to pick the Xcode bundled version, which is what we prefer. This fixes issues with remote cache misses caused by these tools not being the same because of this difference. You can see which path it's picking by running: ``` env -i xcrun -l -n clang ``` --- src/tools/xcode/realpath/BUILD | 2 +- tools/cpp/osx_cc_configure.bzl | 2 ++ tools/osx/BUILD | 2 +- tools/osx/xcode_configure.bzl | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tools/xcode/realpath/BUILD b/src/tools/xcode/realpath/BUILD index 8642f9c7c7cb1b..27deb9521a3b53 100644 --- a/src/tools/xcode/realpath/BUILD +++ b/src/tools/xcode/realpath/BUILD @@ -5,7 +5,7 @@ genrule( name = "realpath_genrule", srcs = ["realpath.c"], outs = ["realpath"], - cmd = "/usr/bin/xcrun clang -o $@ $<", + cmd = "/usr/bin/xcrun -sdk macosx clang -o $@ $<", output_to_bindir = 1, visibility = ["//visibility:public"], ) diff --git a/tools/cpp/osx_cc_configure.bzl b/tools/cpp/osx_cc_configure.bzl index 9434c168b2f06f..56c85a5585c61c 100644 --- a/tools/cpp/osx_cc_configure.bzl +++ b/tools/cpp/osx_cc_configure.bzl @@ -108,6 +108,8 @@ def configure_osx_toolchain(repository_ctx, overriden_tools): "env", "-i", "xcrun", + "-sdk", + "macosx", "clang", "-std=c++11", "-lc++", diff --git a/tools/osx/BUILD b/tools/osx/BUILD index b1326e27af5f32..fa135c93f85ab6 100644 --- a/tools/osx/BUILD +++ b/tools/osx/BUILD @@ -18,7 +18,7 @@ exports_files([ ]) DARWIN_XCODE_LOCATOR_COMPILE_COMMAND = """ - /usr/bin/xcrun clang -fobjc-arc -framework CoreServices \ + /usr/bin/xcrun -sdk macosx clang -fobjc-arc -framework CoreServices \ -framework Foundation -o $@ $< """ diff --git a/tools/osx/xcode_configure.bzl b/tools/osx/xcode_configure.bzl index 6136bcd7b1f6a3..235cdec4774b07 100644 --- a/tools/osx/xcode_configure.bzl +++ b/tools/osx/xcode_configure.bzl @@ -117,6 +117,8 @@ def run_xcode_locator(repository_ctx, xcode_locator_src_label): "env", "-i", "xcrun", + "-sdk", + "macosx", "clang", "-fobjc-arc", "-framework",