From 690da56e356f0a45fcabef39a397e3167b019583 Mon Sep 17 00:00:00 2001 From: zarzet <42882290+zarzet@users.noreply.github.com> Date: Sun, 22 Nov 2026 00:21:30 +0700 Subject: [PATCH] build(desktop): smaller desktop packages - FFmpeg ships as shared libraries beside ffmpeg and ffprobe instead of two static programs that each carried every codec: the lgpl-shared builds on Windows and Linux (RUNPATH $ORIGIN on Linux) and a shared build on macOS without video decoders the app does not need. - Bundles leave out assets the platform never loads: web helper files, glass shaders of other renderers and the licenses of Android-only libraries. The Skia glass shaders stay, as Linux runs without Impeller on NVIDIA. - Runners compile for size, and Linux strips its libraries except libapp.so and the Flutter engine. - Tighter compression: zstd for the AppImage, xz for the deb, LZMA2 ultra for the installer, the highest zip level, and no .pdb or import libraries in the Windows zip. - package_macos_dmg.sh packages a single architecture on request. Untested here: needs a desktop build on each platform. --- linux/CMakeLists.txt | 21 ++++++- scripts/embed_ffmpeg_macos.sh | 16 ++++- scripts/fetch_desktop_ffmpeg.sh | 104 +++++++++++++++++++++++++++++--- scripts/package_linux.sh | 30 +++++++-- scripts/package_macos_dmg.sh | 61 ++++++++++++++++--- scripts/package_windows.ps1 | 17 +++++- windows/CMakeLists.txt | 20 +++++- windows/installer/mornye.iss | 5 +- 8 files changed, 246 insertions(+), 28 deletions(-) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index b7a5a904f..bc1c6736d 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -40,7 +40,8 @@ endif() function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) - target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") + target_compile_options(${TARGET} PRIVATE "$<$>:-Os;-ffunction-sections;-fdata-sections>") + target_link_options(${TARGET} PRIVATE "$<$>:-Wl,--gc-sections>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() @@ -134,6 +135,11 @@ set(MORNYE_FFMPEG_DIR if(EXISTS "${MORNYE_FFMPEG_DIR}/ffmpeg" AND EXISTS "${MORNYE_FFMPEG_DIR}/ffprobe") install(PROGRAMS "${MORNYE_FFMPEG_DIR}/ffmpeg" "${MORNYE_FFMPEG_DIR}/ffprobe" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}/ffmpeg" COMPONENT Runtime) + file(GLOB MORNYE_FFMPEG_LIBS "${MORNYE_FFMPEG_DIR}/lib*.so*") + if(MORNYE_FFMPEG_LIBS) + install(FILES ${MORNYE_FFMPEG_LIBS} + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}/ffmpeg" COMPONENT Runtime) + endif() install(FILES "${MORNYE_FFMPEG_DIR}/LICENSE.txt" "${MORNYE_FFMPEG_DIR}/SOURCE.txt" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}/ffmpeg" COMPONENT Runtime) else() @@ -155,7 +161,18 @@ install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" - DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime + PATTERN "packages/media_kit/assets/web/*" EXCLUDE + PATTERN "packages/record_web/*" EXCLUDE + PATTERN "packages/flutter_local_notifications_web/*" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/metaball_*" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/liquid_glass_border.frag" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/liquid_glass.frag" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/liquid_glass_geometry.frag" EXCLUDE + PATTERN "assets/licenses/usb.txt" EXCLUDE + PATTERN "assets/licenses/oboe.txt" EXCLUDE + PATTERN "assets/licenses/wavpack.txt" EXCLUDE + PATTERN "assets/licenses/flac.txt" EXCLUDE) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" diff --git a/scripts/embed_ffmpeg_macos.sh b/scripts/embed_ffmpeg_macos.sh index d76e818f4..b2af525be 100755 --- a/scripts/embed_ffmpeg_macos.sh +++ b/scripts/embed_ffmpeg_macos.sh @@ -38,7 +38,13 @@ is_staged() { } SOURCE_DIR="" -for candidate in "$STAGE_ROOT/macos-universal" "$STAGE_ROOT/macos-$(host_arch)"; do +CANDIDATES=() +case "${MORNYE_MACOS_ARCH:-}" in + arm64) CANDIDATES=("$STAGE_ROOT/macos-arm64" "$STAGE_ROOT/macos-universal") ;; + x64|x86_64) CANDIDATES=("$STAGE_ROOT/macos-x64" "$STAGE_ROOT/macos-universal") ;; + *) CANDIDATES=("$STAGE_ROOT/macos-universal" "$STAGE_ROOT/macos-$(host_arch)") ;; +esac +for candidate in "${CANDIDATES[@]}"; do if is_staged "$candidate"; then SOURCE_DIR="$candidate" break @@ -69,6 +75,10 @@ mkdir -p "$DESTINATION_DIR" for file in "${FILES[@]}"; do cp -f "$SOURCE_DIR/$file" "$DESTINATION_DIR/$file" done +for lib in "$SOURCE_DIR"/lib*.dylib; do + [[ -e "$lib" || -L "$lib" ]] || continue + cp -a "$lib" "$DESTINATION_DIR/$(basename "$lib")" +done chmod 755 "$DESTINATION_DIR/ffmpeg" "$DESTINATION_DIR/ffprobe" # Nested code must be signed before Xcode signs the app. The app ships @@ -78,6 +88,10 @@ SIGN_IDENTITY="-" if [[ "${CODE_SIGNING_ALLOWED:-YES}" != "NO" && -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" ]]; then SIGN_IDENTITY="$EXPANDED_CODE_SIGN_IDENTITY" fi +for lib in "$DESTINATION_DIR"/lib*.dylib; do + [[ -f "$lib" && ! -L "$lib" ]] || continue + codesign --force --sign "$SIGN_IDENTITY" --timestamp=none "$lib" +done for tool in ffmpeg ffprobe; do codesign --force --sign "$SIGN_IDENTITY" --options runtime --timestamp=none \ "$DESTINATION_DIR/$tool" diff --git a/scripts/fetch_desktop_ffmpeg.sh b/scripts/fetch_desktop_ffmpeg.sh index 39a840d73..d66806d65 100644 --- a/scripts/fetch_desktop_ffmpeg.sh +++ b/scripts/fetch_desktop_ffmpeg.sh @@ -70,12 +70,25 @@ MACOS_MIN_VERSION="12.0" MACOS_ENCODERS="aac,alac,flac,libmp3lame,libopus,opus,vorbis" MACOS_ENCODERS+=",pcm_s16le,pcm_s16be,pcm_s24le,pcm_s24be,pcm_s32le" MACOS_ENCODERS+=",pcm_f32le,pcm_u8,mjpeg,png,rawvideo,wrapped_avframe" +# Drop large standalone video decoders Mornye never needs, while retaining +# every audio decoder, H.264/HEVC motion artwork, and cover image decoders. +MACOS_DISABLED_VIDEO_DECODERS="vp8,vp9,av1,mpeg1video,mpeg2video,mpeg4" +MACOS_DISABLED_VIDEO_DECODERS+=",msmpeg4v1,msmpeg4v2,msmpeg4v3,wmv1,wmv2,wmv3,vc1" +MACOS_DISABLED_VIDEO_DECODERS+=",theora,prores,dnxhd,rv10,rv20,rv30,rv40,svq1,svq3" +MACOS_DISABLED_VIDEO_DECODERS+=",cinepak,indeo2,indeo3,indeo4,indeo5,h261,h263,h263i,h263p" +MACOS_DISABLED_VIDEO_DECODERS+=",flv,flashsv,flashsv2,dirac,snow,bink,smacker" +MACOS_DISABLED_VIDEO_DECODERS+=",truemotion1,truemotion2,vp3,vp5,vp6,vp6a,vp6f" +MACOS_DISABLED_VIDEO_DECODERS+=",exr,jpeg2000,jpegls,tiff,psd,dds,qtrle,tscc,utvideo" +MACOS_DISABLED_VIDEO_DECODERS+=",vvc,evc,cavs,mjpegb,dvvideo,ffv1,ffvhuff,huffyuv" +MACOS_DISABLED_VIDEO_DECODERS+=",lagarith,magicyuv,pixlet,sheervideo,speedhq,cfhd,hap" MACOS_FFMPEG_OPTIONS=( --disable-gpl --disable-nonfree --disable-version3 - --disable-shared --enable-static --disable-autodetect + --enable-shared --disable-static --disable-autodetect --disable-doc --disable-ffplay --disable-debug --disable-avdevice --disable-indevs --disable-outdevs + --disable-postproc --disable-hwaccels --disable-encoders --enable-encoder="$MACOS_ENCODERS" + --disable-decoder="$MACOS_DISABLED_VIDEO_DECODERS" --enable-zlib --enable-audiotoolbox --enable-securetransport --enable-libmp3lame --enable-libopus --enable-libsoxr --pkg-config-flags=--static @@ -150,7 +163,7 @@ fetch_btbn() { windows-x64) platform=win64 ext=zip ;; windows-arm64) platform=winarm64 ext=zip ;; esac - asset="${MORNYE_FFMPEG_BTBN_ASSET:-ffmpeg-n$BTBN_BRANCH-latest-$platform-lgpl-$BTBN_BRANCH.$ext}" + asset="${MORNYE_FFMPEG_BTBN_ASSET:-ffmpeg-n$BTBN_BRANCH-latest-$platform-lgpl-shared-$BTBN_BRANCH.$ext}" base="https://github.com/BtbN/FFmpeg-Builds/releases/download/$BTBN_TAG" # "latest" moves; always fetch the checksums that match the archive. @@ -173,7 +186,30 @@ fetch_btbn() { fi local root root="$(find "$WORK_DIR/extract" -mindepth 1 -maxdepth 1 -type d | head -n 1)" + rm -f "$OUT_DIR"/*.dll "$OUT_DIR"/lib*.so* cp "$root/bin/ffmpeg$EXE" "$root/bin/ffprobe$EXE" "$OUT_DIR/" + if [[ "$OS" == "windows" ]]; then + if compgen -G "$root/bin/*.dll" > /dev/null; then + cp "$root/bin/"*.dll "$OUT_DIR/" + fi + elif [[ "$OS" == "linux" ]]; then + if compgen -G "$root/lib/lib*.so*" > /dev/null; then + cp -a "$root/lib"/lib*.so* "$OUT_DIR/" + # Remove unversioned linker symlinks (.so without version suffix); the + # executables link SONAMEs like libavcodec.so.62. + for link in "$OUT_DIR"/lib*.so; do + [[ -L "$link" ]] && rm -f "$link" + done + # Keep FFmpeg's shared libraries private to lib/ffmpeg/ via $ORIGIN so + # they never collide with the host system's libmpv / libav*. + if command -v patchelf >/dev/null 2>&1; then + patchelf --set-rpath '$ORIGIN' "$OUT_DIR/ffmpeg" "$OUT_DIR/ffprobe" + for lib in "$OUT_DIR"/lib*.so.*; do + [[ -f "$lib" && ! -L "$lib" ]] && patchelf --set-rpath '$ORIGIN' "$lib" + done + fi + fi + fi cp "$root/LICENSE.txt" "$OUT_DIR/LICENSE.txt" { echo "FFmpeg LGPL build from BtbN/FFmpeg-Builds." @@ -198,10 +234,10 @@ build_macos_arch() { jobs="$(sysctl -n hw.ncpu)" prefix="$work/deps" src="$work/src" - local flags="-arch $clang_arch -mmacosx-version-min=$MACOS_MIN_VERSION -O2" + local flags="-arch $clang_arch -mmacosx-version-min=$MACOS_MIN_VERSION -Os" mkdir -p "$out" "$work" "$downloads" - rm -f "$out/ffmpeg" "$out/ffprobe" + rm -f "$out/ffmpeg" "$out/ffprobe" "$out"/lib*.dylib download "https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.xz" \ "$downloads/ffmpeg-$FFMPEG_VERSION.tar.xz" verify "$downloads/ffmpeg-$FFMPEG_VERSION.tar.xz" "$FFMPEG_SHA256" @@ -283,14 +319,41 @@ build_macos_arch() { # Bash 3.2 (macOS) treats an empty "${cross[@]}" as unbound. ${cross[@]+"${cross[@]}"} --extra-cflags="$flags -I$prefix/include" - --extra-ldflags="-arch $clang_arch -mmacosx-version-min=$MACOS_MIN_VERSION -L$prefix/lib" + --extra-ldflags="-arch $clang_arch -mmacosx-version-min=$MACOS_MIN_VERSION -L$prefix/lib -Wl,-rpath,@loader_path -Wl,-dead_strip" "${MACOS_FFMPEG_OPTIONS[@]}" ) ( cd "$src/ffmpeg-$FFMPEG_VERSION" ./configure "${configure[@]}" make -j"$jobs" - cp ffmpeg ffprobe "$out/" + make install + cp "$prefix/bin/ffmpeg" "$prefix/bin/ffprobe" "$out/" + # Stage versioned shared libraries and SONAME symlinks (drop unversioned + # development links like libavcodec.dylib). + for lib in "$prefix/lib"/lib*.dylib; do + local name + name="$(basename "$lib")" + [[ "$name" =~ ^lib[a-z]+\.[0-9] ]] || continue + cp -a "$lib" "$out/$name" + done + # Rewrite install names from the temporary build prefix to @rpath so + # ffmpeg, ffprobe, and their sibling dylibs resolve via @loader_path. + local item dep + for item in "$out/ffmpeg" "$out/ffprobe" "$out"/lib*.dylib; do + [[ -f "$item" && ! -L "$item" ]] || continue + if [[ "$item" == *.dylib ]]; then + install_name_tool -id "@rpath/$(basename "$item")" "$item" + fi + while read -r dep _; do + case "$dep" in + "$prefix"/lib/*) + install_name_tool -change "$dep" "@rpath/$(basename "$dep")" "$item" + ;; + esac + done < <(otool -L "$item" | tail -n +2 | grep -v ':$') + xcrun strip -x "$item" + codesign --force --sign - "$item" + done cp COPYING.LGPLv2.1 "$out/LICENSE.txt" ) { @@ -324,9 +387,23 @@ build_macos() { build_macos_arch arm64 build_macos_arch x64 local base="$PROJECT_DIR/build/ffmpeg" + rm -f "$OUT_DIR"/lib*.dylib for tool in ffmpeg ffprobe; do lipo -create "$base/macos-arm64/$tool" "$base/macos-x64/$tool" \ -output "$OUT_DIR/$tool" + codesign --force --sign - "$OUT_DIR/$tool" + done + for lib in "$base/macos-arm64"/lib*.dylib; do + [[ -e "$lib" || -L "$lib" ]] || continue + local name + name="$(basename "$lib")" + if [[ -L "$lib" ]]; then + cp -a "$lib" "$OUT_DIR/$name" + else + lipo -create "$base/macos-arm64/$name" "$base/macos-x64/$name" \ + -output "$OUT_DIR/$name" + codesign --force --sign - "$OUT_DIR/$name" + fi done cp "$base/macos-arm64/LICENSE.txt" "$OUT_DIR/LICENSE.txt" { @@ -360,18 +437,25 @@ check_license() { exit 1 fi if [[ "$OS" == "macos" ]]; then - local tool library - for tool in ffmpeg ffprobe; do + local item library + for item in "$OUT_DIR/ffmpeg" "$OUT_DIR/ffprobe" "$OUT_DIR"/lib*.dylib; do + [[ -f "$item" && ! -L "$item" ]] || continue # The first line names the binary itself; the rest are its libraries. while read -r library _; do case "$library" in /usr/lib/*|/System/Library/*) ;; + @rpath/*) + if [[ ! -e "$OUT_DIR/${library#@rpath/}" ]]; then + echo "Error: $(basename "$item") links missing bundled library $library." >&2 + exit 1 + fi + ;; *) - echo "Error: $tool links $library, which is not a system library." >&2 + echo "Error: $(basename "$item") links $library, which is not a system or bundled library." >&2 exit 1 ;; esac - done < <(otool -L "$OUT_DIR/$tool" | tail -n +2 | grep -v ':$') + done < <(otool -L "$item" | tail -n +2 | grep -v ':$') done fi } diff --git a/scripts/package_linux.sh b/scripts/package_linux.sh index ee915e8ac..8e23fa6bd 100644 --- a/scripts/package_linux.sh +++ b/scripts/package_linux.sh @@ -97,6 +97,20 @@ install_tree() { cp -a "$BUNDLE_DIR/." "$root/usr/lib/$BINARY_NAME/" ln -s "../lib/$BINARY_NAME/$BINARY_NAME" "$root/usr/bin/$BINARY_NAME" + # Strip local symbols from the Linux runner, Rust backend, and native plugin + # shared libraries. Skip libapp.so and libflutter_linux_gtk.so because + # Flutter's AOT snapshot lookup relies on their exported ELF symbols. + if command -v strip >/dev/null 2>&1; then + strip --strip-unneeded "$root/usr/lib/$BINARY_NAME/$BINARY_NAME" 2>/dev/null || true + for lib in "$root/usr/lib/$BINARY_NAME/lib"/*.so; do + [[ -f "$lib" && ! -L "$lib" ]] || continue + case "$(basename "$lib")" in + libapp.so|libflutter_linux_gtk.so) continue ;; + *) strip --strip-unneeded "$lib" 2>/dev/null || true ;; + esac + done + fi + install -Dm644 "$PACKAGING_DIR/$APP_ID.desktop" "$share/applications/$APP_ID.desktop" mkdir -p "$share/metainfo" awk -v version="$UPSTREAM_VERSION" -v date="$release_date" ' @@ -174,7 +188,11 @@ APPRUN # The AppStream file is validated separately; appimagetool's check would # depend on whichever appstreamcli the host has. ARCH="$ARCH" APPIMAGE_EXTRACT_AND_RUN=1 VERSION="$UPSTREAM_VERSION" \ - "$appimagetool" --no-appstream --runtime-file "$runtime" "$appdir" "$OUTPUT" + "$appimagetool" --no-appstream --runtime-file "$runtime" \ + --comp zstd \ + --mksquashfs-opt -Xcompression-level --mksquashfs-opt 19 \ + --mksquashfs-opt -b --mksquashfs-opt 1M \ + "$appdir" "$OUTPUT" chmod 755 "$OUTPUT" } @@ -184,7 +202,7 @@ build_deb() { chmod -R u+rwX,go+rX,go-w "$root" local deb_version="${UPSTREAM_VERSION//-/\~}" - local fallback_depends="libc6 (>= 2.35), libgcc-s1, libstdc++6, libgtk-3-0 | libgtk-3-0t64, libglib2.0-0 | libglib2.0-0t64, libsecret-1-0, libjson-glib-1.0-0, libgstreamer1.0-0, libgstreamer-plugins-base1.0-0, libasound2 | libasound2t64, liblzma5" + local fallback_depends="libc6 (>= 2.35), libgcc-s1, libstdc++6, libgtk-3-0 | libgtk-3-0t64, libglib2.0-0 | libglib2.0-0t64, libsecret-1-0, libgstreamer1.0-0, libgstreamer-plugins-base1.0-0, libasound2 | libasound2t64, liblzma5" local depends="" if command -v dpkg-shlibdeps >/dev/null 2>&1; then @@ -198,9 +216,13 @@ build_deb() { elf_files+=("$candidate") fi done < <(find "$root/usr/lib/$BINARY_NAME" -type f -print0) + local shlib_paths=(-l"$root/usr/lib/$BINARY_NAME/lib") + if [[ -d "$root/usr/lib/$BINARY_NAME/lib/ffmpeg" ]]; then + shlib_paths+=(-l"$root/usr/lib/$BINARY_NAME/lib/ffmpeg") + fi local substvars if substvars="$(cd "$shlib_dir" && dpkg-shlibdeps -O --ignore-missing-info \ - -l"$root/usr/lib/$BINARY_NAME/lib" "${elf_files[@]}" 2>"$WORK_DIR/shlibdeps.log")"; then + "${shlib_paths[@]}" "${elf_files[@]}" 2>"$WORK_DIR/shlibdeps.log")"; then depends="$(sed -n 's/^shlibs:Depends=//p' <<< "$substvars")" else echo "Warning: dpkg-shlibdeps failed; using the fixed dependency list." >&2 @@ -231,7 +253,7 @@ CONTROL mkdir -p "$(dirname "$OUTPUT")" rm -f "$OUTPUT" - dpkg-deb --build --root-owner-group "$root" "$OUTPUT" + dpkg-deb -Zxz -z9 --build --root-owner-group "$root" "$OUTPUT" dpkg-deb --info "$OUTPUT" } diff --git a/scripts/package_macos_dmg.sh b/scripts/package_macos_dmg.sh index f383b5afd..8ca244c96 100644 --- a/scripts/package_macos_dmg.sh +++ b/scripts/package_macos_dmg.sh @@ -14,6 +14,7 @@ # Environment: # MORNYE_DMG_VOLUME_NAME volume name (default: Mornye) # MORNYE_CODE_SIGN_IDENTITY signing identity (default: - for ad hoc) +# MORNYE_MACOS_ARCH arm64, x86_64/x64, or universal (default: universal) set -euo pipefail @@ -31,6 +32,15 @@ OUTPUT="$2" VOLUME_NAME="${MORNYE_DMG_VOLUME_NAME:-Mornye}" SIGN_IDENTITY="${MORNYE_CODE_SIGN_IDENTITY:--}" APP_NAME="$(basename "$APP_SOURCE")" +case "${MORNYE_MACOS_ARCH:-universal}" in + arm64) TARGET_ARCH="arm64"; VERIFY_ARCHS=(arm64) ;; + x86_64|x64) TARGET_ARCH="x86_64"; VERIFY_ARCHS=(x86_64) ;; + universal) TARGET_ARCH="universal"; VERIFY_ARCHS=(arm64 x86_64) ;; + *) + echo "Error: MORNYE_MACOS_ARCH must be arm64, x86_64, x64, or universal." >&2 + exit 1 + ;; +esac if [[ ! -f "$APP_SOURCE/Contents/Info.plist" ]]; then echo "Error: $APP_SOURCE is not an app bundle." >&2 @@ -68,16 +78,53 @@ is_macho() { file -b "$1" | grep -q '^Mach-O' } -# Sign nested code first (helper executables such as a bundled ffmpeg, -# loose dylibs, then frameworks), and the app itself last with the -# entitlements it was built with. +# Remove non-macOS Flutter assets before signing and imaging. +FLUTTER_ASSETS_DIR="$STAGED_APP/Contents/Frameworks/App.framework/Resources/flutter_assets" +if [[ -d "$FLUTTER_ASSETS_DIR" ]]; then + rm -rf \ + "$FLUTTER_ASSETS_DIR/packages/media_kit/assets/web" \ + "$FLUTTER_ASSETS_DIR/packages/record_web" \ + "$FLUTTER_ASSETS_DIR/packages/flutter_local_notifications_web" + rm -f \ + "$FLUTTER_ASSETS_DIR/packages/liquid_glass_easy/lib/assets/shaders/metaball_"* \ + "$FLUTTER_ASSETS_DIR/packages/liquid_glass_easy/lib/assets/shaders/liquid_glass_desktop.frag" \ + "$FLUTTER_ASSETS_DIR/packages/liquid_glass_easy/lib/assets/shaders/liquid_glass_border.frag" \ + "$FLUTTER_ASSETS_DIR/assets/licenses/usb.txt" \ + "$FLUTTER_ASSETS_DIR/assets/licenses/oboe.txt" \ + "$FLUTTER_ASSETS_DIR/assets/licenses/wavpack.txt" \ + "$FLUTTER_ASSETS_DIR/assets/licenses/flac.txt" +fi + +# When packaging a single-architecture DMG, thin every universal Mach-O slice +# (including FlutterMacOS, media_kit, and plugin frameworks) before signing. +if [[ "$TARGET_ARCH" != "universal" ]]; then + echo "Thinning universal Mach-O binaries in $APP_NAME to $TARGET_ARCH" + while IFS= read -r -d '' candidate; do + if file -b "$candidate" | grep -q '^Mach-O universal binary'; then + if lipo "$candidate" -verify_arch "$TARGET_ARCH" 2>/dev/null; then + lipo -thin "$TARGET_ARCH" "$candidate" -output "$candidate.thin" + mv -f "$candidate.thin" "$candidate" + fi + fi + done < <(find "$STAGED_APP" -type f ! -lname '*' -print0) +fi + +# Sign nested code first (shared libraries, helper executables such as a +# bundled ffmpeg, loose dylibs, then frameworks), and the app itself last with +# the entitlements it was built with. echo "Signing $APP_NAME with identity $SIGN_IDENTITY" +while IFS= read -r -d '' library; do + if is_macho "$library"; then + codesign --force --sign "$SIGN_IDENTITY" --timestamp=none "$library" + fi +done < <(find "$STAGED_APP/Contents/Resources" -type f -name '*.dylib' -print0) + while IFS= read -r -d '' candidate; do if is_macho "$candidate"; then codesign --force --sign "$SIGN_IDENTITY" --timestamp=none "$candidate" fi done < <(find "$STAGED_APP/Contents/MacOS" "$STAGED_APP/Contents/Resources" \ - -type f -perm -u+x ! -path "$STAGED_APP/Contents/MacOS/$EXECUTABLE" -print0) + -type f -perm -u+x ! -name '*.dylib' ! -path "$STAGED_APP/Contents/MacOS/$EXECUTABLE" -print0) if [[ -d "$STAGED_APP/Contents/Frameworks" ]]; then while IFS= read -r -d '' library; do @@ -100,12 +147,12 @@ codesign --verify --deep --strict "$STAGED_APP" mkdir -p "$(dirname "$OUTPUT")" rm -f "$OUTPUT" echo "Creating $OUTPUT" +# ULMO (LZMA) is natively supported since macOS 10.15; Mornye targets 12.0+. hdiutil create \ -volname "$VOLUME_NAME" \ -srcfolder "$STAGE_DIR" \ -fs HFS+ \ - -format UDZO \ - -imagekey zlib-level=9 \ + -format ULMO \ -ov \ "$OUTPUT" >/dev/null hdiutil verify "$OUTPUT" >/dev/null @@ -123,7 +170,7 @@ for binary in "$MOUNTED_APP/Contents/MacOS/$EXECUTABLE" \ "$MOUNTED_APP/Contents/Frameworks/libmornye_desktop.dylib"; do [[ -f "$binary" ]] || continue # One architecture per call: some lipo builds reject several at once. - for arch in arm64 x86_64; do + for arch in "${VERIFY_ARCHS[@]}"; do if ! lipo "$binary" -verify_arch "$arch"; then echo "Error: $binary has no $arch slice." >&2 exit 1 diff --git a/scripts/package_windows.ps1 b/scripts/package_windows.ps1 index 3f568c7c0..6153bf36f 100644 --- a/scripts/package_windows.ps1 +++ b/scripts/package_windows.ps1 @@ -52,7 +52,22 @@ $baseName = "Mornye-$Version-windows-$Arch" if ($Only -in 'all', 'portable') { $zip = Join-Path $OutputDir "$baseName-portable.zip" if (Test-Path $zip) { Remove-Item $zip -Force } - Compress-Archive -Path (Join-Path $BundleDir '*') -DestinationPath $zip + $sevenZip = Get-Command '7z.exe', '7z' -ErrorAction SilentlyContinue | Select-Object -First 1 + if ($sevenZip) { + Push-Location $BundleDir + try { + & $sevenZip.Source a -tzip -mx=9 '-xr!*.pdb' '-xr!*.lib' '-xr!*.exp' '-xr!*.ilk' $zip '*' | Out-Null + if ($LASTEXITCODE -ne 0) { throw "7z failed with exit code $LASTEXITCODE" } + } + finally { + Pop-Location + } + } else { + $items = Get-ChildItem -LiteralPath $BundleDir | Where-Object { + $_.Extension -notin '.pdb', '.lib', '.exp', '.ilk' + } + Compress-Archive -Path $items.FullName -DestinationPath $zip -CompressionLevel Optimal + } Write-Host "Created $zip" } diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index e99592f83..895fc689d 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -37,6 +37,8 @@ function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_options(${TARGET} PRIVATE "$<$:/O1;/Gy;/Gw>") + target_link_options(${TARGET} PRIVATE "$<$:/OPT:REF;/OPT:ICF>") target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() @@ -148,6 +150,11 @@ set(MORNYE_FFMPEG_DIR if(EXISTS "${MORNYE_FFMPEG_DIR}/ffmpeg.exe" AND EXISTS "${MORNYE_FFMPEG_DIR}/ffprobe.exe") install(PROGRAMS "${MORNYE_FFMPEG_DIR}/ffmpeg.exe" "${MORNYE_FFMPEG_DIR}/ffprobe.exe" DESTINATION "${CMAKE_INSTALL_PREFIX}/ffmpeg" COMPONENT Runtime) + file(GLOB MORNYE_FFMPEG_DLLS "${MORNYE_FFMPEG_DIR}/*.dll") + if(MORNYE_FFMPEG_DLLS) + install(FILES ${MORNYE_FFMPEG_DLLS} + DESTINATION "${CMAKE_INSTALL_PREFIX}/ffmpeg" COMPONENT Runtime) + endif() install(FILES "${MORNYE_FFMPEG_DIR}/LICENSE.txt" "${MORNYE_FFMPEG_DIR}/SOURCE.txt" DESTINATION "${CMAKE_INSTALL_PREFIX}/ffmpeg" COMPONENT Runtime) else() @@ -169,7 +176,18 @@ install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" - DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime + PATTERN "packages/media_kit/assets/web/*" EXCLUDE + PATTERN "packages/record_web/*" EXCLUDE + PATTERN "packages/flutter_local_notifications_web/*" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/metaball_*" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/liquid_glass_border.frag" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/liquid_glass.frag" EXCLUDE + PATTERN "packages/liquid_glass_easy/lib/assets/shaders/liquid_glass_geometry.frag" EXCLUDE + PATTERN "assets/licenses/usb.txt" EXCLUDE + PATTERN "assets/licenses/oboe.txt" EXCLUDE + PATTERN "assets/licenses/wavpack.txt" EXCLUDE + PATTERN "assets/licenses/flac.txt" EXCLUDE) install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release diff --git a/windows/installer/mornye.iss b/windows/installer/mornye.iss index 09ef71511..573dd4c2e 100644 --- a/windows/installer/mornye.iss +++ b/windows/installer/mornye.iss @@ -72,7 +72,8 @@ SetupIconFile=..\runner\resources\app_icon.ico UninstallDisplayIcon={app}\{#AppExe} UninstallDisplayName={#AppName} WizardStyle=modern -Compression=lzma2/max +Compression=lzma2/ultra64 +LZMAUseSeparateProcess=yes SolidCompression=yes OutputDir={#OutputDir} OutputBaseFilename={#OutputBaseName} @@ -89,7 +90,7 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{ Type: filesandordirs; Name: "{app}\data" [Files] -Source: "{#BundleDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "{#BundleDir}\*"; DestDir: "{app}"; Excludes: "*.pdb,*.lib,*.exp,*.ilk"; Flags: ignoreversion recursesubdirs createallsubdirs [Icons] Name: "{autoprograms}\{#AppName}"; Filename: "{app}\{#AppExe}"; AppUserModelID: "{#AppUserModelId}"