Use a C++ library in swift package manager - swift

I want to use two frameworks (fat) and one C++ library in my swift package manager project. I know it's possible to convert those frameworks to XCframework that SPM can use that, but not sure that converting process works with all frameworks?
My main question is, there is a c++ library in the package as well, its description is:
libsioclient_tls.a - this library includes the Socket.IO C++ client with TLS features.
Is it possible to add this on swift package manager, and if yes, could you please guide me?
Thank you so much

Related

Setting up Vapor and Clang in the same project

My project is based on Vapor.
The aim is to use libclang, build a wrapper on top of it in C language. Then, make this library available from swift.
How can I mix the two? Preferably still building my project from XCode.
You can build C modules in Swift Package Manager fairly easily, see here for more information.
To wrap a system C library, see instructions here

Swift Run Time Library vs. Swift Standard Library

In this tutorial on how to use CocoaPods I am having trouble understanding the following paragraph:
Unlike Objective-C, the standard Swift runtime libraries aren’t
included in iOS! This means your framework must include the necessary
Swift runtime libraries. As a consequence, pods written in Swift must
be created as dynamic frameworks. If Apple allowed Swift static
libraries, it would cause duplicate symbols across different libraries
that use the same standard runtime dependencies.
Here are my questions:
What exactly are the "standard Swift Runtime Libraries"? Is the Swift Standard Library one such standard swift run time library, would a framework I write in swift be considered a swift run time library?
What exactly does "Swift runtime libraries are not included in iOS" mean? I guess I am having trouble inferring what "iOS" refers too.
Any additional insight, links, resources or explanations regarding this paragraph would be greatly appreciated!
Edit:
After reading the runtime library wiki article I am no longer confused about Q1. The following paragraph clarified this for me:
The concept of a runtime library should not be confused with an
ordinary program library like that created by an application
programmer or delivered by a third party, nor with a dynamic library,
meaning a program library linked at run time. For example, the C
programming language requires only a minimal runtime library (commonly
called crt0), but defines a large standard library (called C standard
library) that has to be provided by each implementation.
However I am still confused about Q2.
Objective C has a stable (unchanging) runtime library, so it makes sense for there to be one shared copy of the library, provided by the OS (macOS/iOS), available to all applications that need it. In contrast Swift is a rapidly evolving language, which means that its runtime library undergoes vast changes between versions. Because of this, Xcode bundles in a copy of the Swift runtime library as part of each app, to ensure that a copy of the correct version (the version the app uses) of the runtime library is available to the app.
Swift Standard Library vs Swift Run Time Library
[Swift Standard Library]
Swift Run Time Library is a part of Swift Standard Library
Before iOS v12.2 there were not ABI[About] stability on iOS level, that is why you could see a lot of frameworks(Swift standard library[About]) inside each built target
Also you are able to adjust it via Always Embed Swift Standard Libraries(ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES) for targets before iOS v12.2

SFTP libraries for iPhone?

Are there any good SFTP libraries other than libssh2?? I'm especially looking for a library that is very easy to integrate and manage! As libssh2 is completely written in C, I find adding extensions to the existing code base rather difficult!
Thanks!!
There are some Objective-C wrappers for libssh2 on GitHub:
NMSSH by Lejdborg (personally, this is my favourite. Super easy to use and well documented)
libssh2_sftp-Cocoa-wrapper by karelia
DLSFTPClient - by Leehro
And some more... These are the most popular ones.
If you are developing using Swift, below wrapper libraries can be used.
SwiftSH - A Swift SSH framework that wraps libssh2.

is there any third party tool to create static library for armv6/armv7?

I have some source code in C/C++. I have to make static library to use in my iPhone application. is there any third party tool to create static library for armv6/armv7 ?
this link will help you create a static library in xcode ...
http://www.icodeblog.com/2011/04/07/creating-static-libraries-for-ios/
just rename the .m file to .mm file and write your c/c++ implementation code in it....
try it for a small function first and if it works for you can implement all your classes in it...
Please make sure when you try to use this library in any other project in XCODE , only use .mm extension for all your files even the appdelegate... hope this helps.
I would recommend iOS Universal Framework. I have used it to create a number of static frameworks that I link against my application projects. It works like a charm and is really easy to setup - no need to come up with your own complicated shell scripts.
It adds a template for a new target project type, which you can then import and use just like an ordinary Apple framework. I would recommend setting up a workspace containing both the framework project and application project, that way the dependencies are handled automatically by Xcode.
In general, you DO NOT WANT to link to a static lib that is made with another compiler than the one used to compile the lib. Static libs are not really portable between compilers, since static lib formats are not covered by C/C++ standards. Due to name mangling and other formatting differences, you may not be able to link at all, or worse, it seems to work but injects bugs. Worse, if you use the standard library from your compiler in your lib, it will create horrible name collisions when someone links to your lib and they don't use an IDENTICAL version of the standard library!
Publish the lib using the compiler you expect them to be using. And if you must use the standard library, then you have to make sure they have the same version you have. Really, you should just have them compile the lib themselves or prebuild it for each compiler you support. It sucks, but that's the reality of it as it stands today.

Compile C library as iPhone framework?

Each C/C++ library has some amount of headers that should be used with that library. And if you're use more than 1-2 libraries, custom header paths is kind of headache.
So I thought: is there a way to compile C libraries as frameworks. Static library + headers + versioning.
I found in XCode template for Cocoa framework but nothing about iPhone framework building. This simple step could allow developers to build and share between each other frameworks with some interesting code.
Also it would be great to use libpng, libjpeg and other libraries packaged as frameworks.
I won't use dynamic libraries in those frameworks. Only static version will be present.
I combined techniques I found here and here into my open source library here (NOTE - I have since removed the relevant scripts from this project. I have updated the link to point to the last revision that included these techniques.). Think that's basically the solution you're looking for.
Basically, it has a target that will build a fat static library (lipo builds for arm6, arm7 and i386). It has another target that takes that library and builds it into a framework.
There's no reason you can't use the same techniques for a C project. In fact I've started work on porting C the VTD XML parser to an Objective C framework using the same techniques.
Frameworks are basically just bundles of dynamic/shared libraries. Since this is not allowed in the App Store, you have to build static libraries and link them with your App's executable at compile time.
However, to ease the pain a little, you can have a Xcode project for each library and compile each library into a static lib. Another way would be to put all required source files into the main Xcode project and configure it appropriately so it all builds at once (I did this with small libraries like Minizip, for instance).
Hope that helps.
the problem you are trying to make already exists - it's called DLL hell
Best way is to stick with plain old static libraries when making small apps and organizing source/headers structure