Skip to content

Commit e373548

Browse files
authored
Merge pull request #2 from iotserver24/main
fixed linux build for apps
2 parents 79e0e76 + 36a9151 commit e373548

17 files changed

Lines changed: 480 additions & 0 deletions

File tree

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Build
2+
build/
3+
4+
# Dart / Flutter
5+
.dart_tool/
6+
.packages
7+
*.iml
8+
.flutter-plugins
9+
.flutter-plugins-dependencies
10+
11+
# IDE
12+
.idea/
13+
.vscode/
14+
*.swp
15+
*.swo
16+
*~
17+
18+
# OS
19+
.DS_Store
20+
Thumbs.db
21+
22+
# Generated
23+
*.g.dart
24+
*.freezed.dart
25+
*.mocks.dart

assets/images/.gitkeep

Whitespace-only changes.

linux/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ add_subdirectory("runner")
6060
# Run the Flutter tool portions of the build. This must not be removed.
6161
add_dependencies(${BINARY_NAME} flutter_assemble)
6262

63+
# Use system mimalloc so build succeeds (media_kit_libs_linux static build is broken).
64+
# For AppImage: copy libmimalloc.so into bundle/lib/ so end users don't need to install it.
65+
set(MIMALLOC_USE_STATIC_LIBS OFF CACHE BOOL "" FORCE)
66+
6367
# Only the install-generated bundle's copy of the executable will launch
6468
# correctly, since the resources must in the right relative locations. To avoid
6569
# people trying to run the unbundled copy, put it in a subdirectory instead of

linux/packaging/AppRun

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
APPDIR="$(dirname "$(readlink -f "$0")")"
3+
exec "$APPDIR/usr/bin/echo" "$@"

