aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Dmitry Shevchenko <dmishe@google.com>2016-10-05 16:07:22 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-10-05 19:41:34 +0000
commit39bb51a47e97f8d3771a282d5a9384fe041a506b (patch)
tree371e62d85737f2e58ddf45fa8c7326aef65b87e6 /tools
parent83e7c710153036c4cbf1c6201947aa7911f93cf4 (diff)
* Fixed breakage in shell tools with an old bazel binary. Rollback of commit deeeb31f8ba0f196fbc9ca2a177d59d57ea50b32. *** Reason for rollback *** Breaks builds with current blaze *** Original change description *** Add a way to select non-default Xcode toolchain * Adds a flag --xcode_toolchain which sets TOOLCHAINS env variable for xcrun. * Updates swift_library to work with this flag when selecting Swift runtime location. * By default the flag has a null value and is not set in env. -- MOS_MIGRATED_REVID=135238820
Diffstat (limited to 'tools')
-rw-r--r--tools/build_defs/apple/swift.bzl38
1 files changed, 36 insertions, 2 deletions
diff --git a/tools/build_defs/apple/swift.bzl b/tools/build_defs/apple/swift.bzl
index 9b496688a7..3cc22fe44b 100644
--- a/tools/build_defs/apple/swift.bzl
+++ b/tools/build_defs/apple/swift.bzl
@@ -78,6 +78,39 @@ def _module_name(ctx):
"""Returns a module name for the given rule context."""
return ctx.label.package.lstrip("//").replace("/", "_") + "_" + ctx.label.name
+def _swift_lib_dir(ctx):
+ """Returns the location of swift runtime directory to link against."""
+ # TODO(dmishe): Expose this template from native code.
+ developer_dir = "__BAZEL_XCODE_DEVELOPER_DIR__"
+ platform_str = ctx.fragments.apple.single_arch_platform.name_in_plist.lower()
+
+ toolchain_name = "XcodeDefault"
+ if hasattr(ctx.fragments.apple, "xcode_toolchain"):
+ toolchain = ctx.fragments.apple.xcode_toolchain
+
+ # We cannot use non Xcode-packaged toolchains, and the only one non-default
+ # toolchain known to exist (as of Xcode 8.1) is this one.
+ # TODO(b/29338444): Write an integration test when Xcode 8 is available.
+ if toolchain == "com.apple.dt.toolchain.Swift_2_3":
+ toolchain_name = "Swift_2.3"
+
+ return "{0}/Toolchains/{1}.xctoolchain/usr/lib/swift/{2}".format(
+ developer_dir, toolchain_name, platform_str)
+
+def _swift_linkopts(ctx):
+ """Returns additional linker arguments for the given rule context."""
+ return set(["-L" + _swift_lib_dir(ctx)])
+
+def _swift_xcrun_args(ctx):
+ """Returns additional arguments that should be passed to xcrun."""
+ # TODO(dmishe): Remove this check when xcode_toolchain is available by default
+ args = []
+ if hasattr(ctx.fragments.apple, "xcode_toolchain"):
+ if ctx.fragments.apple.xcode_toolchain:
+ args += ["--toolchain", ctx.fragments.apple.xcode_toolchain]
+
+ return args
+
def _swift_library_impl(ctx):
"""Implementation for swift_library Skylark rule."""
# TODO(b/29772303): Assert xcode version.
@@ -202,7 +235,7 @@ def _swift_library_impl(ctx):
# https://llvm.org/bugs/show_bug.cgi?id=19501
+ ["-fmodule-map-file=%s" % x.path for x in objc_module_maps])
- args = [
+ args = _swift_xcrun_args(ctx) + [
"swiftc",
"-emit-object",
"-emit-module-path",
@@ -253,7 +286,8 @@ def _swift_library_impl(ctx):
library=set([output_lib] + dep_libs),
header=set([output_header]),
providers=objc_providers,
- uses_swift=True)
+ linkopt=_swift_linkopts(ctx),
+ uses_swift=True,)
return struct(
swift=struct(