-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·262 lines (223 loc) · 9.73 KB
/
build.sh
File metadata and controls
executable file
·262 lines (223 loc) · 9.73 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
export MACOSX_DEPLOYMENT_TARGET="10.6"
# Download arm compiler for compiling on daisy
if [[ "$OSTYPE" == "darwin"* ]]; then
URL="https://github.com/plugdata-team/plugdata-heavy-toolchain/releases/download/arm_gcc/gcc-arm-none-eabi-10-2020-q4-major-mac.tar.bz2"
# Aarch64 Linux
elif [[ $(uname -m) == "aarch64" ]]; then
URL="https://github.com/plugdata-team/plugdata-heavy-toolchain/releases/download/arm_gcc/gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2"
# x86_64 Linux
else
URL="https://github.com/plugdata-team/plugdata-heavy-toolchain/releases/download/arm_gcc/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2"
fi
curl -fSL -A "Mozilla/4.0" -o gcc-arm-none-eabi.tar.bz2 $URL
status=$?
if [ $status -ne 0 ]; then
echo "Failed to download gcc-arm-none-eabi"
exit $status
fi
echo "Extracting..."
mkdir gcc-arm-none-eabi
pushd gcc-arm-none-eabi
tar -xjf ../gcc-arm-none-eabi.tar.bz2
popd
rm gcc-arm-none-eabi.tar.bz2
mkdir Heavy
cp -rf gcc-arm-none-eabi/gcc-arm-*/bin ./Heavy
cp -rf gcc-arm-none-eabi/gcc-arm-*/lib ./Heavy
# cp -rf gcc-arm-none-eabi/gcc-arm-*/libexec ./Heavy
cp -rf gcc-arm-none-eabi/gcc-arm-*/share ./Heavy
# cp -rf gcc-arm-none-eabi/gcc-arm-*/include ./Heavy
cp -rf gcc-arm-none-eabi/gcc-arm-*/arm-none-eabi ./Heavy
# some cleanup
rm -rf ./Heavy/share/doc*
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
curl -fSL -A "Mozilla/4.0" -o x86_64-anywhere-linux-gnu-v5.tar.xz https://github.com/theopolis/build-anywhere/releases/download/v5/x86_64-anywhere-linux-gnu-v5.tar.xz
status=$?
if [ $status -ne 0 ]; then
echo "Failed to download x86_64-anywhere-linux-gnu-v5.tar.xz"
exit $status
fi
mkdir build-anywhere
pushd build-anywhere
tar -xf ../x86_64-anywhere-linux-gnu-v5.tar.xz
pushd x86_64-anywhere-linux-gnu
# Fix: use gcc instead of clang, for compactness
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/include/llvm*
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/include/clang*
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/share/clang
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/lib/libclang
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/lib/cmake/llvm
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/lib/cmake/clang
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/lib/clang
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/bin/llvm-cov
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/bin/llvm-*
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/bin/clang-*
rm ./x86_64-anywhere-linux-gnu/sysroot/usr/lib/libclang.so.8
rm ./x86_64-anywhere-linux-gnu/sysroot/usr/lib/libLLVM-8.so
rm ./x86_64-anywhere-linux-gnu/sysroot/usr/bin/git-clang-format
rm ./x86_64-anywhere-linux-gnu/sysroot/usr/bin/c-index-test
rm ./x86_64-anywhere-linux-gnu/sysroot/usr/bin/diagtool
rm ./x86_64-anywhere-linux-gnu/sysroot/usr/bin/wasm-ld
# more cleanup
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/src*
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/sbin*
rm -rf ./x86_64-anywhere-linux-gnu/sysroot/usr/share/doc*
# copy scripts
cp ../../resources/anywhere-setup.sh ./scripts/anywhere-setup.sh
cp ../../resources/install_udev_rule.sh ./scripts/install_udev_rule.sh
cp ../../resources/askpass.sh ./scripts/askpass.sh
popd
popd
rsync -a ./build-anywhere/x86_64-anywhere-linux-gnu/ ./Heavy/
fi
# Reduce package size by only including the daisy platform tools
mkdir -p "./Heavy/arm-none-eabi/lib/temp/"
# for Daisy
mv -f "./Heavy/arm-none-eabi/lib/thumb/v7e-m+dp" "./Heavy/arm-none-eabi/lib/temp"
# for OWL
mv -f "./Heavy/arm-none-eabi/lib/thumb/v7e-m+fp" "./Heavy/arm-none-eabi/lib/temp"
rm -rf "./Heavy/arm-none-eabi/lib/thumb"
mv -f "./Heavy/arm-none-eabi/lib/temp" "./Heavy/arm-none-eabi/lib/thumb"
mkdir -p "./Heavy/lib/gcc/arm-none-eabi/10.2.1/temp"
mv "./Heavy/lib/gcc/arm-none-eabi/10.2.1/thumb/v7e-m+dp" "./Heavy/lib/gcc/arm-none-eabi/10.2.1/temp/v7e-m+dp"
mv "./Heavy/lib/gcc/arm-none-eabi/10.2.1/thumb/v7e-m+fp" "./Heavy/lib/gcc/arm-none-eabi/10.2.1/temp/v7e-m+fp"
rm -rf "./Heavy/lib/gcc/arm-none-eabi/10.2.1/thumb"
mv "./Heavy/lib/gcc/arm-none-eabi/10.2.1/temp" "./Heavy/lib/gcc/arm-none-eabi/10.2.1/thumb"
rm -rf "./Heavy/arm-none-eabi/lib/arm"
mkdir -p ./Heavy/etc/linkers
# copy resource files
cp -rf ./resources/*.lds ./Heavy/etc/linkers
cp ./resources/simple.json ./Heavy/etc/simple.json
cp ./resources/terrarium.json ./Heavy/etc/terrarium.json
cp ./resources/versio.json ./Heavy/etc/versio.json
cp ./resources/hothouse.json ./Heavy/etc/hothouse.json
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Get libasound
TEMP_DEB2="$(mktemp)"
wget -O "$TEMP_DEB2" 'http://ftp.de.debian.org/debian/pool/main/a/alsa-lib/libasound2_1.2.4-1.1_amd64.deb'
status=$?
if [ $status -ne 0 ]; then
echo "Failed to download libasound2"
exit $status
fi
ar x "$TEMP_DEB2"
tar xvf data.tar.xz
cp ./usr/lib/x86_64-linux-gnu/libasound.so.2.0.0 ./Heavy/x86_64-anywhere-linux-gnu/sysroot/lib/libasound.so
fi
# copy dfu-util
cp $(which dfu-util) ./Heavy/bin/dfu-util
cp $(which dfu-prefix) ./Heavy/bin/dfu-prefix
cp $(which dfu-suffix) ./Heavy/bin/dfu-suffix
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
cp "$(ldconfig -p | grep libusb-1.0.so | tr ' ' '\n' | grep /)" ./Heavy/lib/libusb-1.0.so
# Make sure it can find libusb
patchelf --replace-needed "libusb-1.0.so.0" "\$ORIGIN/../lib/libusb-1.0.so" "./Heavy/bin/dfu-util"
patchelf --replace-needed "libusb-1.0.so" "\$ORIGIN/../lib/libusb-1.0.so" "./Heavy/bin/dfu-util"
elif [[ "$OSTYPE" == "darwin"* ]]; then
HOMEBREW_PREFIX="/usr/local"
cp $HOMEBREW_PREFIX/opt/libusb/lib/libusb-1.0.0.dylib ./Heavy/lib/libusb-1.0.0.dylib
# Make sure it can find libusb
install_name_tool -change "$HOMEBREW_PREFIX/opt/libusb/lib/libusb-1.0.0.dylib" "@executable_path/../lib/libusb-1.0.0.dylib" "./Heavy/bin/dfu-util"
fi
# build a version of GNU make that has no dependencies
curl -fSL -A "Mozilla/4.0" -o make-4.4.tar.gz https://ftpmirror.gnu.org/make/make-4.4.tar.gz
status=$?
if [ $status -ne 0 ]; then
echo "Failed to download make-4.4"
exit $status
fi
tar -xf make-4.4.tar.gz
pushd make-4.4
chmod +x ./build.sh
chmod +x ./configure
# Hack: make sure libintl is not found on macOS when building on Github actions server!
if [[ "$CLEAR_INTL" == "1" ]]; then
rm -f /usr/local/opt/gettext/lib/libintl*.dylib
fi
./configure --disable-dependency-tracking --with-guile=no --without-libintl-prefix
./build.sh
cp make ../Heavy/bin/make
popd
rm -rf make-4.4 make-4.4.tar.gz
# Pre-build libdaisy
pushd libdaisy
make GCC_PATH=../Heavy/bin/
# Cleanup
rm -rf doc
rm -rf tests
rm -rf Drivers/CMSIS_5/CMSIS_Review_Meeting_2020.pdf
rm -rf Drivers/CMSIS_5/CMSIS/DSP
rm -rf Drivers/CMSIS_5/CMSIS/DoxyGen
rm -rf Drivers/CMSIS_5/CMSIS/NN
rm -rf Drivers/CMSIS_5/CMSIS/RTOS2
rm -rf Drivers/CMSIS_5/CMSIS/RTOS
rm -rf Drivers/CMSIS-DSP
popd
# Pre-build OWL libs (only OWL2 target for now)
pushd OwlProgram
../Heavy/bin/make libs PLATFORM=OWL2 TOOLROOT=../Heavy/bin/
popd
# Download OWL FirmwareSender from CI
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
FS_URL="https://github.com/Wasted-Audio/FirmwareSender_plugdata/releases/download/plugdata/FirmwareSender-ubuntu.zip"
curl -fSL -A "Mozilla/4.0" -o FirmwareSender-ubuntu.zip $FS_URL
status=$?
if [ $status -ne 0 ]; then
echo "Failed to download FirmwareSender-ubuntu"
exit $status
fi
unzip FirmwareSender-ubuntu.zip -d FirmwareSender-ubuntu
cp ./FirmwareSender-ubuntu/FirmwareSender OwlProgram/Tools/
elif [[ "$OSTYPE" == "darwin"* ]]; then
FS_URL="https://github.com/Wasted-Audio/FirmwareSender_plugdata/releases/download/plugdata/FirmwareSender-osx.zip"
curl -fSL -A "Mozilla/4.0" -o FirmwareSender-osx.zip $FS_URL
status=$?
if [ $status -ne 0 ]; then
echo "Failed to download FirmwareSender-osx"
exit $status
fi
unzip FirmwareSender-osx.zip -d FirmwareSender-osx
cp ./FirmwareSender-osx/FirmwareSender OwlProgram/Tools/
fi
# Copy all libs to toolchain
cp -rf ./libdaisy ./Heavy/lib/libdaisy
cp -rf ./OwlProgram ./Heavy/lib/OwlProgram
cp -rf ./dpf ./Heavy/lib/dpf
cp -rf ./dpf-widgets ./Heavy/lib/dpf-widgets
# Package Heavy with pyinstaller
python3 -m ensurepip
python3 -m pip install poetry poetry-pyinstaller-plugin pyinstaller
pushd hvcc
pip install -e .
poetry build
popd
mkdir -p Heavy/bin/Heavy
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
mv ./hvcc/dist/pyinstaller/manylinux_2_35_x86_64/Heavy Heavy/bin/Heavy/
elif [[ "$OSTYPE" == "darwin"* ]]; then
mv ./hvcc/dist/pyinstaller/macosx_15_0_x86_64/Heavy Heavy/bin/Heavy/
cat > entitlements.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
EOF
find ./Heavy -type f -perm +111 -exec file {} \; | grep "Mach-O.*executable" | cut -d: -f1 | while read f; do
/usr/bin/codesign --force --options runtime --entitlements entitlements.plist -s "Developer ID Application: Timothy Schoen (7SV7JPRR2L)" "$f"
done
find ./Heavy -type f \( -name "*.dylib" -o -name "*.so" \) -exec /usr/bin/codesign --force --options runtime --entitlements entitlements.plist -s "Developer ID Application: Timothy Schoen (7SV7JPRR2L)" {} \;
# Submit the zipped executable for notarization
# This makes sure we can at least run it with online notarization
ditto -c -k --keepParent ./Heavy Heavy.zip
xcrun notarytool store-credentials "notary_login" --apple-id ${AC_USERNAME} --password ${AC_PASSWORD} --team-id "7SV7JPRR2L"
xcrun notarytool submit Heavy.zip --keychain-profile "notary_login" --wait
rm Heavy.zip
rm entitlements.plist
fi
cp VERSION ./Heavy/VERSION
mv ./Heavy ./Toolchain