linux/packaging/build.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env bash
2+
# Build Linux packages locally: AppImage, .deb, .rpm
3+
# Run from repo root: ./linux/packaging/build.sh
4+
# Requires: flutter, patchelf. Optional: appimagetool (or downloaded), fpm and/or dpkg for packages.
5+
6+
set -e
7+
cd "$(dirname "$0")/../.."
8+
REPO_ROOT="$PWD"
9+
10+
if ! command -v patchelf &>/dev/null; then
11+
echo "patchelf is required. Install it:"
12+
echo " Fedora: sudo dnf install patchelf"
13+
echo " Debian/Ubuntu: sudo apt install patchelf"
14+
exit 1
15+
fi
16+
17+
# Optional: skip Flutter build and use existing bundle (e.g. after "flutter build linux")
18+
SKIP_FLUTTER_BUILD=false
19+
[ "${1:-}" = "--no-flutter-build" ] || [ "${1:-}" = "-n" ] && SKIP_FLUTTER_BUILD=true
20+
21+
# Version from pubspec.yaml
22+
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: *//;s/+.*//;s/ *$//')
23+
echo "Building Echo $VERSION"
24+
25+
BUNDLE="$REPO_ROOT/build/linux/x64/release/bundle"
26+
if [ "$SKIP_FLUTTER_BUILD" = true ]; then
27+
if [ ! -x "$BUNDLE/echo" ]; then
28+
echo "Bundle not found. Run: flutter build linux"
29+
exit 1
30+
fi
31+
echo "Using existing bundle (skip Flutter build)"
32+
else
33+
flutter pub get
34+
flutter build linux --release
35+
fi
36+
# Flutter Linux engine looks for lib/ and data/ in the executable's directory
37+
# (executable_dir/lib/libapp.so, executable_dir/data/flutter_assets). So we put
38+
# lib and data under usr/bin/ for both AppImage and .deb/.rpm.
39+
STAGING="$REPO_ROOT/build/linux_pkg_staging"
40+
rm -rf "$STAGING"
41+
mkdir -p "$STAGING/usr/bin/lib" "$STAGING/usr/bin/data"
42+
43+
# --- Staging: binary, libs, data (all under usr/bin so engine finds them) ---
44+
cp "$BUNDLE/echo" "$STAGING/usr/bin/echo"
45+
cp -a "$BUNDLE/lib/"* "$STAGING/usr/bin/lib/" 2>/dev/null || true
46+
cp -a "$BUNDLE/data/"* "$STAGING/usr/bin/data/"
47+
48+
# Bundle libmpv and libmimalloc (so users don't need to install them)
49+
ARCH=$(uname -m)
50+
for lib in libmpv libmimalloc; do
51+
for dir in /usr/lib64 /usr/lib/$ARCH-linux-gnu /usr/lib; do
52+
for f in "$dir"/$lib.so*; do
53+
[ -e "$f" ] && cp -P "$f" "$STAGING/usr/bin/lib/" && break 2
54+
done
55+
done
56+
done
57+
58+
patchelf --set-rpath '$ORIGIN/lib' "$STAGING/usr/bin/echo"
59+
chmod +x "$STAGING/usr/bin/echo"
60+
61+
# .deb/.rpm: same layout, binary named echo-music to avoid conflict with coreutils
62+
PKG_STAGING="$REPO_ROOT/build/linux_pkg_staging_named"
63+
rm -rf "$PKG_STAGING"
64+
mkdir -p "$PKG_STAGING/usr/bin/lib" "$PKG_STAGING/usr/bin/data" \
65+
"$PKG_STAGING/usr/share/applications" "$PKG_STAGING/usr/share/icons/hicolor/256x256/apps"
66+
cp "$STAGING/usr/bin/echo" "$PKG_STAGING/usr/bin/echo-music"
67+
cp -a "$STAGING/usr/bin/lib/"* "$PKG_STAGING/usr/bin/lib/"
68+
cp -a "$STAGING/usr/bin/data/"* "$PKG_STAGING/usr/bin/data/"
69+
cp "$REPO_ROOT/icons/Echo_nobg.png" "$PKG_STAGING/usr/share/icons/hicolor/256x256/apps/echo.png"
70+
cp "$REPO_ROOT/linux/packaging/echo-music.desktop" "$PKG_STAGING/usr/share/applications/echo-music.desktop"
71+
patchelf --set-rpath '$ORIGIN/lib' "$PKG_STAGING/usr/bin/echo-music"
72+
chmod +x "$PKG_STAGING/usr/bin/echo-music"
73+
74+
echo "Staging ready at $STAGING"
75+
76+
# --- AppImage ---
77+
APPDIR="$REPO_ROOT/build/Echo.AppDir"
78+
rm -rf "$APPDIR"
79+
mkdir -p "$APPDIR/usr" "$APPDIR/usr/share/icons/hicolor/256x256/apps"
80+
cp -a "$STAGING/usr/bin" "$APPDIR/usr/"
81+
cp "$REPO_ROOT/icons/Echo_nobg.png" "$APPDIR/usr/share/icons/hicolor/256x256/apps/echo.png"
82+
cp "$REPO_ROOT/icons/Echo_nobg.png" "$APPDIR/echo.png"
83+
cp "$REPO_ROOT/linux/packaging/echo.desktop" "$APPDIR/echo.desktop"
84+
cp "$REPO_ROOT/linux/packaging/AppRun" "$APPDIR/AppRun"
85+
chmod +x "$APPDIR/AppRun"
86+
87+
APPIMAGETOOL=""
88+
if command -v appimagetool &>/dev/null; then
89+
APPIMAGETOOL=appimagetool
90+
elif [ -x "$REPO_ROOT/build/appimagetool.AppImage" ]; then
91+
APPIMAGETOOL="$REPO_ROOT/build/appimagetool.AppImage"
92+
else
93+
echo "Downloading appimagetool..."
94+
curl -sL -o "$REPO_ROOT/build/appimagetool.AppImage" \
95+
"https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage"
96+
chmod +x "$REPO_ROOT/build/appimagetool.AppImage"
97+
APPIMAGETOOL="$REPO_ROOT/build/appimagetool.AppImage"
98+
fi
99+
ARCH=x86_64 "$APPIMAGETOOL" -n "$APPDIR" "$REPO_ROOT/build/Echo-${VERSION}-x86_64.AppImage"
100+
echo "Built: build/Echo-${VERSION}-x86_64.AppImage"
101+
102+
# --- .deb ---
103+
if command -v dpkg-deb &>/dev/null; then
104+
PKG="$REPO_ROOT/build/echo-music_${VERSION}_amd64"
105+
rm -rf "$PKG"
106+
mkdir -p "$PKG/DEBIAN" "$PKG/usr/share/applications" "$PKG/usr/share/icons/hicolor/256x256/apps"
107+
cp -a "$PKG_STAGING/usr/bin" "$PKG/usr/"
108+
cp "$REPO_ROOT/icons/Echo_nobg.png" "$PKG/usr/share/icons/hicolor/256x256/apps/echo.png"
109+
cp "$REPO_ROOT/linux/packaging/echo-music.desktop" "$PKG/usr/share/applications/echo-music.desktop"
110+
sed "s/VERSION/$VERSION/" "$REPO_ROOT/linux/packaging/control.in" > "$PKG/DEBIAN/control"
111+
dpkg-deb --root-owner-group --build "$PKG" "$REPO_ROOT/build/echo-music_${VERSION}_amd64.deb"
112+
rm -rf "$PKG"
113+
echo "Built: build/echo-music_${VERSION}_amd64.deb"
114+
elif command -v fpm &>/dev/null; then
115+
fpm -s dir -t deb -n echo-music -v "$VERSION" \
116+
--architecture amd64 \
117+
--description "Echo Music Desktop - Music player" \
118+
-C "$PKG_STAGING" usr
119+
mv "echo-music_${VERSION}_amd64.deb" "$REPO_ROOT/build/"
120+
echo "Built: build/echo-music_${VERSION}_amd64.deb"
121+
else
122+
echo "Skip .deb: install dpkg or fpm (gem install fpm)"
123+
fi
124+
125+
# --- .rpm ---
126+
if command -v fpm &>/dev/null; then
127+
fpm -s dir -t rpm -n echo-music -v "$VERSION" \
128+
--architecture x86_64 \
129+
--description "Echo Music Desktop - Music player" \
130+
-C "$PKG_STAGING" usr
131+
mv "$REPO_ROOT/echo-music-${VERSION}-1.x86_64.rpm" "$REPO_ROOT/build/echo-music_${VERSION}_x86_64.rpm"
132+
echo "Built: build/echo-music_${VERSION}_x86_64.rpm"
133+
else
134+
echo "Skip .rpm: install fpm (gem install fpm)"
135+
fi
136+
137+
echo "Done. Outputs in build/"

