diff options
author | Dmitry Shevchenko <dmishe@google.com> | 2016-10-19 18:31:40 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2016-10-19 19:21:01 +0000 |
commit | fc0b635652c566c8f4db00fe317377803a9211d1 (patch) | |
tree | ba163c4a31cd4275b7ed2a71eb31b9de4e806a09 | |
parent | d0a08e5c64b7ce9f5d4c6a83c8398bb42b26cdb2 (diff) |
Add swiftmodule outputs to the linking step.
* This change enables most of LLDB functionality on binaries built by swift_library.
It makes the linker record references to the .swiftmodule outputs, which then can be read by LLDB to deserialize Swift modules and provide debug info.
--
MOS_MIGRATED_REVID=136620475
-rwxr-xr-x | src/test/shell/bazel/apple/bazel_apple_test.sh | 38 | ||||
-rw-r--r-- | tools/build_defs/apple/swift.bzl | 12 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/test/shell/bazel/apple/bazel_apple_test.sh b/src/test/shell/bazel/apple/bazel_apple_test.sh index a2546b3de7..9831b319f7 100755 --- a/src/test/shell/bazel/apple/bazel_apple_test.sh +++ b/src/test/shell/bazel/apple/bazel_apple_test.sh @@ -740,4 +740,42 @@ EOF expect_log "Error in target '//ios:bad-dep'" } +function test_swift_ast_is_recorded() { + rm -rf ios + mkdir -p ios + + touch ios/main.swift + touch ios/dep.swift + + cat >ios/main.m <<EOF +#import <UIKit/UIKit.h> + +int main(int argc, char *argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, nil); + } +} +EOF + + cat >ios/BUILD <<EOF +load("//tools/build_defs/apple:swift.bzl", "swift_library") + +swift_library(name = "dep", + srcs = ["dep.swift"]) + +swift_library(name = "swift_lib", + srcs = ["main.swift"], + deps = [":dep"]) +objc_binary(name = "bin", + srcs = ["main.m"], + deps = [":swift_lib"]) +EOF + + bazel build --verbose_failures --ios_sdk_version=$IOS_SDK_VERSION \ + --xcode_version=$XCODE_VERSION -s \ + //ios:bin >$TEST_log 2>&1 || fail "should build" + expect_log "-Xlinker -add_ast_path -Xlinker bazel-out/local-fastbuild/genfiles/ios/dep/_objs/ios_dep.swiftmodule" + expect_log "-Xlinker -add_ast_path -Xlinker bazel-out/local-fastbuild/genfiles/ios/swift_lib/_objs/ios_swift_lib.swiftmodule" +} + run_suite "apple_tests" diff --git a/tools/build_defs/apple/swift.bzl b/tools/build_defs/apple/swift.bzl index 48596f5665..deb8027647 100644 --- a/tools/build_defs/apple/swift.bzl +++ b/tools/build_defs/apple/swift.bzl @@ -247,6 +247,15 @@ def _swift_library_impl(ctx): framework_args = ["-F%s" % x for x in framework_dirs] define_args = ["-D%s" % x for x in swiftc_defines] + # This tells the linker to write a reference to .swiftmodule as an AST symbol + # in the final binary. + # With dSYM enabled, this results in a __DWARF,__swift_ast section added to + # the dSYM binary, from where LLDB is able deserialize module information. + # Without dSYM, LLDB will follow the AST references, however there is a bug + # where it follows only the first one https://bugs.swift.org/browse/SR-2637 + # This means that dSYM is required for debugging until that is resolved. + extra_linker_args = ["-Xlinker -add_ast_path -Xlinker " + output_module.path] + clang_args = _intersperse( "-Xcc", @@ -317,7 +326,8 @@ def _swift_library_impl(ctx): library=set([output_lib] + dep_libs), header=set([output_header]), providers=objc_providers, - linkopt=_swift_linkopts(ctx), + linkopt=_swift_linkopts(ctx) + extra_linker_args, + link_inputs=set([output_module]), uses_swift=True,) return struct( |