From e885ebcee724c0bf1895ff590c1743ee2b541518 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 2 May 2019 15:32:40 -0700 Subject: [PATCH 1/2] Add custom macOS Swift toolchain support This allows you to pass `--define=SWIFT_CUSTOM_TOOLCHAIN=toolchain.id` to specify a custom swift toolchain like the ones downloaded from https://swift.org/download/#snapshots to use. --- swift/internal/xcode_swift_toolchain.bzl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swift/internal/xcode_swift_toolchain.bzl b/swift/internal/xcode_swift_toolchain.bzl index c20ee97c5..aa5ccd962 100644 --- a/swift/internal/xcode_swift_toolchain.bzl +++ b/swift/internal/xcode_swift_toolchain.bzl @@ -481,6 +481,10 @@ def _xcode_swift_toolchain_impl(ctx): # Configure the action registrars that automatically prepend xcrunwrapper to registered actions. env = _xcode_env(xcode_config, platform) + custom_toolchain = ctx.var.get("SWIFT_CUSTOM_TOOLCHAIN") + if custom_toolchain: + env["TOOLCHAINS"] = custom_toolchain + execution_requirements = {"requires-darwin": ""} bazel_xcode_wrapper = ctx.executable._bazel_xcode_wrapper action_registrars = struct( From 40298b452719bcb306b134387b21d9c0ecb199cd Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 3 May 2019 11:24:51 -0700 Subject: [PATCH 2/2] Add SWIFT_CUSTOM_TOOLCHAIN details to readme --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index a868f9e2d..02883f905 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,22 @@ environment variable `CC=clang` when invoking Bazel. This step is not necessary for macOS users because the Xcode toolchain always uses `clang`. +## Building with Custom Toolchains + +**macOS hosts:** You can build with a custom toolchain installed in +`/Library/Developer/Toolchains` instead of Xcode's default. To do so, pass the +following flag to Bazel: + +``` +--define=SWIFT_CUSTOM_TOOLCHAIN=toolchain.id +``` + +where `toolchain.id` is the value of the `CFBundleIdentifier` key in the +toolchain's Info.plist file. + +**Linux hosts:** At this time, Bazel uses whichever `swift` executable is +encountered first on your `PATH`. + ## Future Work * Support for building and linking to shared libraries (`.dylib`/`.so`) written