Skip to content

Commit a6bd784

Browse files
committed
[cxx-interop] Provide a support header for common attributes, etc.
1 parent 8e0e51a commit a6bd784

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/ClangImporter/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,24 @@ add_dependencies(swiftClangImporter
4242
${CLANG_TABLEGEN_TARGETS})
4343

4444
set_swift_llvm_is_available(swiftClangImporter)
45+
46+
# Mark - copy "cxx-interop.h" into the local include directory and install it
47+
# into the compiler toolchain.
48+
set(SWIFTINC_DIR
49+
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/swift")
50+
51+
add_custom_command(
52+
OUTPUT "${SWIFTINC_DIR}/cxx-interop.h"
53+
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/cxx-interop.h" "${SWIFTINC_DIR}")
54+
55+
add_custom_target("copy_cxxInterop_support_header"
56+
DEPENDS "${SWIFTINC_DIR}/cxx-interop.h"
57+
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")
58+
59+
swift_install_in_component(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cxx-interop.h"
60+
TARGET ${SWIFT_CLANG_RESOURCE_DIR_SYMLINK_INSTALL_TARGET}
61+
DESTINATION "include/swift"
62+
COMPONENT compiler)
63+
64+
add_dependencies(swiftClangImporter
65+
"copy_cxxInterop_support_header")

lib/ClangImporter/cxx-interop.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===--- cxx-interop.h - C++ and Swift Interop ------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file provides common utilities and annotations that are useful for C++
14+
// codebases that interoperate with Swift.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
#ifndef SWIFT_CLANGIMPORTER_CXX_INTEROP_H
18+
#define SWIFT_CLANGIMPORTER_CXX_INTEROP_H
19+
20+
#define SELF_CONTAINED __attribute__((swift_attr("import_owned")))
21+
#define SAFE_TO_IMPORT __attribute__((swift_attr("import_unsafe")))
22+
23+
#define _CXX_INTEROP_STRINGIFY(_x) #_x
24+
#define REFERENCE(_retain, _release) \
25+
__attribute__((swift_attr("import_reference"))) \
26+
__attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:_retain)))) \
27+
__attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:_release))))
28+
29+
#define SWIFT_NAME(_name) __attribute__((swift_name(#_name)))
30+
31+
#endif // SWIFT_CLANGIMPORTER_CXX_INTEROP_H

0 commit comments

Comments
 (0)