diff --git a/rules/BUILD.bazel b/rules/BUILD.bazel index 5fbd192ae..65bfb0ef7 100644 --- a/rules/BUILD.bazel +++ b/rules/BUILD.bazel @@ -1,4 +1,39 @@ + +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") +load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") + + exports_files( glob(["*.bzl"]), visibility = ["//docs:__pkg__"], ) + +genrule( + name = "empty", + outs = ["empty.swift"], + cmd = "touch $(OUTS)", +) + +# A dummy target that enables serialize-debugging-options but only in local development, +# so that swiftmodule paths will refer to paths on the local machine and LLDB will work. +swift_library( + name = "_LocalDebugOptions", + srcs = [":empty"], + copts = [ + "-Xfrontend", + "-serialize-debugging-options", + ], + module_name = "_LocalDebugOptions", + tags = ["no-remote"], + visibility = ["//visibility:public"], +) + + +bool_flag(name = "local_debug_options_enabled", build_setting_default = False) + +config_setting( + name = "local_debug_options", + flag_values = { + ":local_debug_options_enabled": "True", + } +) diff --git a/rules/app.bzl b/rules/app.bzl index 330e6bee5..1c73d4594 100644 --- a/rules/app.bzl +++ b/rules/app.bzl @@ -61,9 +61,16 @@ def ios_application(name, apple_library = apple_library, **kwargs): application_kwargs["launch_storyboard"] = application_kwargs.pop("launch_storyboard", library.launch_screen_storyboard_name) application_kwargs["families"] = application_kwargs.pop("families", ["iphone", "ipad"]) + local_debug_options_for_swift = [] + if library.has_swift_sources: + local_debug_options_for_swift += ["@build_bazel_rules_ios//rules:_LocalDebugOptions"] + rules_apple_ios_application( name = name, - deps = library.deps, + deps = library.deps + select({ + "@build_bazel_rules_ios//rules:local_debug_options": local_debug_options_for_swift, + "//conditions:default": [], + }), infoplists = infoplists, **application_kwargs ) diff --git a/rules/library.bzl b/rules/library.bzl index 1b65c55cf..0444c2db3 100644 --- a/rules/library.bzl +++ b/rules/library.bzl @@ -608,4 +608,5 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names namespace = namespace, linkopts = linkopts, platforms = platforms, + has_swift_sources = (swift_sources and len(swift_sources) > 0), ) diff --git a/rules/test.bzl b/rules/test.bzl index f8b456de2..11cd7c6e6 100644 --- a/rules/test.bzl +++ b/rules/test.bzl @@ -44,8 +44,15 @@ def ios_unit_test(name, apple_library = apple_library, **kwargs): library = apple_library(name = name, namespace_is_module_name = False, platforms = {"ios": unit_test_kwargs.get("minimum_os_version")}, **kwargs) + local_debug_options_for_swift = [] + if library.has_swift_sources and not unit_test_kwargs.get("test_host", None): + local_debug_options_for_swift += ["@build_bazel_rules_ios//rules:_LocalDebugOptions"] + rule( name = name, - deps = library.lib_names, + deps = library.lib_names + select({ + "@build_bazel_rules_ios//rules:local_debug_options": local_debug_options_for_swift, + "//conditions:default": [], + }), **unit_test_kwargs ) diff --git a/tests/macos/xcodeproj/build.sh b/tests/macos/xcodeproj/build.sh index 9f7031d52..1f7c68a61 100755 --- a/tests/macos/xcodeproj/build.sh +++ b/tests/macos/xcodeproj/build.sh @@ -4,4 +4,5 @@ cd $(dirname $0) xcodebuild -project Single-Application-Project-DirectTargetsOnly.xcodeproj -quiet xcodebuild -project Single-Application-Project-AllTargets.xcodeproj -quiet -xcodebuild -project Test-Target-With-Test-Host-Project.xcodeproj -quiet \ No newline at end of file +xcodebuild -project Test-Target-With-Test-Host-Project.xcodeproj -quiet +# TODO: use strings to test that absolute paths and debug-prefix-map are present in the LocalDebug.swiftmodule. Not sure if this is the right palce to do it. We could also grep out the build event text file maybe. \ No newline at end of file diff --git a/tools/xcodeproj_shims/build-wrapper.sh b/tools/xcodeproj_shims/build-wrapper.sh index efa94c349..8c7e4ba08 100755 --- a/tools/xcodeproj_shims/build-wrapper.sh +++ b/tools/xcodeproj_shims/build-wrapper.sh @@ -1,4 +1,4 @@ #!/bin/bash set -euxo pipefail -$BAZEL_PATH build --experimental_execution_log_file=$BAZEL_BUILD_EXECUTION_LOG_FILENAME --build_event_text_file=$BAZEL_BUILD_EVENT_TEXT_FILENAME --build_event_publish_all_actions $1 2>&1 | $BAZEL_OUTPUT_PROCESSOR +$BAZEL_PATH build --experimental_execution_log_file=$BAZEL_BUILD_EXECUTION_LOG_FILENAME --build_event_text_file=$BAZEL_BUILD_EVENT_TEXT_FILENAME --build_event_publish_all_actions $1 --@build_bazel_rules_ios//rules:local_debug_options_enabled 2>&1 | $BAZEL_OUTPUT_PROCESSOR