swift: Xcode 14.3 RC 2 (14E222b)/Swift Compiler 5.8 SwiftVerifyEmittedModuleInterface failed to verify module interface

Description

Use Xcode 14.3 RC 2 compile a swift file which import a objc clang module, and a framework with swiftinterface, verify module interface happened error. The clang module path is explicitly passed by -fmodule-map-file.

Steps to reproduce 1、download SwiftVerifyInterfaceIssue.zip and unzip 2、Use Xcode 14.3 RC 2 open SwiftVerifyInterfaceIssue.xcworkspace, and then build

Expected behavior build success

image

Environment

  • Swift compiler version info swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
  • Xcode version info Xcode 14.3 Build version 14E222b

SwiftVerifyInterfaceIssue.zip

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 7
  • Comments: 26 (8 by maintainers)

Commits related to this issue

Most upvoted comments

There are a few alternatives I would recommend to workaround the issue of name ambiguities and get a usable swiftinterface. Here they are in order of reliability:

  1. Even though it’s a common pattern, when possible and when you own the offending module, avoid using the same name for a type and a module. This is the best way to dodge this problem entirely.
  2. Add -module-interface-preserve-types-as-written to Other Swift Flags to print type references in the swiftinterface the way they were written in code. There may still be errors on synthesized code, usually conformances to Hashable and Equatable, which can be avoided by explicitly declaring these conformances in the sources to prevent the compiler from synthesizing them.
  3. Add -alias-module-names-in-module-interface to Other Swift Flags for the compiler to print modules references in swiftinterfaces in a way to avoid ambiguities. This one is more experimental, there could be rough edges. Please file issues or feedbacks if it causes any problems.
  4. If all else fails, I’d recommend writing a script to post-process the swiftinterface, removing the instances of MyModule. is often enough. Since the scripts usually run after the verification, you may have to disable the verification by adding -no-verify-emitted-module-interface to Other Swift Flags.

In the future, the proper fix to this issue is the language support for fully qualified names. This feature was discussed in the forums at https://forums.swift.org/t/pitch-fully-qualified-name-syntax/28482

Also note that SWIFT_INSTALL_OBJC_HEADER=YES automatically disables the verification, so even if you don’t see an error the swiftinterface may still be broken.

set it, nothing happens

You got a typo, the option is spelled no-verify-emitted-module-interface (swiftc -h to verify).

Screenshot 2023-05-15 at 2 32 07 PM I set it, nothing happens

@super-gsevla put the -no-verify-emitted-module-interface flag on the faild target. e.g the SwiftPodA compile failed because of verify module interface, then put -no-verify-emitted-module-interface on the SwiftPodA target. image

if you use CocoaPods, you can add
s.xcconfig = { 'OTHER_SWIFT_FLAGS' => '-no-verify-emitted-module-interface' } to the SwiftPodA.podspec

-no-verify-emitted-module-interface

You can try change the default behavior of the Swift compiler by passing -no-verify-emitter-module-interface to OTHER_SWIFT_FLAGS

The solution of adding -no-verify-emitted-module-interface worked for running on simulator. Fails to run on a real device.

UPD: Ok I build it for spm:

  1. I created Release.xcconfig
  2. added one line: OTHER_SWIFT_FLAGS = -no-verify-emitted-module-interface
  3. added this file to config as param for xcodebuild
xcodebuild archive -scheme schemeName \                                                                                                                                                 
	 -disableAutomaticPackageResolution \
	 -destination "generic/platform=iOS" \
	 -archivePath Release-iphoneos \
	 -configuration Release \
	 -derivedDataPath ".build" \
	 -xcconfig Release.xcconfig \
	 -UseModernBuildSystem=YES \
	 SKIP_INSTALL=NO \
	 BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
	 DEPLOYMENT_POSTPROCESSING=YES \
	 STRIP_INSTALLED_PRODUCT=YES \
	 SWIFT_INSTALL_OBJC_HEADER=YES \
	 GENERATE_MASTER_OBJECT_FILE=NO \
	 STRIP_STYLE=non-global
  1. profit

@xymus Thanks, for your useful advice!

Looks like xcode 14.3 useless for us now… and should we downgrade to 14.2?

The workarounds are working for us but we would like to know if this is intended behavior as of Xcode 14.3, or if this is a bug. We created the following radar under our team.

For my side, adding no-verify-emitter-module-interface (without the first -) to OTHER_SWIFT_FLAGS works