Similar to our LLVM-On-iOS project and actually thank to the experience from that project, we develop this project to provide scripts and YAML pipeline to build LibGit2 and its dependencies (OpenSSL, PCRE and LibSSH2) on Azure DevOps (a.k.a. VSTS) as XCFrameworks that could be easily embedded in Xcode iOS/Mac Catalyst project.
If you want to build the frameworks on your own machine, simply execute the script
build-libgit2-framework.shat the root of this repository. See here for our CI builds on Azure DevOps.
A tip for Windows user: Instead of using swift package compute-checksum, one can also compute checksum with
CertUtil -hashfile Clibgit2.xcframework.zip SHA256Method 0: Interoperate Swift, C/C++ and Objective-C via bridging header as described in our LLVM-On-iOS project.
Method 1: You can download the prebuilt XCFramework, extract and add it directly to your Xcode iOS app project. Then simply
import Clibgit2and then use the libgit2 API directly.
The built XCFramework is also released as a Swift Package at https://github.com/light-tech/Clibgit2.
But be ready to write not-very-Swift-y Swift code.
Method 2: Our recommended way is to use the Swift Package available on the spm branch of our fork of SwiftGit2.
SwiftGit2 takes care of the not-very-Swift-y Swift code.
See the screenshots in our example app below.
To test, you can get our iOS example app project by cloning
git clone https://github.com/light-tech/SwiftGit2-SampleApp.gitThe first thing that might have come to your mind is:
Why another work on libgit2? Didn't we already have SwiftGit2?
The reasons:
- Contrary to the first impression,
SwiftGit2currently doesn't compiled for iOS unless one reverts back to an earlier version. The reason is thatlibgit2now depends onlibpcrewhich is only supplied in Xcode's MacOS SDK but not iOS SDK; hence we will run into missing symbolspcre_*****when using it in an iOS app. SwiftGit2isn't very actively maintained. It still uses the older fat binary (which cannot support MacOS, Mac Catalyst and iPhone Simulator simultaneously since all 3 have the same underlying CPU architecture x86_64 but different ABI) instead of switching to XCFramework.- We are only aware of this blog post after doing this work. And the post doesn't build
libpcrewhich is necessary for many Git features on iOS. - We do not intend to replace
SwiftGit2but to extract and update its outdated building scripts.
This project is public domain. That is, there is no license attached.
Feel free to do what you want with it.
However, the usage of the result library built by our script is still subjected to libgit2, pcre, openssl and libssh2 license.