Also note that Swift 5.7 does not support this functionality. You will want to try this on a Swift-5.8 or main align toolchain downloaded from swift.org.
If that's a practical need and you need it today – you can call swift from C++ (and back) via Obj-C inter-op (the class would have to be NSObject subclass) or via registering swift callback (either as convention (c) with a C function pointer, or a normal if you can tolerate using "blocks" on the C side). Ask here or privately if you are new to this and want to know details of those alternatives.
Using Swift 5.8 toolchain and adding @_expose(Cxx) made the module header contain the Swift class for C++, and I succeeded in calling a Swift class from a C++ class.
Thank you for your advices!
(Just for those who has visited here)
The Swift file became
@_expose(Cxx)
public class MyClass {
public init() { /* just make it public */ }
public func speak() {
print("Hello, 334")
}
}
The module header generation command is
xcrun --toolchain swift swiftc -c MyClass.swift -emit-objc-header -module-name MySwiftModule -enable-experimental-cxx-interop