forked from EPNW/opus_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_opus.sh
More file actions
executable file
·221 lines (179 loc) · 6.7 KB
/
Copy pathbuild_opus.sh
File metadata and controls
executable file
·221 lines (179 loc) · 6.7 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
#!/bin/bash
#
# Builds pre-compiled opus libraries for all platforms that need them.
#
# Platforms:
# web – WASM + JS glue via Docker (Emscripten)
# windows – DLLs (x86, x64) via Docker (MinGW cross-compile)
# linux – Shared libraries (x86_64, aarch64) via Docker
# ios – XCFramework via native Xcode toolchain
# macos – XCFramework via native Xcode toolchain
#
# Android builds from source at Gradle time (CMake FetchContent).
#
# Usage:
# ./build_opus.sh # build all platforms
# ./build_opus.sh web # build web only
# ./build_opus.sh web windows # build web and windows
# ./build_opus.sh ios macos # build ios and macos
#
# Requirements:
# web/windows/linux : Docker
# ios/macos : Xcode CLI tools, CMake, Git
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OPUS_VERSION="v1.5.2"
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
log() { echo -e "${CYAN}[opus]${RESET} $*"; }
ok() { echo -e "${GREEN}[opus]${RESET} $*"; }
err() { echo -e "${RED}[opus]${RESET} $*" >&2; }
require_docker() {
command -v docker >/dev/null 2>&1 || {
err "Docker is required for $1 builds but was not found in PATH."
exit 1
}
}
# --------------------------------------------------------------------------- #
# Web
# --------------------------------------------------------------------------- #
build_web() {
log "Building opus for ${BOLD}web${RESET} (WASM + JS via Emscripten)..."
require_docker "web"
local plugin_dir="$SCRIPT_DIR/opus_flutter_web"
local assets_dir="$plugin_dir/assets"
local image_tag="opus-flutter-web-builder"
docker build -t "$image_tag" -f "$plugin_dir/Dockerfile" "$plugin_dir"
local container_id
container_id=$(docker create "$image_tag")
mkdir -p "$assets_dir"
docker cp "$container_id:/build/out/libopus.js" "$assets_dir/libopus.js"
docker cp "$container_id:/build/out/libopus.wasm" "$assets_dir/libopus.wasm"
docker rm "$container_id" > /dev/null
local js_size wasm_size
js_size=$(wc -c < "$assets_dir/libopus.js" | tr -d ' ')
wasm_size=$(wc -c < "$assets_dir/libopus.wasm" | tr -d ' ')
ok "Web build complete:"
ok " $assets_dir/libopus.js ($js_size bytes)"
ok " $assets_dir/libopus.wasm ($wasm_size bytes)"
}
# --------------------------------------------------------------------------- #
# Windows
# --------------------------------------------------------------------------- #
build_windows() {
log "Building opus for ${BOLD}windows${RESET} (x86 + x64 DLLs via MinGW)..."
require_docker "windows"
local plugin_dir="$SCRIPT_DIR/opus_flutter_windows"
local assets_dir="$plugin_dir/assets"
local image_tag="opus-flutter-windows-builder"
docker build -t "$image_tag" -f "$plugin_dir/Dockerfile" "$plugin_dir"
local container_id
container_id=$(docker create "$image_tag")
mkdir -p "$assets_dir"
docker cp "$container_id:/app/libopus_x64.dll.blob" "$assets_dir/libopus_x64.dll.blob"
docker cp "$container_id:/app/libopus_x86.dll.blob" "$assets_dir/libopus_x86.dll.blob"
docker rm "$container_id" > /dev/null
local x64_size x86_size
x64_size=$(wc -c < "$assets_dir/libopus_x64.dll.blob" | tr -d ' ')
x86_size=$(wc -c < "$assets_dir/libopus_x86.dll.blob" | tr -d ' ')
ok "Windows build complete:"
ok " $assets_dir/libopus_x64.dll.blob ($x64_size bytes)"
ok " $assets_dir/libopus_x86.dll.blob ($x86_size bytes)"
}
# --------------------------------------------------------------------------- #
# Linux
# --------------------------------------------------------------------------- #
build_linux() {
log "Building opus for ${BOLD}linux${RESET} (x86_64 + aarch64 shared libraries)..."
require_docker "linux"
local plugin_dir="$SCRIPT_DIR/opus_flutter_linux"
local assets_dir="$plugin_dir/assets"
local image_tag="opus-flutter-linux-builder"
docker build -t "$image_tag" -f "$plugin_dir/Dockerfile" "$plugin_dir"
local container_id
container_id=$(docker create "$image_tag")
mkdir -p "$assets_dir"
docker cp "$container_id:/build/out/libopus_x86_64.so" "$assets_dir/libopus_x86_64.so.blob"
docker cp "$container_id:/build/out/libopus_aarch64.so" "$assets_dir/libopus_aarch64.so.blob"
docker rm "$container_id" > /dev/null
local x86_64_size aarch64_size
x86_64_size=$(wc -c < "$assets_dir/libopus_x86_64.so.blob" | tr -d ' ')
aarch64_size=$(wc -c < "$assets_dir/libopus_aarch64.so.blob" | tr -d ' ')
ok "Linux build complete:"
ok " $assets_dir/libopus_x86_64.so.blob ($x86_64_size bytes)"
ok " $assets_dir/libopus_aarch64.so.blob ($aarch64_size bytes)"
}
# --------------------------------------------------------------------------- #
# iOS
# --------------------------------------------------------------------------- #
build_ios() {
log "Building opus for ${BOLD}iOS${RESET} (XCFramework)..."
local build_script="$SCRIPT_DIR/opus_flutter_ios/ios/build_xcframework.sh"
if [ ! -f "$build_script" ]; then
err "Missing build script: $build_script"
exit 1
fi
chmod +x "$build_script"
"$build_script"
ok "iOS build complete."
}
# --------------------------------------------------------------------------- #
# macOS
# --------------------------------------------------------------------------- #
build_macos() {
log "Building opus for ${BOLD}macOS${RESET} (XCFramework)..."
local build_script="$SCRIPT_DIR/opus_flutter_macos/macos/build_xcframework.sh"
if [ ! -f "$build_script" ]; then
err "Missing build script: $build_script"
exit 1
fi
chmod +x "$build_script"
"$build_script"
ok "macOS build complete."
}
# --------------------------------------------------------------------------- #
# Main
# --------------------------------------------------------------------------- #
ALL_PLATFORMS=(web windows linux ios macos)
print_usage() {
echo "Usage: $0 [platform ...]"
echo ""
echo "Platforms: ${ALL_PLATFORMS[*]}"
echo ""
echo "If no platforms are specified, all are built."
echo ""
echo "Examples:"
echo " $0 # build all"
echo " $0 web # build web only"
echo " $0 web windows # build web and windows"
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
print_usage
exit 0
fi
targets=("${@:-}")
if [ ${#targets[@]} -eq 0 ] || [ -z "${targets[0]}" ]; then
targets=("${ALL_PLATFORMS[@]}")
fi
echo ""
log "opus ${BOLD}${OPUS_VERSION}${RESET} – building for: ${BOLD}${targets[*]}${RESET}"
echo ""
for target in "${targets[@]}"; do
case "$target" in
web) build_web ;;
windows) build_windows ;;
linux) build_linux ;;
ios) build_ios ;;
macos) build_macos ;;
*)
err "Unknown platform: $target"
print_usage
exit 1
;;
esac
echo ""
done
ok "${BOLD}All done!${RESET}"