Skip to content

Commit d2cc787

Browse files
committed
Clean up and reorganize build functions
1 parent 4a4e07e commit d2cc787

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ jobs:
3939

4040
- script: swift package compute-checksum Clibgit2.xcframework.zip
4141
displayName: 'Compute Clibgit2 XCFramework Checksum'
42-
enabled: false
42+
enabled: true
4343

4444
- publish: $(System.DefaultWorkingDirectory)/Clibgit2.xcframework.zip
4545
artifact: Clibgit2
4646
displayName: 'Publish Clibgit2 XCFramework'
47-
enabled: false
47+
enabled: true
4848

4949
- publish: $(System.DefaultWorkingDirectory)/install
5050
artifact: install

build-libgit2-framework.sh

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -80,40 +80,6 @@ function setup_variables() {
8080
esac
8181
}
8282

83-
### Build libgit2 for a single platform (given as the first and only argument)
84-
### See @setup_variables for the list of available platform names
85-
### Assume openssl and libssh2 was built
86-
function build_libgit2() {
87-
setup_variables $1
88-
89-
# test -d libgit2 || git clone --recursive https://github.com/libgit2/libgit2.git
90-
# cd libgit2
91-
# git submodule update --recursive
92-
93-
rm -rf libgit2-1.3.0
94-
test -f v1.3.0.zip || wget -q https://github.com/libgit2/libgit2/archive/refs/tags/v1.3.0.zip
95-
unzip v1.3.0.zip >/dev/null #tar xzf libgit2-1.3.0.tar.gz
96-
cd libgit2-1.3.0
97-
98-
rm -rf build && mkdir build && cd build
99-
100-
CMAKE_ARGS+=(-DBUILD_CLAR=NO)
101-
102-
# See libgit2/cmake/FindPkgLibraries.cmake to understand how libgit2 looks for libssh2
103-
# Basically, setting LIBSSH2_FOUND forces SSH support and since we are building static library,
104-
# we only need the headers.
105-
CMAKE_ARGS+=(-DOPENSSL_ROOT_DIR=$REPO_ROOT/install/$PLATFORM \
106-
-DUSE_SSH=ON \
107-
-DLIBSSH2_FOUND=YES \
108-
-DLIBSSH2_INCLUDE_DIRS=$REPO_ROOT/install/$PLATFORM/include)
109-
110-
# Must add "" around ${CMAKE_ARGS[@]} since the array element can have space!
111-
# See https://stackoverflow.com/questions/9084257/bash-array-with-spaces-in-elements
112-
cmake "${CMAKE_ARGS[@]}" .. >/dev/null 2>/dev/null
113-
114-
cmake --build . --target install >/dev/null 2>/dev/null
115-
}
116-
11783
### Build libpcre for a given platform
11884
function build_libpcre() {
11985
setup_variables $1
@@ -178,7 +144,7 @@ function build_libssh2() {
178144
setup_variables $1
179145

180146
rm -rf libssh2-1.10.0
181-
test -f libssh2-1.10.0.tar.gz || wget -q https://github.com/libssh2/libssh2/releases/download/libssh2-1.10.0/libssh2-1.10.0.tar.gz
147+
test -f libssh2-1.10.0.tar.gz || wget -q https://www.libssh2.org/download/libssh2-1.10.0.tar.gz
182148
tar xzf libssh2-1.10.0.tar.gz
183149
cd libssh2-1.10.0
184150

@@ -194,14 +160,32 @@ function build_libssh2() {
194160
cmake --build . --target install >/dev/null 2>/dev/null
195161
}
196162

197-
### Copy SwiftGit2's module.modulemap to libgit2.xcframework/*/Headers
198-
### so that we can use libgit2.xcframework with SwiftGit2
199-
function copy_modulemap() {
200-
local FWDIRS=$(find Clibgit2.xcframework -mindepth 1 -maxdepth 1 -type d)
201-
for d in ${FWDIRS[@]}; do
202-
echo $d
203-
cp Clibgit2_modulemap $d/Headers/module.modulemap
204-
done
163+
### Build libgit2 for a single platform (given as the first and only argument)
164+
### See @setup_variables for the list of available platform names
165+
### Assume openssl and libssh2 was built
166+
function build_libgit2() {
167+
setup_variables $1
168+
169+
rm -rf libgit2-1.3.0
170+
test -f v1.3.0.zip || wget -q https://github.com/libgit2/libgit2/archive/refs/tags/v1.3.0.zip
171+
unzip v1.3.0.zip >/dev/null
172+
cd libgit2-1.3.0
173+
174+
rm -rf build && mkdir build && cd build
175+
176+
CMAKE_ARGS+=(-DBUILD_CLAR=NO)
177+
178+
# See libgit2/cmake/FindPkgLibraries.cmake to understand how libgit2 looks for libssh2
179+
# Basically, setting LIBSSH2_FOUND forces SSH support and since we are building static library,
180+
# we only need the headers.
181+
CMAKE_ARGS+=(-DOPENSSL_ROOT_DIR=$REPO_ROOT/install/$PLATFORM \
182+
-DUSE_SSH=ON \
183+
-DLIBSSH2_FOUND=YES \
184+
-DLIBSSH2_INCLUDE_DIRS=$REPO_ROOT/install/$PLATFORM/include)
185+
186+
cmake "${CMAKE_ARGS[@]}" .. >/dev/null 2>/dev/null
187+
188+
cmake --build . --target install >/dev/null 2>/dev/null
205189
}
206190

207191
### Create xcframework for a given library
@@ -221,23 +205,30 @@ function build_xcframework() {
221205
xcodebuild -create-xcframework ${FRAMEWORKS_ARGS[@]} -output $FWNAME.xcframework
222206
}
223207

224-
### Build all frameworks for every available platforms
208+
### Copy SwiftGit2's module.modulemap to libgit2.xcframework/*/Headers
209+
### so that we can use libgit2 C API in Swift (e.g. via SwiftGit2)
210+
function copy_modulemap() {
211+
local FWDIRS=$(find Clibgit2.xcframework -mindepth 1 -maxdepth 1 -type d)
212+
for d in ${FWDIRS[@]}; do
213+
echo $d
214+
cp Clibgit2_modulemap $d/Headers/module.modulemap
215+
done
216+
}
217+
218+
### Build libgit2 and Clibgit2 frameworks for all available platforms
225219

226220
for p in ${AVAILABLE_PLATFORMS[@]}; do
221+
echo "Build libraries for $p"
227222
build_libpcre $p
228223
build_openssl $p
229224
build_libssh2 $p
230225
build_libgit2 $p
231226

232-
# Merge all static libs as libgit2.a
227+
# Merge all static libs as libgit2.a since xcodebuild doesn't allow specifying multiple .a
233228
cd $REPO_ROOT/install/$p
234229
libtool -static -o libgit2.a lib/*.a
235230
done
236231

237-
#for fw in ${AVAILABLE_FRAMEWORKS[@]}; do
238-
# build_xcframework $fw ${AVAILABLE_PLATFORMS[@]}
239-
#done
240-
241232
# Build raw libgit2 XCFramework for Objective-C usage
242233
build_xcframework libgit2 ${AVAILABLE_PLATFORMS[@]}
243234
zip -r libgit2.xcframework.zip libgit2.xcframework/

0 commit comments

Comments
 (0)