Skip to content

Commit 68c4e0c

Browse files
committed
v1.1.0
1 parent 886a44b commit 68c4e0c

File tree

8 files changed

+205
-107
lines changed

8 files changed

+205
-107
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
[submodule "iSSH2"]
55
path = iSSH2
66
url = https://github.com/sharplet/iSSH2.git
7+
branch = main

.swiftlint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trailing_comma:
2+
mandatory_comma: true

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 Adam Sharp.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

Package.swift

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import PackageDescription
44

55
let package = Package(
66
name: "swift-cgit2",
7+
platforms: [
8+
.macOS(.v10_13),
9+
.iOS(.v11),
10+
],
11+
products: [
12+
.library(name: "Cgit2", targets: ["Cgit2"]),
13+
],
714
targets: [
815
.target(
916
name: "Cgit2",
@@ -12,13 +19,20 @@ let package = Package(
1219
),
1320
.testTarget(name: "Cgit2Tests", dependencies: ["Cgit2"]),
1421

15-
.binaryTarget(name: "OpenSSL", path: ".build/OpenSSL.xcframework"),
16-
.binaryTarget(name: "libgit2", path: ".build/libgit2.xcframework"),
17-
.binaryTarget(name: "libssh2", path: ".build/libssh2.xcframework"),
18-
// .binaryTarget(
19-
// name: "libgit2",
20-
// url: "https://github.com/sharplet/swift-git/releases/v1.1.0/download/libgit2.xcframework.zip",
21-
// checksum: "ddf955d108d0773effb531457b196f1509573cb2610562c30f9f021cace9edd9"
22-
// ),
22+
.binaryTarget(
23+
name: "OpenSSL",
24+
url: "https://github.com/sharplet/swift-cgit2/releases/download/v1.1.0/OpenSSL.xcframework.zip",
25+
checksum: "cf95859d15d8f61a229023e70ed3ece532e47a143247de56931c329a029c7d35"
26+
),
27+
.binaryTarget(
28+
name: "libgit2",
29+
url: "https://github.com/sharplet/swift-cgit2/releases/download/v1.1.0/libgit2.xcframework.zip",
30+
checksum: "6252d651a74ef953b29d7144ed20cf91be2ebe7f148ea3c0eaba00ddca1cd8cd"
31+
),
32+
.binaryTarget(
33+
name: "libssh2",
34+
url: "https://github.com/sharplet/swift-cgit2/releases/download/v1.1.0/libssh2.xcframework.zip",
35+
checksum: "7b34a75674b622cc98c7a524a555817abdea455220070bdfb91b9234f4217c8e"
36+
),
2337
]
2438
)

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# swift-cgit2 - libgit2 for Apple platforms
2+
3+
swift-cgit2 is a binary distribution of [libgit2][] for Apple platforms.
4+
It's provided for the following platforms and architectures:
5+
6+
| Platform | Version | Architectures |
7+
| -------- | ---------- | ----------------- |
8+
| macOS | >= 10.13.0 | `x86_64`, `arm64` |
9+
| iOS | >= 11.0.0 | `arm64` |
10+
11+
swift-cgit2 is not intended to provide native Swift bindings to libgit2. For a
12+
Swift API, take a look at [SwiftGit2][].
13+
14+
[libgit2]: https://libgit2.org
15+
[SwiftGit2]: https://github.com/SwiftGit2/SwiftGit2
16+
17+
## Versioning
18+
19+
swift-cgit2 will follow the same versioning scheme as libgit2, starting at
20+
version 1.1.0. If patches are necessary, a new semantic version will be chosen
21+
that a) doesn't conflict with future libgit2 versions, and b) preserves
22+
semantic versioning for both libraries (if possible).
23+
24+
Examples of swift-cgit2 patches could include bugs that are found with the
25+
prebuilt `.xcframework` binaries & build scripts, or the introduction of new
26+
architectures for existing libgit2 versions.
27+
28+
## License
29+
30+
See [LICENSE](/LICENSE).

bin/upload renamed to bin/archive

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
print_usage() {
6-
echo >&2 "Usage: bin/upload <tag> <xcframework ...>"
6+
echo >&2 "Usage: bin/archive <file.xcframework ...>"
77
}
88

