Files
swift-mirror/test/Interop/Cxx/stdlib/use-std-string.swift
Egor Zhdan a3e914364a [cxx-interop] Import libstdc++ as a Clang module
This change adds a module map for libstdc++, which allows it to be properly imported into Swift as a module. The module map is installed into `usr/lib/swift/linux/{arch}` similarly to `glibc.modulemap`, and is passed to Clang as `-fmodule-map-file`.

That means it is now possible to import std directly from Swift on Linux, when C++ interop is enabled.

The module map currently declares a single `std` module without splitting the headers into submodules. This is going to change in the near future.

rdar://87654514
2022-04-08 14:10:04 +01:00

34 lines
780 B
Swift

// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
//
// REQUIRES: executable_test
//
// Enable this everywhere once we have a solution for modularizing other C++ stdlibs: rdar://87654514
// REQUIRES: OS=macosx || OS=linux-gnu
import StdlibUnittest
import StdString
#if os(Linux)
import std
// FIXME: import std.string once libstdc++ is split into submodules.
#else
import std.string
#endif
var StdStringTestSuite = TestSuite("StdString")
StdStringTestSuite.test("init") {
let s = CxxString()
expectEqual(s.size(), 0)
expectTrue(s.empty())
}
StdStringTestSuite.test("push back") {
var s = CxxString()
s.push_back(42)
expectEqual(s.size(), 1)
expectFalse(s.empty())
expectEqual(s[0], 42)
}
runAllTests()