diff options
author | Dmitry Shevchenko <dmishe@google.com> | 2016-08-29 20:54:29 +0000 |
---|---|---|
committer | Klaus Aehlig <aehlig@google.com> | 2016-08-30 08:34:34 +0000 |
commit | 13c60d05942609e0979087bc9b33931de78bdd76 (patch) | |
tree | df756ddadfb1bb5541283d37b498771adbee1d45 | |
parent | bdc0e54daaea322023a4c82bc24fe2e0d523d690 (diff) |
Add support for watchOS in swift_library
--
MOS_MIGRATED_REVID=131631222
-rwxr-xr-x | src/test/shell/bazel/bazel_apple_test.sh | 30 | ||||
-rw-r--r-- | tools/build_defs/apple/shared.bzl | 10 | ||||
-rw-r--r-- | tools/build_defs/apple/swift.bzl | 31 |
3 files changed, 63 insertions, 8 deletions
diff --git a/src/test/shell/bazel/bazel_apple_test.sh b/src/test/shell/bazel/bazel_apple_test.sh index 5f56934bfc..8495c15dba 100755 --- a/src/test/shell/bazel/bazel_apple_test.sh +++ b/src/test/shell/bazel/bazel_apple_test.sh @@ -517,4 +517,34 @@ EOF //ios:swift_lib >$TEST_log 2>&1 || fail "should build" } +function test_apple_watch_with_swift() { + make_app + + cat >ios/watchapp.swift <<EOF + import WatchKit + class ExtensionDelegate: NSObject, WKExtensionDelegate { + func applicationDidFinishLaunching() {} + } +EOF + + cat >ios/BUILD <<EOF +load("//tools/build_defs/apple:swift.bzl", "swift_library") + +swift_library(name = "WatchModule", + srcs = ["watchapp.swift"]) + +apple_binary(name = "bin", + deps = [":WatchModule"], + platform_type = "watchos") + +apple_watch2_extension( + name = "WatchExtension", + app_bundle_id = "com.google.app.watchkit", + app_name = "WatchApp", + binary = ":bin", + ext_bundle_id = "com.google.app.extension", +) +EOF +} + run_suite "apple_tests" diff --git a/tools/build_defs/apple/shared.bzl b/tools/build_defs/apple/shared.bzl index 976911b177..05d96ceb91 100644 --- a/tools/build_defs/apple/shared.bzl +++ b/tools/build_defs/apple/shared.bzl @@ -65,10 +65,16 @@ def xcrun_action(ctx, **kw): This method takes the same keyword arguments as ctx.action, however you don't need to specify the executable. """ - platform = ctx.fragments.apple.ios_cpu_platform() + if hasattr(ctx.fragments.apple, "single_arch_platform"): + platform = ctx.fragments.apple.single_arch_platform + else: + # TODO(dmishe): Remove this branch when single_arch_platform is available + # by default. + platform = ctx.fragments.apple.ios_cpu_platform() + action_env = ctx.fragments.apple.target_apple_env(platform) \ + ctx.fragments.apple.apple_host_system_env() - env = kw.get('env', {}) + env = kw.get("env", {}) kw['env'] = env + action_env apple_action(ctx, executable=ctx.executable._xcrunwrapper, **kw) diff --git a/tools/build_defs/apple/swift.bzl b/tools/build_defs/apple/swift.bzl index 9f0889c432..4a6f443518 100644 --- a/tools/build_defs/apple/swift.bzl +++ b/tools/build_defs/apple/swift.bzl @@ -29,9 +29,18 @@ def _intersperse(separator, iterable): return result -def _swift_target(cpu, sdk_version): +def _swift_target(cpu, platform, sdk_version): """Returns a target triplet for Swift compiler.""" - return "%s-apple-ios%s" % (cpu, sdk_version) + # TODO(dmishe): Use PlatformType object when available. + platform_string = None + if str(platform).startswith("IOS_"): + platform_string = "ios" + elif str(platform).startswith("WATCHOS_"): + platform_string = "watchos" + else: + fail("Platform %s is not supported") + + return "%s-apple-%s%s" % (cpu, platform_string, sdk_version) def _swift_compilation_mode_flags(ctx): """Returns additional swiftc flags for the current compilation mode.""" @@ -61,10 +70,20 @@ def _module_name(ctx): def _swift_library_impl(ctx): """Implementation for swift_library Skylark rule.""" # TODO(b/29772303): Assert xcode version. - cpu = ctx.fragments.apple.ios_cpu() - platform = ctx.fragments.apple.ios_cpu_platform() - sdk_version = ctx.fragments.apple.sdk_version_for_platform(platform) - target = _swift_target(cpu, sdk_version) + apple_fm = ctx.fragments.apple + + if (hasattr(apple_fm, "single_arch_platform") + and hasattr(apple_fm, "single_arch_cpu")): + cpu = apple_fm.single_arch_cpu + platform = apple_fm.single_arch_platform + else: + # TODO(dmishe): Remove this branch when single_arch_platform is available + # by default. + cpu = apple_fm.ios_cpu() + platform = apple_fm.ios_cpu_platform() + + sdk_version = apple_fm.sdk_version_for_platform(platform) + target = _swift_target(cpu, platform, sdk_version) apple_toolchain = apple_common.apple_toolchain() module_name = ctx.attr.module_name or _module_name(ctx) |