99
truncate() {
@@ -32,7 +32,6 @@ fi
3232

3333
declare -a archives
3434
manifest=upload-manifest.txt
35-
tag=$1; shift
3635

3736
truncate "$manifest"
3837

@@ -50,5 +49,3 @@ for xcframework; do
5049
done
5150

5251
echo "Upload manifest written to '$manifest'."
53-
54-
gh release upload "$tag" "${archives[@]}"

bin/build

Lines changed: 129 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,37 @@ set -e
55
issh2_dir="$PWD/iSSH2"
66
libgit2_dir="$PWD/libgit2"
77

8+
ios_min_version=11.0.0
9+
macos_min_version=10.13.0
10+
11+
build_macosx=true
12+
build_iphoneos=true
13+
build_iphonesimulator=true
14+
15+
declare -a cmake_configure_opts
16+
817
build_and_install() {
9-
if command -v xcpretty >/dev/null 2>&1; then
10-
cmake --build . --target install | xcpretty
11-
else
12-
cmake --build . --target install
13-
fi
18+
local platform=$1
19+
local build_dir=$2
20+
local build_log=$2/build.log
21+
echo -n "Building $platform..."
22+
trap 'echo " failed. ($build_log)"' ERR
23+
cmake --build "$build_dir" --target install >"$build_log"
24+
trap - ERR
25+
echo " done."
1426
}
1527

1628
cmake_configure() {
17-
cmake -G Xcode "$libgit2_dir" \
29+
local build_dir=$1; shift
30+
pushd &>/dev/null "$build_dir"
31+
cmake "${cmake_configure_opts[@]}" "$libgit2_dir" \
32+
-DBUILD_CLAR:BOOL=OFF \
33+
-DBUILD_SHARED_LIBS:BOOL=OFF \
34+
-DREGEX_BACKEND=builtin \
1835
-DCMAKE_C_FLAGS=-fembed-bitcode \
19-
-DCMAKE_INSTALL_PREFIX="Products/\$ENV{PROJECT_NAME}\$ENV{EFFECTIVE_PLATFORM_NAME}" \
20-
-DCMAKE_XCODE_ATTRIBUTE_BITCODE_ENABLED=YES \
36+
-DCMAKE_INSTALL_PREFIX="Products" \
2137
"$@"
38+
popd &>/dev/null
2239
}
2340

2441
cmake_prefix() {
@@ -58,19 +75,25 @@ xcode_arch_sysroots() {
5875

5976
build_openssl() {
6077
mkdir -p .build/OpenSSL
61-
pushd .build/OpenSSL
78+
pushd &>/dev/null .build/OpenSSL
6279

63-
issh2 --no-clean --platform=macosx --archs="arm64 x86_64" --min-version=10.11.0
64-
mkdir -p macosx/lib
65-
libtool -static -o macosx/lib/libOpenSSL.a "$issh2_dir"/openssl_macosx/lib/*.a
80+
if [[ $build_macosx == true ]]; then
81+
issh2 --no-clean --platform=macosx --archs="arm64 x86_64" --min-version="$macos_min_version"
82+
mkdir -p macosx/lib
83+
libtool -static -o macosx/lib/libOpenSSL.a "$issh2_dir"/openssl_macosx/lib/*.a
84+
fi
6685

67-
issh2 --no-clean --platform=iphoneos --archs=arm64 --min-version=9.0.0
68-
mkdir -p iphoneos/lib
69-
libtool -static -o iphoneos/lib/libOpenSSL.a "$issh2_dir"/openssl_iphoneos/lib/*.a
86+
if [[ $build_iphoneos == true ]]; then
87+
issh2 --no-clean --platform=iphoneos --archs=arm64 --min-version="$ios_min_version"
88+
mkdir -p iphoneos/lib
89+
libtool -static -o iphoneos/lib/libOpenSSL.a "$issh2_dir"/openssl_iphoneos/lib/*.a
90+
fi
7091

71-
issh2 --platform=iphonesimulator --archs="arm64 x86_64" --min-version=9.0.0
72-
mkdir -p iphonesimulator/lib
73-
libtool -static -o iphonesimulator/lib/libOpenSSL.a "$issh2_dir"/openssl_iphonesimulator/lib/*.a
92+
if [[ $build_iphonesimulator == true ]]; then
93+
issh2 --no-clean --platform=iphonesimulator --archs="arm64 x86_64" --min-version="$ios_min_version"
94+
mkdir -p iphonesimulator/lib
95+
libtool -static -o iphonesimulator/lib/libOpenSSL.a "$issh2_dir"/openssl_iphonesimulator/lib/*.a
96+
fi
7497

7598
rm -rf ../OpenSSL.xcframework
7699
xcodebuild -create-xcframework \
@@ -82,7 +105,7 @@ build_openssl() {
82105
-library iphonesimulator/lib/*.a \
83106
-headers "$issh2_dir"/openssl_iphonesimulator/include
84107

85-
popd
108+
popd &>/dev/null
86109

87110
rm -rf .build/libssh2.xcframework
88111
xcodebuild -create-xcframework \
@@ -97,91 +120,103 @@ build_openssl() {
97120

98121
# ============================================================================ #
99122

100-
build_libssh2() {
101-
mkdir -p .build/libssh2
102-
pushd .build/libssh2
103-
104-
issh2 --platform=macosx --archs="arm64 x86_64" --min-version=10.11.0
105-
mkdir -p macosx/lib
106-
libtool -static -o macosx/lib/libOpenSSL.a "$issh2_dir"/openssl_macosx/lib/*.a
107-
108-
issh2 --platform=iphoneos --archs=arm64 --min-version=9.0.0
109-
mkdir -p iphoneos/lib
110-
libtool -static -o iphoneos/lib/libOpenSSL.a "$issh2_dir"/openssl_iphoneos/lib/*.a
111-
112-
issh2 --platform=iphonesimulator --archs="arm64 x86_64" --min-version=9.0.0
113-
mkdir -p iphonesimulator/lib
114-
libtool -static -o iphonesimulator/lib/libOpenSSL.a "$issh2_dir"/openssl_iphonesimulator/lib/*.a
115-
116-
rm -rf ../OpenSSL.xcframework
117-
xcodebuild -create-xcframework \
118-
-output ../OpenSSL.xcframework \
119-
-library macosx/lib/*.a \
120-
-headers "$issh2_dir"/openssl_macosx/include \
121-
-library iphoneos/lib/*.a \
122-
-headers "$issh2_dir"/openssl_iphoneos/include \
123-
-library iphonesimulator/lib/*.a \
124-
-headers "$issh2_dir"/openssl_iphonesimulator/include
125-
126-
popd
127-
}
128-
129-
# ============================================================================ #
130-
131123
build_libgit2() {
132-
mkdir -p .build/libgit2
133-
pushd .build/libgit2
134-
135-
# macosx
136-
137-
cmake_configure \
138-
-DCMAKE_PREFIX_PATH="$(cmake_prefix macosx)" \
139-
-DBUILD_SHARED_LIBS:BOOL=OFF \
140-
-DBUILD_CLAR:BOOL=OFF \
141-
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
142-
-DCMAKE_APPLE_ARCH_SYSROOTS="$(xcode_arch_sysroots macosx arm64 x86_64)" \
143-
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13.0 \
144-
-DCMAKE_OSX_SYSROOT=macosx
145-
146-
build_and_install
147-
148-
# iphoneos
149-
150-
cmake_configure \
151-
-DCMAKE_PREFIX_PATH="$(cmake_prefix iphoneos)" \
152-
-DBUILD_SHARED_LIBS:BOOL=OFF \
153-
-DBUILD_CLAR:BOOL=OFF \
154-
-DREGEX_BACKEND=builtin \
155-
-DCMAKE_OSX_ARCHITECTURES=arm64 \
156-
-DCMAKE_APPLE_ARCH_SYSROOTS="$(xcode_arch_sysroots iphoneos arm64)" \
157-
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
158-
-DCMAKE_OSX_SYSROOT=iphoneos
159-
160-
build_and_install
161-
162-
# iphonesimulator
124+
if [[ $build_macosx == true ]]; then
125+
build_dir=.build/libgit2/macosx
126+
configure_log=$build_dir/configure.log
127+
mkdir -p "$build_dir"
128+
129+
echo -n "Configuring macosx..."
130+
trap ' failed. ($configure_log)' ERR
131+
cmake_configure "$build_dir" \
132+
-DCMAKE_PREFIX_PATH="$(cmake_prefix macosx)" \
133+
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
134+
-DCMAKE_OSX_DEPLOYMENT_TARGET="$macos_min_version" \
135+
-DCMAKE_OSX_SYSROOT=macosx \
136+
>"$configure_log"
137+
trap - ERR
138+
echo " done."
139+
140+
build_and_install macosx "$build_dir"
141+
fi
163142

164-
cmake_configure \
165-
-DCMAKE_PREFIX_PATH:PATH="$(cmake_prefix iphonesimulator)" \
166-
-DBUILD_SHARED_LIBS:BOOL=OFF \
167-
-DBUILD_CLAR:BOOL=OFF \
168-
-DREGEX_BACKEND=builtin \
169-
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
170-
-DCMAKE_APPLE_ARCH_SYSROOTS="$(xcode_arch_sysroots iphonesimulator arm64 x86_64)" \
171-
-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 \
172-
-DCMAKE_OSX_SYSROOT=iphonesimulator
143+
if [[ $build_iphoneos == true ]]; then
144+
build_dir=.build/libgit2/iphoneos
145+
configure_log=$build_dir/configure.log
146+
mkdir -p "$build_dir"
147+
148+
echo -n "Configuring iphoneos..."
149+
trap ' failed. ($configure_log)' ERR
150+
cmake_configure "$build_dir" \
151+
-DCMAKE_PREFIX_PATH="$(cmake_prefix iphoneos)" \
152+
-DCMAKE_C_COMPILER_WORKS:BOOL=ON \
153+
-DCMAKE_OSX_ARCHITECTURES=arm64 \
154+
-DCMAKE_OSX_DEPLOYMENT_TARGET="$ios_min_version" \
155+
-DCMAKE_OSX_SYSROOT=iphoneos \
156+
>"$configure_log"
157+
trap - ERR
158+
echo " done."
159+
160+
build_and_install iphoneos "$build_dir"
161+
fi
173162

174-
build_and_install
163+
if [[ $build_iphonesimulator == true ]]; then
164+
build_dir=.build/libgit2/iphonesimulator
165+
configure_log=$build_dir/configure.log
166+
mkdir -p "$build_dir"
167+
168+
echo -n "Configuring iphonesimulator..."
169+
trap ' failed. ($configure_log)' ERR
170+
cmake_configure "$build_dir" \
171+
-DCMAKE_PREFIX_PATH:PATH="$(cmake_prefix iphonesimulator)" \
172+
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
173+
-DCMAKE_OSX_DEPLOYMENT_TARGET="$ios_min_version" \
174+
-DCMAKE_OSX_SYSROOT=iphonesimulator \
175+
>"$configure_log"
176+
trap - ERR
177+
echo " done."
178+
179+
build_and_install iphonesimulator "$build_dir"
180+
fi
175181

176182
# build xcframework
177183

178-
create_xcframework ../libgit2.xcframework Products/*
179-
180-
popd
184+
create_xcframework .build/libgit2.xcframework .build/libgit2/*/Products
181185
}
182186

183187
# ============================================================================ #
184188

189+
for opt; do
190+
case $opt in
191+
--macosx)
192+
build_macosx=true
193+
build_iphoneos=false
194+
build_iphonesimulator=false
195+
;;
196+
--iphoneos)
197+
build_macosx=false
198+
build_iphoneos=true
199+
build_iphonesimulator=false
200+
;;
201+
--iphonesimulator)
202+
build_macosx=false
203+
build_iphoneos=false
204+
build_iphonesimulator=true
205+
;;
206+
*)
207+
echo >&2 "Unknown option '$opt'"
208+
exit 1
209+
;;
210+
esac
211+
done
212+
185213
mkdir -p .build
214+
186215
build_openssl
216+
217+
if ninja_path="$(command -v ninja)"; then
218+
echo "Configuring CMake to use Ninja (found at path $ninja_path)"
219+
cmake_configure_opts+=(-G Ninja)
220+
fi
221+
187222
build_libgit2

iSSH2

0 commit comments

Comments
 (0)