-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-linux-demos.sh
More file actions
executable file
·272 lines (230 loc) · 7.34 KB
/
build-linux-demos.sh
File metadata and controls
executable file
·272 lines (230 loc) · 7.34 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
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIGURATION="Release"
RID="linux-x64"
CLEAN=0
JOBS="${JOBS:-$(nproc)}"
usage() {
cat <<'EOF'
Usage: ./build-linux-demos.sh [options] [demo...]
Builds the Linux LVGL shared library and publishes the demo apps as
self-contained single-file executables.
Options:
--clean Remove previous build/publish output first.
--configuration <cfg> Build configuration. Default: Release
--rid <rid> Runtime identifier. Default: linux-x64
-j, --jobs <count> Parallel build jobs. Default: nproc
-h, --help Show this help.
Demos:
SerialPort
WinFormsDemo
PictureBoxDemo
MusicDemo
SmartWatchDemo
If no demo is specified, all demos are published.
EOF
}
get_demo_target_framework() {
case "$1" in
SerialPort|WinFormsDemo|PictureBoxDemo|MusicDemo|SmartWatchDemo)
printf 'net10.0'
;;
*)
fail "no target framework mapping for demo: $1"
;;
esac
}
get_demo_project_path() {
case "$1" in
MusicDemo)
printf '%s' "$ROOT_DIR/src/Demos/MusicDemo/MusicDemo.csproj"
;;
*)
printf '%s' "$ROOT_DIR/src/Demos/$1/$1.csproj"
;;
esac
}
fail() {
printf 'error: %s\n' "$*" >&2
exit 1
}
get_cmd_path_or_null() {
command -v "$1" 2>/dev/null || true
}
require_cmd() {
local name="$1"
local install_hint="${2:-}"
local command_path
command_path="$(get_cmd_path_or_null "$name")"
if [[ -z "$command_path" ]]; then
local message="缺少必需命令: $name"
if [[ -n "$install_hint" ]]; then
message+=$'\n安装建议: '
message+="$install_hint"
fi
message+=$'\n最小依赖: .NET SDK 10、CMake、Ninja、基础 GNU 文件工具(cp/find/ln/rm/chmod)。'
fail "$message"
fi
printf '%s' "$command_path"
}
show_minimal_requirements() {
printf '==> 最小安装清单\n'
printf ' 1. .NET SDK 10.x\n'
printf ' 2. CMake\n'
printf ' 3. Ninja\n'
printf ' 4. 基础 GNU 文件工具: cp / find / ln / rm / chmod\n'
printf ' 5. Linux 构建环境(Ubuntu/Debian 可直接 apt 安装上述依赖)\n'
}
assert_build_prerequisites() {
local cmake_path dotnet_path ninja_path
cmake_path="$(require_cmd cmake '安装 CMake,并确保 cmake 在 PATH 中。')"
dotnet_path="$(require_cmd dotnet '安装 .NET SDK 10,并确保 dotnet 在 PATH 中。')"
ninja_path="$(require_cmd ninja '安装 ninja-build,并确保 ninja 在 PATH 中。')"
require_cmd cp '安装 coreutils。' >/dev/null
require_cmd find '安装 findutils。' >/dev/null
require_cmd ln '安装 coreutils。' >/dev/null
require_cmd rm '安装 coreutils。' >/dev/null
require_cmd chmod '安装 coreutils。' >/dev/null
printf '==> 检查构建依赖\n'
printf ' dotnet: %s\n' "$dotnet_path"
printf ' cmake : %s\n' "$cmake_path"
printf ' ninja : %s\n' "$ninja_path"
}
normalize_demo() {
case "$1" in
serialport|SerialPort)
printf 'SerialPort'
;;
winformsdemo|WinFormsDemo)
printf 'WinFormsDemo'
;;
pictureboxdemo|PictureBoxDemo)
printf 'PictureBoxDemo'
;;
musicdemo|MusicDemo)
printf 'MusicDemo'
;;
smartwatchdemo|SmartWatchDemo)
printf 'SmartWatchDemo'
;;
*)
return 1
;;
esac
}
DEMO_NAMES=()
while (($# > 0)); do
case "$1" in
--clean)
CLEAN=1
;;
--configuration)
shift
(($# > 0)) || fail "--configuration requires a value"
CONFIGURATION="$1"
;;
--rid)
shift
(($# > 0)) || fail "--rid requires a value"
RID="$1"
;;
-j|--jobs)
shift
(($# > 0)) || fail "--jobs requires a value"
JOBS="$1"
;;
-h|--help)
usage
exit 0
;;
*)
demo_name="$(normalize_demo "$1")" || fail "unknown demo: $1"
DEMO_NAMES+=("$demo_name")
;;
esac
shift
done
if ((${#DEMO_NAMES[@]} == 0)); then
DEMO_NAMES=(SerialPort WinFormsDemo PictureBoxDemo MusicDemo SmartWatchDemo)
fi
show_minimal_requirements
assert_build_prerequisites
LVGL_SOURCE_DIR="$ROOT_DIR/libs/lvgl"
LVGL_BUILD_DIR="$ROOT_DIR/libs/build/lvgl-x11"
LVGL_LIB_DIR="$LVGL_BUILD_DIR/lib"
LVGL_SONAME_PATH="$LVGL_LIB_DIR/liblvgl.so.9"
DIST_DIR="$ROOT_DIR/dist/$RID"
NUGET_CONFIG_PATH="$ROOT_DIR/NuGet.Wsl.Config"
NUGET_CONFIG_OPTION=()
if [[ -f "$NUGET_CONFIG_PATH" ]]; then
NUGET_CONFIG_OPTION=(--configfile "$NUGET_CONFIG_PATH")
fi
LINUX_NUGET_PACKAGES="${HOME}/.nuget/packages"
export NUGET_PACKAGES="$LINUX_NUGET_PACKAGES"
export NUGET_FALLBACK_PACKAGES=""
if ((CLEAN)); then
rm -rf "$DIST_DIR" "$LVGL_BUILD_DIR"
fi
mkdir -p "$DIST_DIR"
if ((${#NUGET_CONFIG_OPTION[@]} > 0)); then
find "$ROOT_DIR/src" -type d \( -name obj -o -name bin \) -prune -exec rm -rf {} +
fi
printf '==> Building LVGL shared library (%s)\n' "$RID"
cmake -S "$LVGL_SOURCE_DIR" -B "$LVGL_BUILD_DIR" \
-G Ninja \
-DCMAKE_BUILD_TYPE="$CONFIGURATION" \
-DBUILD_SHARED_LIBS=ON \
-DCONFIG_LV_BUILD_EXAMPLES=OFF \
-DCONFIG_LV_BUILD_DEMOS=OFF \
-DCONFIG_LV_USE_LINUX_FBDEV=OFF \
-DCONFIG_LV_USE_SDL=OFF \
-DCONFIG_LV_USE_LINUX_DRM=OFF \
-DCONFIG_LV_USE_WAYLAND=OFF \
-DLV_BUILD_CONF_DIR="$ROOT_DIR/libs"
cmake --build "$LVGL_BUILD_DIR" -j"$JOBS"
[[ -f "$LVGL_SONAME_PATH" ]] || fail "missing built LVGL shared library: $LVGL_SONAME_PATH"
publish_demo() {
local demo_name="$1"
local project_path
local publish_dir="$DIST_DIR/$demo_name"
local executable_path="$publish_dir/$demo_name"
local target_framework
target_framework="$(get_demo_target_framework "$demo_name")"
project_path="$(get_demo_project_path "$demo_name")"
[[ -f "$project_path" ]] || fail "missing demo project: $project_path"
printf '==> Publishing %s (%s)\n' "$demo_name" "$target_framework"
rm -rf "$publish_dir"
dotnet restore "$project_path" \
-p:Configuration="$CONFIGURATION" \
-r "$RID" \
--force-evaluate \
"${NUGET_CONFIG_OPTION[@]}" \
-p:EnableWindowsTargeting=true \
-p:RestorePackagesPath="$LINUX_NUGET_PACKAGES" \
-p:NuGetPackageFolders="$LINUX_NUGET_PACKAGES" \
-p:RestoreFallbackFolders=
dotnet publish "$project_path" \
-f "$target_framework" \
-c "$CONFIGURATION" \
-r "$RID" \
-o "$publish_dir" \
--no-restore \
"${NUGET_CONFIG_OPTION[@]}" \
-p:Configuration="$CONFIGURATION" \
-p:EnableWindowsTargeting=true \
-p:RestorePackagesPath="$LINUX_NUGET_PACKAGES" \
-p:NuGetPackageFolders="$LINUX_NUGET_PACKAGES" \
-p:RestoreFallbackFolders=
[[ -f "$executable_path" ]] || fail "missing published executable: $executable_path"
cp -Lf "$LVGL_SONAME_PATH" "$publish_dir/liblvgl.so.9"
ln -sfn liblvgl.so.9 "$publish_dir/liblvgl.so"
rm -f "$publish_dir"/*.pdb "$publish_dir"/*.dbg
chmod +x "$executable_path"
printf ' output: %s\n' "$publish_dir"
}
for demo_name in "${DEMO_NAMES[@]}"; do
publish_demo "$demo_name"
done
printf '==> Done\n'
printf 'Published demos under %s\n' "$DIST_DIR"