-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_ctrld_ios.sh
executable file
·93 lines (80 loc) · 2.18 KB
/
build_ctrld_ios.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# This script is used to locally build OS .xcframework from ctrld source using the go mobile tool.
# Requirements:
# - Xcode 15 + Build tools
# - Go 1.21
# - Git
# usage: $ ./build_lib.sh v1.3.4
TAG="$1"
if [ -z "$TAG" ]; then
echo "Usage: $0 <version-tag>"
exit 1
fi
# Hacky way to replace version info.
update_versionInfo() {
local file="$1/ctrld/cmd/cli/cli.go"
local tag="$2"
local commit="$3"
awk -v tag="$tag" -v commit="$commit" '
BEGIN { version_updated = 0; commit_updated = 0 }
/^\tversion/ {
sub(/= ".+"/, "= \"" tag "\"");
version_updated = 1;
}
/^\tcommit/ {
sub(/= ".+"/, "= \"" commit "\"");
commit_updated = 1;
}
{ print }
END {
if (version_updated == 0) {
print "\tversion = \"" tag "\"";
}
if (commit_updated == 0) {
print "\tcommit = \"" commit "\"";
}
}
' "$file" > "$file.tmp" && mv "$file.tmp" "$file"
}
# Set the PATH for Go binaries
export PATH="$PATH:$HOME/go/bin"
# Clean up previous builds
if [ -d "bin" ]; then
rm -rf bin
fi
mkdir -p bin
cd bin || exit
root=$(pwd)
# Clean up previous ctrld repo if it exists
if [ -d "ctrld" ]; then
rm -rf ctrld
fi
# Clone the repository and checkout the specified tag
git clone --depth 1 --branch "$TAG" --single-branch https://github.com/Control-D-Inc/ctrld.git
# Check if the clone was successful
if [ $? -ne 0 ]; then
echo "Error: Failed to clone the repository."
exit 1
fi
# Prepare gomobile tool
sourcePath="./ctrld/cmd/ctrld_library"
cd "$sourcePath" || exit
# Install gomobile tool
go install golang.org/x/mobile/cmd/gomobile@latest
go get golang.org/x/mobile/bind
gomobile init
# Prepare build info
buildDir="$root/../Build"
mkdir -p "$buildDir"
COMMIT=$(git rev-parse HEAD)
update_versionInfo "$root" "$TAG" "$COMMIT"
ldflags="-s -w"
# Build
gomobile bind -ldflags="$ldflags" -target=ios -o "$buildDir/Ctrld.xcframework"
if [ $? -ne 0 ]; then
echo "Error: Failed to build the Ctrld library."
exit 1
fi
# Clean up
rm -rf "$root"
echo "Successfully built Ctrld library $TAG ($COMMIT)."