linux/packaging/control.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Package: echo-music
2+
Version: VERSION
3+
Section: sound
4+
Priority: optional
5+
Architecture: amd64
6+
Maintainer: Echo Music <noreply@echo.music>
7+
Description: Echo Music Desktop - Music player

linux/packaging/echo-music.desktop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Desktop Entry]
2+
Type=Application
3+
Name=Echo Music
4+
Comment=Music player
5+
Exec=echo-music
6+
Icon=echo
7+
Categories=AudioVideo;Audio;Music;Player;
8+
StartupWMClass=echo

linux/packaging/echo.desktop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Desktop Entry]
2+
Type=Application
3+
Name=Echo Music
4+
Comment=Music player
5+
Exec=echo
6+
Icon=echo
7+
Categories=AudioVideo;Audio;Music;Player;
8+
StartupWMClass=echo
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## 1.2.1
2+
3+
- **FIX**: correct minimum required CMake version.
4+
5+
## 1.2.0
6+
7+
- chore: refactor mimalloc import
8+
9+
## 1.1.3
10+
11+
- feat: improve compile-time failure handling
12+
13+
## 1.1.2
14+
15+
- build: bump libraries
16+
17+
## 1.1.1
18+
19+
- build: bump libraries
20+
21+
## 1.1.0
22+
23+
- feat: mimalloc support
24+
25+
## 1.0.2
26+
27+
- feat: migrate to the plugin template
28+
- feat: make package optional during build
29+
- feat: add `MEDIA_KIT_LIBS_AVAILABLE` option
30+
31+
## 1.0.1
32+
33+
- chore: add `example/README.md`
34+
35+
## 1.0.0
36+
37+
- Initial release
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 & onwards Hitesh Kumar Saini <saini123hitesh@gmail.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)