Skip to content

[cxx-interop] Provide a support header for common attributes, etc. #63839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ add_dependencies(swiftClangImporter
${CLANG_TABLEGEN_TARGETS})

set_swift_llvm_is_available(swiftClangImporter)

# Mark - copy "swift-interop-support.h" into the local include directory and install it
# into the compiler toolchain.
set(SWIFTINC_DIR
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/include/swift")

add_custom_command(
OUTPUT "${SWIFTINC_DIR}/swift-interop-support.h"
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${CMAKE_CURRENT_SOURCE_DIR}/swift-interop-support.h" "${SWIFTINC_DIR}")

add_custom_target("copy_cxxInterop_support_header"
DEPENDS "${SWIFTINC_DIR}/swift-interop-support.h"
COMMENT "Copying C++ interop support header to ${SWIFTINC_DIR}")

swift_install_in_component(FILES "${CMAKE_CURRENT_SOURCE_DIR}/swift-interop-support.h"
DESTINATION "include/swift"
COMPONENT compiler)

add_dependencies(swiftClangImporter
"copy_cxxInterop_support_header")
31 changes: 31 additions & 0 deletions lib/ClangImporter/swift-interop-support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===--- swift-interop-support.h - C++ and Swift Interop --------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file provides common utilities and annotations that are useful for C++
// codebases that interoperate with Swift.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H
#define SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H

#define SELF_CONTAINED __attribute__((swift_attr("import_owned")))
#define SAFE_TO_IMPORT __attribute__((swift_attr("import_unsafe")))

#define _CXX_INTEROP_STRINGIFY(_x) #_x
#define SWIFT_REFERENCE_TYPE(_retain, _release) \
__attribute__((swift_attr("import_reference"))) \
__attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:_retain)))) \
__attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:_release))))

#define SWIFT_NAME(_name) __attribute__((swift_name(#_name)))

#endif // SWIFT_CLANGIMPORTER_SWIFT_INTEROP_SUPPORT_H