diff --git a/BUILD b/BUILD index c41dd6d899..2f820e7ec3 100644 --- a/BUILD +++ b/BUILD @@ -1,6 +1,7 @@ load("@build_bazel_rules_android//android:rules.bzl", "aar_import") load("@build_bazel_rules_apple//apple:apple.bzl", "apple_static_framework_import") load("@io_bazel_rules_kotlin//kotlin/internal:toolchains.bzl", "define_kt_toolchain") +load("@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:xcodeproj.bzl", "xcodeproj") load("//bazel:framework_imports_extractor.bzl", "framework_imports_extractor") licenses(["notice"]) # Apache 2 @@ -102,3 +103,19 @@ genrule( """, tools = ["@kotlin_formatter//file"], ) + +xcodeproj( + name = "xcodeproj", + archived_bundles_allowed = True, + build_mode = "bazel", + project_name = "Envoy", + tags = ["manual"], + targets = [ + # TODO(jpsim): Fix Objective-C app support + # "//examples/objective-c/hello_world:app", + "//examples/swift/async_await:app", + "//examples/swift/hello_world:app", + "//test/swift/apps/baseline:app", + "//test/swift/apps/experimental:app", + ], +) diff --git a/WORKSPACE b/WORKSPACE index ec48dbd462..fd2d8313f2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -61,3 +61,6 @@ android_configure( load("@local_config_android//:android_configure.bzl", "android_workspace") android_workspace() + +load("@com_github_buildbuddy_io_rules_xcodeproj//xcodeproj:repositories.bzl", "xcodeproj_rules_dependencies") +xcodeproj_rules_dependencies() diff --git a/bazel/envoy_mobile_repositories.bzl b/bazel/envoy_mobile_repositories.bzl index af8c4eb066..0fdb156d44 100644 --- a/bazel/envoy_mobile_repositories.bzl +++ b/bazel/envoy_mobile_repositories.bzl @@ -78,10 +78,12 @@ def swift_repos(): url = "https://github.com/bazelbuild/rules_apple/archive/2d1fa9ea5f3544fed41d50c28c8508af035bc0a0.tar.gz", ) + # TODO(jpsim): Update to the next release which includes https://github.com/bazelbuild/rules_swift/pull/818 http_archive( name = "build_bazel_rules_swift", - sha256 = "a2fd565e527f83fb3f9eb07eb9737240e668c9242d3bc318712efa54a7deda97", - url = "https://github.com/bazelbuild/rules_swift/releases/download/0.27.0/rules_swift.0.27.0.tar.gz", + sha256 = "b5966b422113866398035cd970feffb4ab6c081fa1c96c02d942b17e5b8429c4", + strip_prefix = "rules_swift-8d4b096b90e47095755e47c27e749ae9b9f83e81", + url = "https://github.com/bazelbuild/rules_swift/archive/8d4b096b90e47095755e47c27e749ae9b9f83e81.tar.gz", ) http_archive( @@ -98,6 +100,14 @@ def swift_repos(): url = "https://github.com/realm/SwiftLint/releases/download/0.47.1/portable_swiftlint.zip", ) + # TODO(jpsim): Update to the next release which includes https://github.com/buildbuddy-io/rules_xcodeproj/pull/407 + http_archive( + name = "com_github_buildbuddy_io_rules_xcodeproj", + sha256 = "af9f6ebbf4d7c83cf35d7ced0b9d13fd6e91e9da5e4ceaf06614ed8caeab45aa", + strip_prefix = "rules_xcodeproj-96f59d785e8ec226b74af0586f856770b5e7e60c", + url = "https://github.com/buildbuddy-io/rules_xcodeproj/archive/96f59d785e8ec226b74af0586f856770b5e7e60c.tar.gz", + ) + def kotlin_repos(): http_archive( name = "rules_java", diff --git a/docs/root/development/debugging/images/instruments.jpg b/docs/root/development/debugging/images/instruments.jpg new file mode 100644 index 0000000000..459a6a0733 Binary files /dev/null and b/docs/root/development/debugging/images/instruments.jpg differ diff --git a/docs/root/development/debugging/images/xcode_breakpoint.jpg b/docs/root/development/debugging/images/xcode_breakpoint.jpg new file mode 100644 index 0000000000..93d314926b Binary files /dev/null and b/docs/root/development/debugging/images/xcode_breakpoint.jpg differ diff --git a/docs/root/development/debugging/ios_local.rst b/docs/root/development/debugging/ios_local.rst new file mode 100644 index 0000000000..c546fa1126 --- /dev/null +++ b/docs/root/development/debugging/ios_local.rst @@ -0,0 +1,75 @@ +.. _debugging_ios_instructions: + +Build & run the example iOS apps +======================================= + +*Note: This document assumes that you have installed the +:ref:`iOS build requirements `_.* + +The fastest way to build and run the sample iOS apps is to run the +following command:: + + ./bazelw run //examples/swift/hello_world:app + +This will build and run the Hello World iOS app in a new iOS Simulator. + +.. _using_xcode: + +Using the Xcode GUI +------------------- + +Envoy Mobile makes use of the +`rules_xcodeproj `_ +project to add support for many of Xcode's development, debugging and +profiling features to Envoy Mobile. + +To start, run ``./bazelw run //:xcodeproj`` to generate an Xcode project +and ``xed .`` to open it in Xcode (or double-click ``Envoy.xcodeproj`` +in Finder). + +In Xcode's scheme selector, pick the app target you want to build (e.g. +``__examples_swift_hello_world_app``), pick a Simulator to run it on, +then hit cmd-R to build and run. + +From there, most Xcode features should just work for all transitively +compiled source files in C/C++/Objective-C/Objective-C++/Swift: + +* Auto-complete +* Syntax highlighting +* Go to definition +* Breakpoints +* LLDB console +* Thread navigator +* Symbols +* Metrics like CPU/memory/networking/energy +* Profiling with Instruments + +|xcode_breakpoint| |instruments| + +.. |xcode_breakpoint| image:: images/xcode_breakpoint.jpg + :width: 45% + +.. |instruments| image:: images/instruments.jpg + :width: 45% + +Running on a real iPhone +------------------------ + +Although building and running on a physical device is +`not yet officially supported `_ +by rules_xcodeproj, following these steps may work: + +1. Add ``build --ios_multi_cpus=arm64`` to ``.bazelrc``. +2. Add a ``.mobileprovision`` provisioning profile capable of signing + the app you want to run next to its ``BUILD`` file. + E.g. ``examples/swift/hello_world/dev.mobileprovision`` +3. Set the provisioning profile on the ``ios_application`` you want to + run. E.g. ``provisioning_profile = "dev.mobileprovision",`` +4. Remove all apps without a provisioning profile from the ``xcodeproj`` + configuration in Envoy Mobile's root ``BUILD`` file. +5. Follow the same steps as defined in the + :ref:`Using the Xcode GUI `_ section above, but + targeting your device instead of a simulator. + +*Note: You may need to clean from Xcode with cmd-shift-k between device +runs.* diff --git a/docs/root/development/development.rst b/docs/root/development/development.rst index bed1c4e071..49d124a7d9 100644 --- a/docs/root/development/development.rst +++ b/docs/root/development/development.rst @@ -14,3 +14,4 @@ developing Envoy Mobile. testing/testing tools/tools debugging/android_local + debugging/ios_local diff --git a/docs/root/start/building/building.rst b/docs/root/start/building/building.rst index acacc68450..25d488a6cd 100644 --- a/docs/root/start/building/building.rst +++ b/docs/root/start/building/building.rst @@ -52,6 +52,8 @@ For local builds, set ``ANDROID_HOME`` and ``ANDROID_NDK_HOME`` to point to the See `ci/mac_ci_setup.sh` for the specific NDK version used during builds. +.. _ios_requirements: + ---------------- iOS requirements ---------------- diff --git a/examples/objective-c/hello_world/BUILD b/examples/objective-c/hello_world/BUILD index 96ba9f355f..4c85dbc97c 100644 --- a/examples/objective-c/hello_world/BUILD +++ b/examples/objective-c/hello_world/BUILD @@ -19,7 +19,6 @@ ios_application( families = ["iphone"], infoplists = ["Info.plist"], minimum_os_version = MINIMUM_IOS_VERSION, - deps = [ - "appmain", - ], + visibility = ["//visibility:public"], + deps = ["appmain"], ) diff --git a/examples/swift/async_await/BUILD b/examples/swift/async_await/BUILD index 12e6582b0d..4bf8737f70 100644 --- a/examples/swift/async_await/BUILD +++ b/examples/swift/async_await/BUILD @@ -6,8 +6,7 @@ licenses(["notice"]) # Apache 2 swift_library( name = "appmain", srcs = glob(["*.swift"]), - linkopts = ["-lNetwork"], - deps = ["//:envoy_mobile_ios"], + deps = ["//library/swift:ios_lib"], ) ios_application( @@ -16,5 +15,6 @@ ios_application( families = ["iphone"], infoplists = ["Info.plist"], minimum_os_version = "15.0", + visibility = ["//visibility:public"], deps = ["appmain"], ) diff --git a/examples/swift/hello_world/BUILD b/examples/swift/hello_world/BUILD index 123d5abc1c..9d0627e3dc 100644 --- a/examples/swift/hello_world/BUILD +++ b/examples/swift/hello_world/BUILD @@ -7,7 +7,7 @@ licenses(["notice"]) # Apache 2 swift_library( name = "appmain", srcs = glob(["*.swift"]), - deps = ["//:envoy_mobile_ios"], + deps = ["//library/swift:ios_lib"], ) ios_application( @@ -16,5 +16,6 @@ ios_application( families = ["iphone"], infoplists = ["Info.plist"], minimum_os_version = MINIMUM_IOS_VERSION, + visibility = ["//visibility:public"], deps = ["appmain"], ) diff --git a/test/swift/apps/baseline/BUILD b/test/swift/apps/baseline/BUILD index 96a3bf4c14..181dfaa93a 100644 --- a/test/swift/apps/baseline/BUILD +++ b/test/swift/apps/baseline/BUILD @@ -7,7 +7,7 @@ licenses(["notice"]) # Apache 2 swift_library( name = "appmain", srcs = glob(["*.swift"]), - deps = ["//:envoy_mobile_ios"], + deps = ["//library/swift:ios_lib"], ) ios_application( @@ -16,5 +16,6 @@ ios_application( families = ["iphone"], infoplists = ["Info.plist"], minimum_os_version = MINIMUM_IOS_VERSION, + visibility = ["//visibility:public"], deps = ["appmain"], ) diff --git a/test/swift/apps/experimental/BUILD b/test/swift/apps/experimental/BUILD index 123d5abc1c..9d0627e3dc 100644 --- a/test/swift/apps/experimental/BUILD +++ b/test/swift/apps/experimental/BUILD @@ -7,7 +7,7 @@ licenses(["notice"]) # Apache 2 swift_library( name = "appmain", srcs = glob(["*.swift"]), - deps = ["//:envoy_mobile_ios"], + deps = ["//library/swift:ios_lib"], ) ios_application( @@ -16,5 +16,6 @@ ios_application( families = ["iphone"], infoplists = ["Info.plist"], minimum_os_version = MINIMUM_IOS_VERSION, + visibility = ["//visibility:public"], deps = ["appmain"], ) diff --git a/tools/check_format.sh b/tools/check_format.sh index d57fff5c4d..7d4380d564 100755 --- a/tools/check_format.sh +++ b/tools/check_format.sh @@ -23,7 +23,7 @@ TARGET_PATH="$2" # TODO(mattklein123): WORKSPACE is excluded due to warning about @bazel_tools reference. Fix here # or in the upstream checker. ENVOY_BAZEL_PREFIX=@envoy envoy/tools/code_format/check_format.py \ - --add-excluded-prefixes ./envoy/ ./envoy_build_config/extensions_build_config.bzl ./WORKSPACE ./dist/ ./library/common/config_template.cc ./bazel/envoy_mobile_swift_bazel_support.bzl ./bazel/envoy_mobile_repositories.bzl \ + --add-excluded-prefixes ./envoy/ ./envoy_build_config/extensions_build_config.bzl ./WORKSPACE ./Envoy.xcodeproj/ ./dist/ ./library/common/config_template.cc ./bazel/envoy_mobile_swift_bazel_support.bzl ./bazel/envoy_mobile_repositories.bzl \ --skip_envoy_build_rule_check "$ENVOY_FORMAT_ACTION" $TARGET_PATH \ --namespace_check_excluded_paths ./envoy ./examples/ ./library/java/ ./library/kotlin ./library/objective-c ./test/java ./test/java ./test/objective-c ./test/swift ./experimental/swift \ --build_fixer_check_excluded_paths ./envoy ./BUILD ./dist ./examples ./library/java ./library/kotlin ./library/objective-c ./library/swift ./library/common/extensions ./test/java ./test/kotlin ./test/objective-c ./test/swift ./experimental/swift