-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·176 lines (137 loc) · 3.67 KB
/
build.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
# shellcheck source=patcher.sh
WORKDIR=$(pwd)
ARCH="${ARCH:-x86_64}"
LIBC="${LIBC:-musl}"
TARGET="$ARCH-unknown-linux-$LIBC"
# ---
dep () {
if ! which "$1" 2>/dev/null
then
echo "$1 not found"
exit 1
fi
}
clone () {
git clone --single-branch --depth 1 "$1" "$2" || exit 2
}
cd_and_exec () {
old=$(pwd)
cd "$1" || exit 3
shift
"$@" || exit 4
cd "$old" || exit 3
}
update_repo () {
if [ -e "$1" ]
then
echo "$1 exists, updating"
old=$(pwd)
cd "$1" || exit 3
git stash && git stash drop
git pull || exit 2
cd "$old" || exit 3
else
echo "$1 not found, cloning"
clone "$2" "$1"
fi
}
try_exec () {
"$@"
return 0
}
set_piped_version () {
# From GitHub Actions
commit_date=$(git log -1 --date=short --pretty=format:%cd)
commit_sha=$(git rev-parse --short HEAD)
echo "$commit_date-$commit_sha" >VERSION
}
title () {
# Newline, Bold text, $1, Normal text, Newline
printf '\n\033[1m%s\033[0m\n' "$1"
}
# ---
title 'Checking dependencies...'
dep git
dep java
dep cargo
dep 7z
title 'Updating repositories...'
update_repo backend https://github.com/TeamPiped/Piped-Backend
update_repo reqwest4j https://github.com/TeamPiped/reqwest4j
title 'Applying patches...'
source patcher.sh
cd_and_exec backend patch_backend
cd_and_exec reqwest4j patch_reqwest4j
# ---
[ "$LIBC" = "musl" ] && export RUSTFLAGS="-C target-feature=-crt-static"
title 'Building reqwest-jni'
cd_and_exec reqwest4j/reqwest-jni \
cargo build --release --target "$TARGET"
title 'Building reqwest4j without Rust library...'
OLD_PATH="$PATH"
export JAVA_HOME="/usr/lib/jvm/java-21-openjdk"
export PATH="$JAVA_HOME/bin:$PATH"
cd_and_exec reqwest4j ./gradlew shadowJar
cd_and_exec reqwest4j ./gradlew --stop
export PATH="$OLD_PATH"
unset JAVA_HOME
# ---
title 'Adding built libreqwest_jni into reqwest4j JAR...'
title '--Copying files'
# Copy JAR into workdir
REQ4J_NAME="reqwest4j.jar"
REQ4J="$WORKDIR/$REQ4J_NAME"
cd_and_exec reqwest4j/build/libs \
find . -maxdepth 1 -name 'reqwest4j-*-all.jar' -exec \
cp {} "$REQ4J" \;
# Copy built reqwest-jni into workdir
REQJNI_NAME="libreqwest.so"
REQJNI="$WORKDIR/$REQJNI_NAME"
cd_and_exec "reqwest4j/reqwest-jni/target/$TARGET/release" \
cp libreqwest_jni.so "$REQJNI"
# Create JAR native libraries tree
title '--Creating libraries directory tree'
NATIVES="META-INF/natives/linux/$ARCH"
mkdir -p "$NATIVES"
# Move reqwest-jni to native libraries directory
title '--Moving libreqwest'
mv "$REQJNI" "$NATIVES/$REQJNI_NAME"
# Add native libraries into JAR
title '--Injecting libraries directory into reqwest4j JAR'
7z u "$REQ4J" META-INF
# Clean up
title '--Cleaning up'
rm -rf META-INF
rm -f "$REQJNI"
# ---
title 'Adding reqwest4j JAR into Piped sources...'
cd_and_exec backend mkdir -p libs
cd_and_exec backend/libs mv "$REQ4J" ./
title 'Creating VERSION file...'
cd_and_exec backend set_piped_version
title 'Building Piped...'
OLD_PATH="$PATH"
export JAVA_HOME="/usr/lib/jvm/java-21-openjdk"
export PATH="$JAVA_HOME/bin:$PATH"
cd_and_exec backend ./gradlew shadowJar
cd_and_exec backend ./gradlew --stop
export PATH="$OLD_PATH"
unset JAVA_HOME
# ---
title 'Copying Piped JAR...'
cd_and_exec backend/build/libs \
find . -maxdepth 1 -name 'piped-*-all.jar' -exec \
cp {} "$WORKDIR/piped.jar" \;
title 'Copying config and version...'
cd_and_exec backend cp config.properties VERSION "$WORKDIR"
# ---
echo
echo '*** ************** ***'
echo '*** DONE ***'
echo '*** ************** ***'
title 'You need these files:'
for f in "piped.jar" "config.properties" "VERSION"
do
echo " $(readlink -f "$f")"
done