mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
There are two main scenarios when printing a compatibility header that references a @cdecl enum defined in Swift code. (1) When defined in the same module as it's used we can print the definition normally and then reference it. (2) When used in a different mode we need to print a forward declaration before we can reference it. This change adds printing the forward declaration and fix an issue where the compiler would instead print an @include of the Swift module. The import of the Swift module would work only in a local scenario where a compatibility header and module would be generated under the same name. However for a distributed frameworks we do not distribute the compatibility header so this strategy doesn't work. Relying on a forward declaration should be more reliable in all cases but clients may need to import the other compatibility header explicitly.
46 lines
1.3 KiB
Swift
46 lines
1.3 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
|
|
/// Build CoreLib defining a @cdecl enum.
|
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
|
|
// RUN: %t/CoreLib.swift -emit-module -verify -o %t \
|
|
// RUN: -emit-clang-header-path %t/CoreLib.h \
|
|
// RUN: -enable-experimental-feature CDecl
|
|
// RUN: %check-in-clang-c %t/CoreLib.h -I %t
|
|
|
|
/// Build MiddleLib using the @cdecl enum in API.
|
|
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
|
|
// RUN: %t/MiddleLib.swift -emit-module -verify -o %t -I %t \
|
|
// RUN: -emit-clang-header-path %t/MiddleLib.h \
|
|
// RUN: -enable-experimental-feature CDecl
|
|
// RUN: %FileCheck %s --input-file %t/MiddleLib.h
|
|
// RUN: %check-in-clang-c %t/MiddleLib.h -I %t
|
|
|
|
/// Build a client.
|
|
// RUN: %clang-no-modules -c %t/Client.c -I %t \
|
|
// RUN: -F %S/../Inputs/clang-importer-sdk-path/frameworks \
|
|
// RUN: -I %clang-include-dir -Werror \
|
|
// RUN: -isysroot %S/../Inputs/clang-importer-sdk
|
|
|
|
// REQUIRES: swift_feature_CDecl
|
|
|
|
//--- CoreLib.swift
|
|
@cdecl("CEnum")
|
|
public enum CEnum: CInt { case A, B }
|
|
|
|
//--- MiddleLib.swift
|
|
import CoreLib
|
|
|
|
@cdecl("CFunc")
|
|
public func CFunc(e: CEnum) {}
|
|
// CHECK: typedef SWIFT_ENUM_FWD_DECL(int, CEnum)
|
|
// CHECK: SWIFT_EXTERN void CFunc(SWIFT_ENUM_TAG CEnum e) SWIFT_NOEXCEPT;
|
|
|
|
//--- Client.c
|
|
#include "CoreLib.h"
|
|
#include "MiddleLib.h"
|
|
|
|
int main() {
|
|
CFunc(CEnumA);
|
|
}
|