Swift Serialize Debugging Options
Overview
This is an undocumented Swift frontend flag. Neither invoking Update: This
is documented inswift -help
nor swift -help-hidden shows this flag (as of Xcode 12.0 beta).
$ 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)
The equivalent build setting in Xcode is SWIFT_SERIALIZE_DEBUGGING_OPTIONS.
Below is the information found in the Swift.xcspec file bundled within Xcode.
{
Name = "SWIFT_SERIALIZE_DEBUGGING_OPTIONS";
Type = Boolean;
DefaultValue = YES;
CommandLineArgs = {
YES = ( "-Xfrontend", "-serialize-debugging-options" );
NO = ();
};
},
This expands to -Xfrontend -serialize-debugging-options when
passing to the Swift compiler. You could disable it by either setting
SWIFT_SERIALIZE_DEBUGGING_OPTIONS = NO
or
OTHER_SWIFT_FLAGS = -Xfrontend -no-serialize-debugging-options
in your target’s build settings (notice the -no prefix).
Discussions
When building with this flag enabled, the debugging information in the
generated .swiftmodule will include the information of Swift module/framework
search paths and extra Clang flags embedded as absolute paths.
If you build libraries or frameworks for third-party distribution, you should disable this flag in your release builds. It is reported that enabling it in the builds that you distribute to your users may break their debugging experience.
Enabling it also means that your builds will not be portable—you won’t be
able to build your Swift module on a machine and debug it on another. If you
use a build system that relies on cacheable builds like Bazel or Buck, you may
want to disable this flag. To work around the debugging problem, you could
manually reconstruct the search paths and extra Clang flags by editing your
~/.lldbinit file; for example:
settings set -- target.swift-extra-clang-flags <flags>
settings set -- target.swift-framework-search-paths <paths>
settings set -- target.swift-module-search-paths <paths>
Though, it may not work in all cases.
References
- Improving Path Remappings for ExtraClangArgs/SwiftASTContext
- Xcode could not resolve type from dSYM if build folder is different
- Debuggable Remotely Built Swift
- Couldn’t IRGen expression, no additional error
- Couldn’t IRGen expression, no additional error; with -no-serialize-debugging-options
- How to Fix LLDB: Couldn’t IRGen Expression