Skip to content

[libc++] Add a few basic tests for C++ / Swift interoperation #104863

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

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 21 additions & 0 deletions libcxx/test/libcxx/vendor/apple/swift-interop.sh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// This test requires access to the Swift compiler, which we assume is only available on Apple
// platforms for now.
// REQUIRES: buildhost=darwin

// std::string basic test
// RUN: swiftc -cxx-interoperability-mode=default %S/swift-interop/string/main.swift -o %t.string.exe \
// RUN: -Xcc -nostdinc++ -Xcc -nostdlib++ -Xcc -isystem -Xcc "%{include-dir}"
// RUN: %{exec} %t.string.exe

// std::vector test with a modulemap
// RUN: swiftc -cxx-interoperability-mode=default %S/swift-interop/vector/main.swift -o %t.vector.exe \
// RUN: -Xcc -nostdinc++ -Xcc -nostdlib++ -Xcc -isystem -Xcc "%{include-dir}" -Xcc -I -Xcc %S/swift-interop/vector
// RUN: %{exec} %t.vector.exe
13 changes: 13 additions & 0 deletions libcxx/test/libcxx/vendor/apple/swift-interop/string/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

import CxxStdlib

let s: std.string = "abc123"

for char in s { print(char) }
13 changes: 13 additions & 0 deletions libcxx/test/libcxx/vendor/apple/swift-interop/vector/header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <vector>

using VectorOfInt = std::vector<int>;

inline VectorOfInt getStdVector() { return {1, 2, 3}; }
13 changes: 13 additions & 0 deletions libcxx/test/libcxx/vendor/apple/swift-interop/vector/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

import MyCxxDep // no explicit import of CxxStdlib

let vec = getStdVector()

for it in vec { print(it) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyCxxDep {
header "header.h"
export *
}
Loading