Swift Serialize Debugging Options


Overview

Initially, this was an undocumented Swift frontend flag. Neither swift -help nor swift -help-hidden showed this flag (as of Xcode 12.0 beta). However, it’s now documented in

$ swift -frontend -help

  -no-serialize-debugging-options
      Never serialize options for debugging (default: only for apps)
  -serialize-debugging-options
      Always serialize options for debugging (default: only for apps)

In Xcode, the equivalent build setting is SWIFT_SERIALIZE_DEBUGGING_OPTIONS. Below is the relevant information found in the Swift.xcspec file bundled with Xcode.

{
  Name = "SWIFT_SERIALIZE_DEBUGGING_OPTIONS";
  Type = Boolean;
  DefaultValue = YES;
  CommandLineArgs = {
    YES = ( "-Xfrontend", "-serialize-debugging-options" );
    NO  = ();
  };
},

When passed to the Swift compiler, this expands to -Xfrontend -serialize-debugging-options. You can disable it by setting either

SWIFT_SERIALIZE_DEBUGGING_OPTIONS = NO

or

OTHER_SWIFT_FLAGS = -Xfrontend -no-serialize-debugging-options

in your target’s build settings (note the -no prefix).

Discussions

When building with this flag enabled, the debugging information in the generated .swiftmodule will include Swift module/framework search paths and extra Clang flags, embedded as absolute paths.

If you’re building libraries or frameworks for third-party distribution, it’s advisable to disable this flag in your release builds. It’s been reported that enabling it in the builds that you distribute to your users might impair their debugging experience.

Enabling it also means your builds will lack portability—you won’t be able to build your Swift module on one machine and debug it on another. If you’re using a build system that relies on cacheable builds, like Bazel or Buck, you might want to disable this flag. To work around the debugging issue, you could manually reconstruct the search paths and extra Clang flags by editing your ~/.lldbinit file, like so:

settings set -- target.swift-extra-clang-flags <flags>
settings set -- target.swift-framework-search-paths <paths>
settings set -- target.swift-module-search-paths <paths>

However, this solution might not work in all cases.

References