diff --git a/.gitignore b/.gitignore index 4d40931..be6fc54 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /releases/ *.AppImage .directory +/dist diff --git a/Cargo.lock b/Cargo.lock index f639a6c..92dbb9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,7 +111,7 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "audiphi" -version = "0.2.0" +version = "0.2.1" dependencies = [ "base64 0.22.1", "dirs", diff --git a/Cargo.toml b/Cargo.toml index ee2c126..c8b57a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "audiphi" -version = "0.2.0" +version = "0.2.1" edition = "2021" description = "A Material 3 music downloader and quick player for any music service" license = "MIT" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e951cbf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Audiphi contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index ae4585a..d1a9d96 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,34 @@ proper tags, cover art and synced lyrics. This is the Rust port of the Python/Py - **Quick player** (libmpv) with a spectrum ring around the cover, wavy seek bar and click-to-seek lyrics. - **Colours** from Caelestia's scheme, your desktop accent, the album art, or a colour you pick. -## Requirements +## Install a release -`yt-dlp`, `ffmpeg`, `mpv` (libmpv) and, for YouTube, a JavaScript runtime (`deno` recommended). +Downloads are on the [Releases page](https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi/releases); check them against `SHA256SUMS-`. The Linux builds +are made on Arch Linux and need a recent glibc (the version is named in the packages and checked by the installer), +so they run on Arch and other up-to-date distributions; on older ones, build from source. + +- **Arch Linux:** `sudo pacman -U Audiphi--arch-x86_64.pkg.tar.zst` (package `audiphi-bin`; remove it with + `sudo pacman -R audiphi-bin`). `packaging/arch/PKGBUILD` builds the same package from the release. +- **Debian, Ubuntu and other apt systems:** `sudo apt install ./Audiphi--amd64.deb`. +- **Nix:** `nix profile install git+https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi` (this repo is a flake), or `callPackage ./packaging/nix { }`. +- **Any distribution:** unpack `Audiphi--Linux-x86_64.tar.gz` and run `sh install.sh` inside (your home, + `~/.local`, no root) or `sh install.sh --system` (`/usr/local`). `sh uninstall.sh` removes it; `--purge` also + deletes settings and data. `installer.sh` from this repo does the same next to a downloaded tar.gz or AppImage. +- **AppImage:** `chmod +x Audiphi--x86_64.AppImage` and run it. libmpv is bundled in it. +- **Windows (x64):** `Audiphi--Setup.exe` installs for your user only (no admin) with a Start menu entry + and an uninstaller; `Audiphi--Windows-portable.zip` runs from any folder. + +Audiphi needs `yt-dlp` and `ffmpeg` on the system (the packages pull them in) and, for YouTube, a JavaScript +runtime (`deno` recommended). On Windows, put `yt-dlp.exe` and `ffmpeg.exe` on `PATH` or next to `audiphi.exe`. + +## Build from source + +You need Rust and `mpv` (libmpv) to build. ```bash sudo pacman -S yt-dlp ffmpeg mpv deno # Arch ./install.sh # builds and installs to ~/.local +tools/package.sh # release files in dist/ (Linux and Windows) ``` `audiphi 'https://…'` fetches the link straight away. @@ -42,4 +63,4 @@ pages; `examples/probe.rs` exercises the engine from the command line Setting `AUDIPHI_SHOTS=/dir` (and `AUDIPHI_SHOT_URL=`) makes the app walk its tabs and save screenshots. Built on yt-dlp, ffmpeg, mpv, lofty and egui. Tags from Deezer, iTunes and MusicBrainz; lyrics from LRCLIB. -Bundled fonts: Material Symbols (Apache 2.0) and Rubik (SIL OFL 1.1), licenses in `assets/fonts/`. +Licence: MIT (`LICENSE`). Bundled fonts: Material Symbols (Apache 2.0) and Rubik (SIL OFL 1.1), licenses in `assets/fonts/`. diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..cfdec84 --- /dev/null +++ b/build.rs @@ -0,0 +1,32 @@ +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + windows_resource(); +} + +/// Windows: embed the icon and version resource into audiphi.exe (needs mingw's windres; skipped without it). +fn windows_resource() { + println!("cargo:rerun-if-changed=packaging/audiphi.ico"); + if std::env::var("CARGO_CFG_TARGET_OS").as_deref() != Ok("windows") { + return; + } + let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); + let ver = std::env::var("CARGO_PKG_VERSION").unwrap(); + let nums: Vec<&str> = ver.split('.').collect(); + let comma = format!("{},{},{},0", nums[0], nums.get(1).unwrap_or(&"0"), nums.get(2).unwrap_or(&"0")); + let ico = std::fs::canonicalize("packaging/audiphi.ico").unwrap().to_string_lossy().replace('\\', "/"); + let rc = format!( + "1 ICON \"{ico}\"\n\ + 1 VERSIONINFO\nFILEVERSION {comma}\nPRODUCTVERSION {comma}\nBEGIN\n BLOCK \"StringFileInfo\"\n BEGIN\n BLOCK \"040904b0\"\n BEGIN\n\ + \x20 VALUE \"ProductName\", \"Audiphi\"\n VALUE \"FileDescription\", \"Audiphi music downloader and player\"\n VALUE \"FileVersion\", \"{ver}\"\n VALUE \"ProductVersion\", \"{ver}\"\n VALUE \"OriginalFilename\", \"audiphi.exe\"\n\ + \x20 END\n END\n BLOCK \"VarFileInfo\"\n BEGIN\n VALUE \"Translation\", 0x0409, 1200\n END\nEND\n" + ); + let rc_path = out.join("audiphi.rc"); + std::fs::write(&rc_path, rc).unwrap(); + let obj = out.join("audiphi_res.o"); + let ok = std::process::Command::new("x86_64-w64-mingw32-windres").arg(&rc_path).arg(&obj).status().map(|s| s.success()).unwrap_or(false); + if ok { + println!("cargo:rustc-link-arg-bins={}", obj.display()); + } else { + println!("cargo:warning=windres not available: audiphi.exe has no icon/version resource"); + } +} diff --git a/docs/releases/0.2.1.md b/docs/releases/0.2.1.md new file mode 100644 index 0000000..41d4837 --- /dev/null +++ b/docs/releases/0.2.1.md @@ -0,0 +1,15 @@ +# Audiphi 0.2.1 + +First packaged release of the Rust Audiphi. + +- **New icon colour:** the icon is honey yellow instead of purple, so it stands apart from the other apps in a dock. +- **Packages:** Linux AppImage (libmpv bundled), tar.gz with an installer, Arch package `audiphi-bin`, Debian/Ubuntu + `.deb`, a Nix flake, and for Windows a per-user installer (no admin) and a portable zip with libmpv. +- Copy and paste work in text fields (clipboard support). +- Settings show the installed yt-dlp version. +- Faster mouse-wheel scrolling. +- Playing a song queues the library as it is currently sorted and filtered. +- Windows: yt-dlp and ffmpeg are found as `.exe` (on `PATH` or next to `audiphi.exe`), they no longer flash a + console window, and "open folder" and links open in Explorer and the browser. + +Needs `yt-dlp` and `ffmpeg` (the Linux packages pull them in); YouTube also needs a JavaScript runtime such as `deno`. diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..de84e59 --- /dev/null +++ b/flake.nix @@ -0,0 +1,10 @@ +{ + description = "Material 3 music downloader and quick player for any music service"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + outputs = { self, nixpkgs }: + let pkgs = nixpkgs.legacyPackages.x86_64-linux; + in { + packages.x86_64-linux.default = pkgs.callPackage ./packaging/nix { }; + apps.x86_64-linux.default = { type = "app"; program = "${self.packages.x86_64-linux.default}/bin/audiphi"; }; + }; +} diff --git a/installer.sh b/installer.sh new file mode 100755 index 0000000..395c7df --- /dev/null +++ b/installer.sh @@ -0,0 +1,158 @@ +#!/bin/sh +# Audiphi installer. Installs from a release tar.gz or AppImage, or removes an install. +# installer.sh [--user|--system] [--prefix DIR] [--url URL] [FILE] +# installer.sh --uninstall [--purge] [--user|--system] [--prefix DIR] +# --user (default): ~/.local, no root. --system: /usr/local, sudo only for the copy. +# Without FILE it uses the unpacked release folder it sits in, or Audiphi-*-Linux-x86_64.tar.gz or +# Audiphi-*-x86_64.AppImage next to it. SHA256SUMS- beside the file is checked when present. +# --purge also deletes settings and data (~/.config/audiphi, ~/.cache/audiphi: settings, library index). DESTDIR=dir stages under dir (no sudo). +# Needs glibc 2.35 or newer. +set -eu + +app=audiphi main=audiphi need=2.35 +mode=install scope=user purge=0 prefix= url= file= +while [ $# -gt 0 ]; do + case $1 in + --user) scope=user ;; + --system) scope=system ;; + --prefix) [ $# -ge 2 ] || { echo "--prefix needs a folder." >&2; exit 2; }; prefix=$2; shift ;; + --url) [ $# -ge 2 ] || { echo "--url needs an address." >&2; exit 2; }; url=$2; shift ;; + --uninstall) mode=uninstall ;; + --purge) purge=1 ;; + -h|--help) sed -n '2,9p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; + -*) echo "Unknown option: $1 (see --help)." >&2; exit 2 ;; + *) file=$1 ;; + esac + shift +done +[ "$purge" = 0 ] || [ "$mode" = uninstall ] || { echo "--purge only goes with --uninstall." >&2; exit 2; } +if [ -z "$prefix" ]; then + if [ "$scope" = system ]; then prefix=/usr/local; else prefix=$HOME/.local; fi +fi +case $prefix in /*) ;; *) echo "--prefix must be an absolute path." >&2; exit 2 ;; esac +prefix=${prefix%/} +destdir=${DESTDIR:-} +root=$destdir$prefix +list=$root/lib/$app/files +sudo= +if [ -z "$destdir" ] && [ "$(id -u)" != 0 ]; then + d=$root; while [ ! -e "$d" ]; do d=$(dirname "$d"); done + [ -w "$d" ] || sudo=sudo +fi + +refresh() { + [ -z "$destdir" ] || return 0 + command -v update-desktop-database >/dev/null 2>&1 && $sudo update-desktop-database -q "$root/share/applications" 2>/dev/null || true + [ -f "$root/share/icons/hicolor/index.theme" ] && command -v gtk-update-icon-cache >/dev/null 2>&1 \ + && $sudo gtk-update-icon-cache -q -t -f "$root/share/icons/hicolor" 2>/dev/null || true +} + +# Removes the files the last install listed, then the folders that became empty. +remove_listed() { + [ -f "$list" ] || return 0 + while IFS= read -r f; do + [ -n "$f" ] || continue + $sudo rm -f "$root/$f" + d=$(dirname "$f") + while [ "$d" != . ] && $sudo rmdir "$root/$d" 2>/dev/null; do d=$(dirname "$d"); done + done < "$list" + $sudo rm -f "$list" + $sudo rmdir "$root/lib/$app" "$root/lib" 2>/dev/null || true +} + +if [ "$mode" = uninstall ]; then + if [ ! -f "$list" ]; then + echo "Audiphi is not installed in $prefix (no $list)." >&2 + [ "$purge" = 1 ] || exit 1 + else + remove_listed + refresh + echo "Audiphi removed from $prefix." + fi + if [ "$purge" = 1 ]; then + rm -rf "${XDG_CONFIG_HOME:-$HOME/.config}/audiphi" + rm -rf "${XDG_CACHE_HOME:-$HOME/.cache}/audiphi" + echo "Settings and data removed (~/.config/audiphi, ~/.cache/audiphi: settings, library index)." + else + echo "Settings and data are kept (--purge deletes them)." + fi + exit 0 +fi + +# glibc check (AUDIPHI_GLIBC overrides the detected version, for tests) +have=${AUDIPHI_GLIBC:-$(getconf GNU_LIBC_VERSION 2>/dev/null | sed 's/^glibc //')} +if [ -z "$have" ]; then + echo "Audiphi needs glibc $need or newer, and this system does not report a glibc (musl?). Nothing was installed." >&2; exit 1 +fi +if [ "$(printf '%s\n%s\n' "$need" "$have" | sort -V | head -n 1)" != "$need" ]; then + echo "Audiphi needs glibc $need or newer, and this system has glibc $have. Nothing was installed." >&2; exit 1 +fi + +here=$(cd "$(dirname "$0")" && pwd) +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT INT TERM + +if [ -n "$url" ]; then + file=$tmp/$(basename "${url%%\?*}") + if command -v curl >/dev/null 2>&1; then curl -fL -o "$file" -- "$url" + elif command -v wget >/dev/null 2>&1; then wget -O "$file" -- "$url" + else echo "Neither curl nor wget is installed, so $url cannot be fetched." >&2; exit 1; fi +fi +src= +if [ -z "$file" ]; then + if [ -f "$here/bin/$main" ]; then src=$here + else + for f in "$here"/Audiphi-*-Linux-x86_64.tar.gz "$here"/Audiphi-*-x86_64.AppImage; do + [ -f "$f" ] && { file=$f; break; } + done + fi +fi +if [ -z "$src" ]; then + [ -n "$file" ] && [ -f "$file" ] || { echo "No Audiphi tar.gz or AppImage was given or found next to the installer." >&2; exit 1; } + dir=$(dirname "$file"); name=$(basename "$file") + for s in "$dir"/SHA256SUMS-*; do + [ -f "$s" ] || continue + line=$(grep -F " $name" "$s" | head -n 1 || true) + [ -n "$line" ] || continue + [ "${line%% *}" = "$(sha256sum "$file" | cut -d' ' -f1)" ] \ + || { echo "The checksum of $name does not match $(basename "$s"). Nothing was installed." >&2; exit 1; } + echo "Checksum ok." + done + mkdir "$tmp/x" + case $name in + *.tar.gz) + tar -xzf "$file" -C "$tmp/x" + src=$(find "$tmp/x" -maxdepth 1 -mindepth 1 -type d | head -n 1) + [ -n "$src" ] && [ -f "$src/bin/$main" ] || { echo "$name has no bin/$main, so it is not a Audiphi release." >&2; exit 1; } ;; + *.AppImage) + cp "$file" "$tmp/app"; chmod 755 "$tmp/app" + (cd "$tmp/x" && "$tmp/app" --appimage-extract >/dev/null 2>&1) || true + [ -d "$tmp/x/squashfs-root/usr/share" ] || { echo "Could not read the contents of $name. Nothing was installed." >&2; exit 1; } + src=$tmp/src; mkdir -p "$src/bin" + mv "$tmp/app" "$src/bin/$main" + mv "$tmp/x/squashfs-root/usr/share" "$src/share" + [ ! -d "$tmp/x/squashfs-root/usr/lib" ] || mv "$tmp/x/squashfs-root/usr/lib" "$src/lib" ;; + *) echo "Unknown file type: $name (need .tar.gz or .AppImage)." >&2; exit 1 ;; + esac +fi + +# Stage with launchers pointing at this prefix, then copy and list every file for --uninstall. +st=$tmp/stage +mkdir -p "$st" +for d in bin lib share; do [ ! -d "$src/$d" ] || cp -R "$src/$d" "$st/$d"; done +for d in "$st"/share/applications/*.desktop; do + [ -f "$d" ] || continue + for b in "$st"/bin/*; do + b=$(basename "$b") + sed -i -e "s#^Exec=$b\( \|\$\)#Exec=$prefix/bin/$b\1#" -e "s#^TryExec=$b\$#TryExec=$prefix/bin/$b#" "$d" + done +done +chmod 755 "$st"/bin/* +(cd "$st" && find . \( -type f -o -type l \) | sed 's|^\./||' | sort) > "$tmp/files" +mkdir -p "$st/lib/$app"; echo "lib/$app/files" >> "$tmp/files"; cp "$tmp/files" "$st/lib/$app/files" + +remove_listed +$sudo mkdir -p "$root" +$sudo cp -R "$st/." "$root/" +refresh +echo "Audiphi installed in $prefix/bin/$main" +case ":$PATH:" in *":$prefix/bin:"*) ;; *) echo "Note: $prefix/bin is not on your PATH." ;; esac diff --git a/packaging/arch/.SRCINFO b/packaging/arch/.SRCINFO new file mode 100644 index 0000000..47e35e1 --- /dev/null +++ b/packaging/arch/.SRCINFO @@ -0,0 +1,33 @@ +pkgbase = audiphi-bin + pkgdesc = Material 3 music downloader and quick player for any music service + pkgver = 0.2.1 + pkgrel = 1 + url = https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi + arch = x86_64 + license = MIT + depends = glibc>=2.35 + depends = gcc-libs + depends = mpv + depends = yt-dlp + depends = ffmpeg + depends = fontconfig + depends = libglvnd + depends = wayland + depends = libxkbcommon + depends = libxkbcommon-x11 + depends = libx11 + depends = libxcb + depends = libxcursor + depends = libxi + depends = libxrender + depends = hicolor-icon-theme + optdepends = deno: YouTube downloads (yt-dlp JavaScript challenges) + optdepends = xdg-desktop-portal: open and save dialogs + provides = audiphi + conflicts = audiphi + options = !strip + options = !debug + source = Audiphi-0.2.1-Linux-x86_64.tar.gz::https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi/releases/download/v0.2.1/Audiphi-0.2.1-Linux-x86_64.tar.gz + sha256sums = 47092173f702e950ff6c3098911f7a931b6a372fe05b0f1d9785c1296b44e815 + +pkgname = audiphi-bin diff --git a/packaging/arch/PKGBUILD b/packaging/arch/PKGBUILD new file mode 100644 index 0000000..a1345b8 --- /dev/null +++ b/packaging/arch/PKGBUILD @@ -0,0 +1,30 @@ +# Maintainer: astar76 +# Built by tools/package.sh from the release tar.gz (TARBALL=file://… for an offline build); it keeps pkgver, +# sha256sums and the glibc floor current. +pkgname=audiphi-bin +pkgver=0.2.1 +pkgrel=1 +pkgdesc='Material 3 music downloader and quick player for any music service' +arch=('x86_64') +url='https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi' +license=('MIT') +depends=('glibc>=2.35' 'gcc-libs' 'mpv' 'yt-dlp' 'ffmpeg' 'fontconfig' 'libglvnd' 'wayland' 'libxkbcommon' 'libxkbcommon-x11' 'libx11' 'libxcb' 'libxcursor' 'libxi' 'libxrender' 'hicolor-icon-theme') +optdepends=( + 'deno: YouTube downloads (yt-dlp JavaScript challenges)' + 'xdg-desktop-portal: open and save dialogs' +) +provides=('audiphi') +conflicts=('audiphi') +options=('!strip' '!debug') +source=("Audiphi-$pkgver-Linux-x86_64.tar.gz::${TARBALL:-$url/releases/download/v$pkgver/Audiphi-$pkgver-Linux-x86_64.tar.gz}") +sha256sums=('47092173f702e950ff6c3098911f7a931b6a372fe05b0f1d9785c1296b44e815') + +package() { + cd "$srcdir/audiphi-$pkgver" + install -d "$pkgdir/usr" + for d in bin lib share; do [ ! -d "$d" ] || cp -R "$d" "$pkgdir/usr/"; done + if [ -d "$pkgdir/usr/share/licenses/audiphi" ] && [ "$pkgname" != audiphi ]; then + mv "$pkgdir/usr/share/licenses/audiphi" "$pkgdir/usr/share/licenses/$pkgname" + fi + install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md" +} diff --git a/packaging/audiphi.ico b/packaging/audiphi.ico new file mode 100644 index 0000000..5ad72bb Binary files /dev/null and b/packaging/audiphi.ico differ diff --git a/packaging/audiphi.iss b/packaging/audiphi.iss new file mode 100644 index 0000000..e5e1a95 --- /dev/null +++ b/packaging/audiphi.iss @@ -0,0 +1,51 @@ +; Inno Setup script: per-user install (no admin), Start menu entry, uninstaller. +; Built by tools/package.sh under wine: iscc /DVersion= /DSrc= /DOut= audiphi.iss +#ifndef Version + #define Version "0.0.0" +#endif +#ifndef Src + #define Src "..\dist\Audiphi" +#endif +#ifndef Out + #define Out "..\dist" +#endif + +[Setup] +AppId={{CF109E85-B812-43ED-9575-73F404B7BABF} +AppName=Audiphi +AppVersion={#Version} +AppVerName=Audiphi {#Version} +AppPublisher=astar76 +AppPublisherURL=https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi +VersionInfoVersion={#Version} +VersionInfoProductName=Audiphi +VersionInfoDescription=Audiphi Setup +DefaultDirName={localappdata}\Programs\Audiphi +DisableProgramGroupPage=yes +DisableDirPage=auto +PrivilegesRequired=lowest +ArchitecturesAllowed=x64compatible +ArchitecturesInstallIn64BitMode=x64compatible +OutputDir={#Out} +OutputBaseFilename=Audiphi-{#Version}-Setup +SetupIconFile=audiphi.ico +UninstallDisplayIcon={app}\audiphi.exe +UninstallDisplayName=Audiphi +LicenseFile=..\LICENSE +Compression=lzma2/max +SolidCompression=yes +WizardStyle=modern +CloseApplications=yes + +[Tasks] +Name: "desktopicon"; Description: "Create a desktop shortcut"; Flags: unchecked + +[Files] +Source: "{#Src}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs + +[Icons] +Name: "{userprograms}\Audiphi"; Filename: "{app}\audiphi.exe" +Name: "{userdesktop}\Audiphi"; Filename: "{app}\audiphi.exe"; Tasks: desktopicon + +[Run] +Filename: "{app}\audiphi.exe"; Description: "Launch Audiphi"; Flags: nowait postinstall skipifsilent diff --git a/packaging/nix/default.nix b/packaging/nix/default.nix new file mode 100644 index 0000000..8d6d10f --- /dev/null +++ b/packaging/nix/default.nix @@ -0,0 +1,33 @@ +# Audiphi for Nix, from the release tar.gz. Written by tools/package.sh (version and hash); edit the header there. +# nix build .#default or nix profile install . (from the repo), or callPackage this file. +{ lib, stdenv, fetchurl, autoPatchelfHook, makeWrapper, libGL, wayland, libxkbcommon, xorg, fontconfig, dbus, mpv-unwrapped, yt-dlp, ffmpeg }: + +stdenv.mkDerivation rec { + pname = "audiphi"; + version = "0.2.1"; + src = fetchurl { + url = "https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi/releases/download/v${version}/Audiphi-${version}-Linux-x86_64.tar.gz"; + hash = "sha256-Rwkhc/cC6VD/bDCYkR96kxtqNy/gWw8dl4XBKWtE6BU="; + }; + nativeBuildInputs = [ autoPatchelfHook makeWrapper ]; + buildInputs = [ mpv-unwrapped stdenv.cc.cc.lib ]; + # Loaded with dlopen at run time, so autoPatchelf can't see them. + runtimeDependencies = [ libGL wayland libxkbcommon xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr fontconfig dbus ]; + dontBuild = true; + installPhase = '' + runHook preInstall + mkdir -p $out + for d in bin lib share; do [ ! -d $d ] || cp -R $d $out/; done + install -Dm644 README.md $out/share/doc/audiphi/README.md + runHook postInstall + ''; + postFixup = "wrapProgram $out/bin/audiphi --prefix PATH : ${lib.makeBinPath [ yt-dlp ffmpeg ]}"; + meta = { + description = "Material 3 music downloader and quick player for any music service"; + homepage = "https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi"; + license = lib.licenses.mit; + platforms = [ "x86_64-linux" ]; + mainProgram = "audiphi"; + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; + }; +} diff --git a/src/app.rs b/src/app.rs index 958976e..4ec2461 100644 --- a/src/app.rs +++ b/src/app.rs @@ -523,10 +523,10 @@ impl App { fn draw_banners(&mut self, ui: &mut egui::Ui) { let mut msgs = vec![]; if !self.ffmpeg_ok { - msgs.push("ffmpeg wasn't found. Downloads need it to convert audio — install it (e.g. “sudo pacman -S ffmpeg”) or set its location in Settings."); + msgs.push(if cfg!(windows) { "ffmpeg wasn't found. Downloads need it to convert audio — put ffmpeg.exe next to audiphi.exe or on PATH, or set its location in Settings." } else { "ffmpeg wasn't found. Downloads need it to convert audio — install it (e.g. “sudo pacman -S ffmpeg”) or set its location in Settings." }); } if !self.ytdlp_ok { - msgs.push("yt-dlp wasn't found. Install it (e.g. “sudo pacman -S yt-dlp”) so Audiphi can download."); + msgs.push(if cfg!(windows) { "yt-dlp wasn't found. Put yt-dlp.exe next to audiphi.exe or on PATH so Audiphi can download." } else { "yt-dlp wasn't found. Install it (e.g. “sudo pacman -S yt-dlp”) so Audiphi can download." }); } for m in msgs { let t = self.g.theme.clone(); diff --git a/src/core/downloader.rs b/src/core/downloader.rs index ba42160..0981c94 100644 --- a/src/core/downloader.rs +++ b/src/core/downloader.rs @@ -663,7 +663,7 @@ fn encode(ctx: &Ctx, src: &Path, duration: Option, o: &DownloadOptions, tmp ctx.update(Some(JobState::Converting), Some(&base), true); let ext = format_ext(&o.format).unwrap_or("mp3"); let dst = tmp_dir.join(format!("{uid}.out.{ext}")); - let mut cmd = Command::new(ffmpeg); + let mut cmd = crate::core::paths::command(ffmpeg); cmd.args(["-hide_banner", "-nostdin", "-y", "-loglevel", "error", "-progress", "pipe:1", "-i"]).arg(src).args(encode_args(o)).arg(&dst).stdout(Stdio::piped()).stderr(Stdio::piped()); let mut child = cmd.spawn().map_err(|e| format!("couldn't start ffmpeg: {e}"))?; let stdout = child.stdout.take().unwrap(); diff --git a/src/core/paths.rs b/src/core/paths.rs index 0bec36f..83fa14f 100644 --- a/src/core/paths.rs +++ b/src/core/paths.rs @@ -19,16 +19,21 @@ pub fn music_dir() -> PathBuf { dirs::audio_dir().unwrap_or_else(|| dirs::home_dir().unwrap_or_default().join("Music")) } +/// `name` as a program file name here: `yt-dlp` on Linux, `yt-dlp.exe` on Windows. +fn exe(name: &str) -> String { + format!("{name}{}", std::env::consts::EXE_SUFFIX) +} + pub fn which(name: &str) -> Option { let path = std::env::var_os("PATH")?; - std::env::split_paths(&path).map(|d| d.join(name)).find(|p| p.is_file()) + std::env::split_paths(&path).map(|d| d.join(exe(name))).find(|p| p.is_file()) } pub fn find_ffmpeg(configured: &str) -> Option { if !configured.is_empty() { let mut p = PathBuf::from(shellexpand(configured)); if p.is_dir() { - p = p.join("ffmpeg"); + p = p.join(exe("ffmpeg")); } if p.is_file() { return Some(p.to_string_lossy().into_owned()); @@ -37,13 +42,13 @@ pub fn find_ffmpeg(configured: &str) -> Option { if let Some(p) = which("ffmpeg") { return Some(p.to_string_lossy().into_owned()); } - let local = std::env::current_exe().ok()?.parent()?.join("ffmpeg"); + let local = std::env::current_exe().ok()?.parent()?.join(exe("ffmpeg")); local.is_file().then(|| local.to_string_lossy().into_owned()) } pub fn find_ytdlp() -> Option { - if let Ok(exe) = std::env::current_exe() { - if let Some(p) = exe.parent().map(|d| d.join("yt-dlp")).filter(|p| p.is_file()) { + if let Ok(me) = std::env::current_exe() { + if let Some(p) = me.parent().map(|d| d.join(exe("yt-dlp"))).filter(|p| p.is_file()) { return Some(p.to_string_lossy().into_owned()); } } @@ -75,3 +80,22 @@ pub const AUDIO_EXTENSIONS: &[&str] = &["mp3", "m4a", "flac", "opus", "ogg", "og pub fn is_audio(p: &Path) -> bool { p.extension().map(|e| AUDIO_EXTENSIONS.contains(&e.to_string_lossy().to_lowercase().as_str())).unwrap_or(false) } + +/// Opens a folder, file or web address with the desktop's default handler (Explorer on Windows). +pub fn open(target: impl AsRef) { + let opener = if cfg!(windows) { "explorer" } else { "xdg-open" }; + let _ = std::process::Command::new(opener).arg(target).spawn(); +} + +/// A command for a console tool (yt-dlp, ffmpeg) that opens no console window on Windows. +pub fn command(program: impl AsRef) -> std::process::Command { + #[allow(unused_mut)] + let mut cmd = std::process::Command::new(program); + #[cfg(windows)] + { + use std::os::windows::process::CommandExt; + const CREATE_NO_WINDOW: u32 = 0x0800_0000; + cmd.creation_flags(CREATE_NO_WINDOW); + } + cmd +} diff --git a/src/core/ytdlp.rs b/src/core/ytdlp.rs index 68e6841..f37e7e8 100644 --- a/src/core/ytdlp.rs +++ b/src/core/ytdlp.rs @@ -10,11 +10,11 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; pub fn binary() -> Res { - paths::find_ytdlp().ok_or_else(|| "yt-dlp wasn't found. Install it (e.g. “sudo pacman -S yt-dlp”) and make sure it is on your PATH.".to_string()) + paths::find_ytdlp().ok_or_else(|| if cfg!(windows) { "yt-dlp wasn't found. Put yt-dlp.exe next to audiphi.exe or on PATH." } else { "yt-dlp wasn't found. Install it (e.g. “sudo pacman -S yt-dlp”) and make sure it is on your PATH." }.to_string()) } pub fn version() -> Option { - let out = Command::new(paths::find_ytdlp()?).arg("--version").output().ok()?; + let out = paths::command(paths::find_ytdlp()?).arg("--version").output().ok()?; Some(String::from_utf8_lossy(&out.stdout).trim().to_string()) } @@ -47,7 +47,7 @@ pub struct Outcome { /// Run yt-dlp, feeding each stdout line to `on_line` and stderr to the log. pub fn run(args: &[String], cancel: Option<&Arc>, log: Log, mut on_line: impl FnMut(&str)) -> Res { - let mut cmd = Command::new(binary()?); + let mut cmd = paths::command(binary()?); cmd.args(args).stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()); let mut child = cmd.spawn().map_err(|e| format!("couldn't start yt-dlp: {e}"))?; let stdout = child.stdout.take().unwrap(); diff --git a/src/main.rs b/src/main.rs index 6990916..5ca1ccf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![cfg_attr(all(windows, not(debug_assertions)), windows_subsystem = "windows")] use audiphi::app::App; use eframe::egui; diff --git a/src/player.rs b/src/player.rs index 880a7e6..d06d346 100644 --- a/src/player.rs +++ b/src/player.rs @@ -31,7 +31,7 @@ impl Spectrum { let (path, ctx) = (path.to_string(), ctx.clone()); std::thread::spawn(move || { let ffmpeg = crate::core::paths::find_ffmpeg("").unwrap_or_else(|| "ffmpeg".into()); - let Ok(mut child) = Command::new(ffmpeg).args(["-v", "error", "-nostdin", "-i", &path, "-vn", "-ac", "1", "-ar", &SR.to_string(), "-f", "f32le", "-"]).stdout(Stdio::piped()).stderr(Stdio::null()).spawn() else { return }; + let Ok(mut child) = crate::core::paths::command(ffmpeg).args(["-v", "error", "-nostdin", "-i", &path, "-vn", "-ac", "1", "-ar", &SR.to_string(), "-f", "f32le", "-"]).stdout(Stdio::piped()).stderr(Stdio::null()).spawn() else { return }; let mut out = child.stdout.take().unwrap(); let mut buf = vec![0u8; 1 << 16]; let mut carry: Vec = vec![]; diff --git a/src/ui/pages/download.rs b/src/ui/pages/download.rs index 62fda3a..f4cd1f8 100644 --- a/src/ui/pages/download.rs +++ b/src/ui/pages/download.rs @@ -561,7 +561,7 @@ fn options_card(app: &mut App, ui: &mut Ui) { } } Some(_) => { - let _ = std::process::Command::new("xdg-open").arg(&app.dl.folder).spawn(); + crate::core::paths::open(&app.dl.folder); } None => {} } diff --git a/src/ui/pages/player_page.rs b/src/ui/pages/player_page.rs index 235436f..113edb1 100644 --- a/src/ui/pages/player_page.rs +++ b/src/ui/pages/player_page.rs @@ -453,7 +453,7 @@ fn library(app: &mut App, ui: &mut Ui) { Some(A::Lyrics(p)) => find_lyrics(app, &p), Some(A::Folder(p)) => { let dir = std::path::Path::new(&p).parent().map(|d| d.to_string_lossy().into_owned()).unwrap_or(p); - let _ = std::process::Command::new("xdg-open").arg(dir).spawn(); + crate::core::paths::open(dir); } None => {} } diff --git a/src/ui/pages/queue.rs b/src/ui/pages/queue.rs index 5eb9ad6..4f0f32e 100644 --- a/src/ui/pages/queue.rs +++ b/src/ui/pages/queue.rs @@ -81,7 +81,7 @@ pub fn draw(app: &mut App, ui: &mut Ui) { Act::Edit(p) => app.edit_file(&p), Act::Open(p) => { let dir = std::path::Path::new(&p).parent().map(|d| d.to_string_lossy().into_owned()).unwrap_or(p); - let _ = std::process::Command::new("xdg-open").arg(dir).spawn(); + crate::core::paths::open(dir); } } } diff --git a/src/ui/pages/settings_page.rs b/src/ui/pages/settings_page.rs index 68299dd..1e1cbaa 100644 --- a/src/ui/pages/settings_page.rs +++ b/src/ui/pages/settings_page.rs @@ -308,7 +308,7 @@ fn advanced(app: &mut App, ui: &mut Ui) { app.spawn( || { let Some(bin) = paths::find_ytdlp() else { return "yt-dlp wasn't found".to_string() }; - match std::process::Command::new(bin).arg("-U").output() { + match crate::core::paths::command(bin).arg("-U").output() { Ok(o) => { let txt = format!("{}{}", String::from_utf8_lossy(&o.stdout), String::from_utf8_lossy(&o.stderr)); let line = txt.lines().rev().find(|l| !l.trim().is_empty()).unwrap_or("").trim().to_string(); @@ -352,7 +352,7 @@ fn about(app: &mut App, ui: &mut Ui) { ui.label(RichText::new("Built on yt-dlp and ffmpeg. Tags from Deezer, iTunes and MusicBrainz; lyrics from LRCLIB. The player follows the look of Caelestia's media panel. Bundled fonts: Material Symbols (Apache 2.0) and Rubik (SIL OFL 1.1).").size(13.0).color(t.on_surface_variant)); ui.horizontal(|ui| { if button_h(ui, &mut app.g, Some("open_in_new"), "Project page", Kind::Text, 34.0).clicked() { - let _ = std::process::Command::new("xdg-open").arg(crate::HOMEPAGE).spawn(); + crate::core::paths::open(crate::HOMEPAGE); } }); let _ = (Align2::CENTER_CENTER, Id::NULL); diff --git a/tools/package.sh b/tools/package.sh new file mode 100755 index 0000000..ef8def2 --- /dev/null +++ b/tools/package.sh @@ -0,0 +1,226 @@ +#!/bin/bash +# Audiphi release packages. Run: tools/package.sh (see the common part below for what it makes) +set -euo pipefail +root=$(cd "$(dirname "$0")/.." && pwd) +APP=audiphi NAME=Audiphi DESKTOP=audiphi.desktop +URL=https://archlinux.tail7c4f5e.ts.net/git/astar76/Audiphi +ver=$(sed -n 's/^version = "\(.*\)"/\1/p' "$root/Cargo.toml" | head -n 1) +BINS=(audiphi) +LICENSE=MIT NIX_LICENSE=mit SUMMARY='Material 3 music downloader and quick player for any music service' +DEB_DEPENDS='libgl1, libegl1, libwayland-client0, libwayland-egl1, libxkbcommon0, libxkbcommon-x11-0, libx11-6, libxcursor1, libxi6, libxrandr2, libfontconfig1, libdbus-1-3, libmpv2, yt-dlp, ffmpeg' DEB_RECOMMENDS='xdg-desktop-portal' DEB_SECTION=sound +NIX_ARGS='libGL, wayland, libxkbcommon, xorg, fontconfig, dbus, mpv-unwrapped, yt-dlp, ffmpeg' NIX_RUNTIME='libGL wayland libxkbcommon xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr fontconfig dbus' NIX_BUILD_INPUTS='mpv-unwrapped stdenv.cc.cc.lib' +NIX_EXTRA=' postFixup = "wrapProgram $out/bin/audiphi --prefix PATH : ${lib.makeBinPath [ yt-dlp ffmpeg ]}";' +WIN=1 WIN_MPV=1 WIN_DLLS=(libmpv-2.dll) BUNDLE_LIBS=1 +ZIG_GLIBC=2.35 +build() { RUSTFLAGS="-L $tools/linuxlib -C link-arg=-Wl,--allow-shlib-undefined" nice cargo zigbuild --release --locked -q -j 2 --target x86_64-unknown-linux-gnu.$ZIG_GLIBC; } +stage() { + install -Dm644 packaging/audiphi.desktop "$1/applications/audiphi.desktop" + icon_pngs assets/audiphi.svg "$1" audiphi + install -Dm644 -t "$1/licenses/audiphi" LICENSE assets/fonts/LICENSE-MaterialSymbols.txt assets/fonts/LICENSE-Rubik-OFL.txt +} + +# ---------------------------------------------------------------- common part (same in every project) +# Builds into dist/ (and never writes to releases/): +# $NAME--Linux-x86_64.tar.gz bin/ share/ [lib/] laid out like a prefix, with install.sh and uninstall.sh +# $NAME--x86_64.AppImage GUI apps (DESKTOP set); BUNDLE_LIBS=1 adds the non-desktop library closure +# $NAME--arch-x86_64.pkg.tar.zst makepkg from that tar.gz, offline ($PKGDIR/PKGBUILD gets version and checksum) +# $NAME--amd64.deb the same tree under /usr, for apt +# $NAME--Setup.exe and $NAME--Windows-portable.zip when WIN=1 (mingw cross build, Inno Setup in wine) +# SHA256SUMS- +# It also writes packaging/nix/default.nix (fetches the release tar.gz; version and hash filled in here) and the +# glibc floor read from the binary into installer.sh, the PKGBUILD and the .deb. Nothing is downloaded: appimagetool +# and libmpv-2.dll come from ~/.local/opt/build-tools. +# SKIP_BUILD=1 packages the existing build, NO_WIN=1 skips Windows. CARGO_TARGET_DIR is honoured. +cd "$root"; PKGDIR=${PKGDIR:-packaging/arch} +tools=${BUILD_TOOLS:-$HOME/.local/opt/build-tools} +[ "${SKIP_BUILD:-}" = 1 ] || build +tdir=${CARGO_TARGET_DIR:-$root/target} +rel=$tdir/release +# ZIG_GLIBC: built with cargo-zigbuild against that glibc, so the binary runs on older distributions too. +[ -z "${ZIG_GLIBC:-}" ] || rel=$tdir/x86_64-unknown-linux-gnu/release +out=$root/dist +mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}"; work=$(mktemp -d "${XDG_CACHE_HOME:-$HOME/.cache}/package.XXXXXX"); trap 'rm -rf "$work"' EXIT +export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(git log -1 --format=%ct 2>/dev/null || date +%s)} + +# hicolor PNGs from an SVG: icon_pngs +icon_pngs() { + install -Dm644 "$1" "$2/icons/hicolor/scalable/apps/$3.svg" + for n in 16 24 32 48 64 128 256 512; do + mkdir -p "$2/icons/hicolor/${n}x$n/apps"; rsvg-convert -w "$n" -h "$n" "$1" -o "$2/icons/hicolor/${n}x$n/apps/$3.png" + done +} + +# glibc floor: the newest GLIBC_x.y symbol version any shipped binary (or EXTRA_ELF library) needs. +glibc=$(for b in "${BINS[@]}" ${EXTRA_ELF[@]+"${EXTRA_ELF[@]}"}; do objdump -T "$rel/$b"; done | grep -o 'GLIBC_[0-9.]*' | sed 's/GLIBC_//' | sort -uV | tail -n 1) +[ -n "$glibc" ] || { echo "could not read the glibc version from the binary" >&2; exit 1; } +sed -i "s/^app=$APP main=\([^ ]*\) need=.*/app=$APP main=\1 need=$glibc/; s/glibc [0-9.]* or newer\./glibc $glibc or newer./" installer.sh +sed -i "s/'glibc>=[0-9.]*'/'glibc>=$glibc'/" $PKGDIR/PKGBUILD + +# tar.gz: bin/ and share/ laid out like a prefix, so installer.sh, the PKGBUILD, the .deb and Nix just copy them. +rm -rf "$out"; mkdir -p "$out" +t=$work/$APP-$ver +mkdir -p "$t/bin" "$t/share" # stage may add $t/lib too +for b in "${BINS[@]}"; do install -m755 "$rel/$b" "$t/bin/$b"; done +stage "$t/share" +install -m755 installer.sh "$t/install.sh" +printf '#!/bin/sh\n# Removes %s installed by install.sh. --purge also deletes settings and data; --system or --prefix DIR as for install.sh.\nexec sh "$(dirname "$0")/install.sh" --uninstall "$@"\n' "$NAME" > "$t/uninstall.sh" +chmod 755 "$t/uninstall.sh" +cp README.md "$t/" +find "$t" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + +tgz=$NAME-$ver-Linux-x86_64.tar.gz +tar -C "$work" --sort=name --owner=0 --group=0 --numeric-owner -cf - "$APP-$ver" | gzip -n -9 > "$out/$tgz" + +# AppImage (GUI apps): the same tree under usr/, desktop file and icon at the top. +if [ -n "${DESKTOP:-}" ]; then + a=$work/AppDir + mkdir -p "$a/usr" + cp -R "$t/bin" "$t/share" "$a/usr/"; [ ! -d "$t/lib" ] || cp -R "$t/lib" "$a/usr/" + if [ "${BUNDLE_LIBS:-0}" = 1 ]; then + # Libraries every desktop already has (glibc, graphics, windowing, sound servers, fonts) stay with the host. + skip='^(linux-vdso|ld-linux|libc|libm|libdl|libpthread|librt|libutil|libresolv|libnsl|libgcc_s|libstdc\+\+|libGL|libGLX|libGLdispatch|libEGL|libOpenGL|libGLESv2|libgbm|libdrm|libvulkan|libX11|libX11-xcb|libxcb.*|libXau|libXdmcp|libXext|libXfixes|libXrandr|libXrender|libXi|libXcursor|libXss|libXv|libXxf86vm|libXinerama|libwayland-.*|libxkbcommon.*|libfontconfig|libfreetype|libharfbuzz|libglib-2.0|libgobject-2.0|libgio-2.0|libgmodule-2.0|libdbus-1|libsystemd|libudev|libasound|libpulse.*|libpipewire-0.3|libjack|libsndio|libcap|libselinux|libpcre2-8|libffi|libz|libexpat|libnss.*)\.so' + mkdir -p "$a/usr/lib" + ldd "$rel/${BINS[0]}" | awk '/=> \//{print $3} $1 ~ /^\// {print $1}' | while read -r lib; do + name=$(basename "$lib"); [[ $name =~ $skip ]] || cp -L "$lib" "$a/usr/lib/$name" + done + fi + cp "$a/usr/share/applications/$DESKTOP" "$a/" + icon=$(sed -n 's/^Icon=//p' "$a/$DESKTOP" | head -n 1) + for ext in svg png; do + f=$(find "$a/usr/share/icons" -name "$icon.$ext" | sort -V | tail -n 1) + [ -n "$f" ] && { cp "$f" "$a/$icon.$ext"; break; } + done + cat > "$a/AppRun" </dev/null) + ARCH=x86_64 "$work/squashfs-root/AppRun" --no-appstream "$a" "$out/$NAME-$ver-x86_64.AppImage" >"$work/ait.log" 2>&1 \ + || { tail -20 "$work/ait.log"; exit 1; } +fi + +# Arch package from the local tar.gz; the repo's PKGBUILD gets this version and checksum. +sum=$(sha256sum "$out/$tgz" | cut -d' ' -f1) +sed -i "s/^pkgver=.*/pkgver=$ver/; s/^sha256sums=.*/sha256sums=('$sum')/" $PKGDIR/PKGBUILD +mkdir "$work/arch"; cp $PKGDIR/PKGBUILD "$work/arch/" +(cd "$work/arch" && makepkg --printsrcinfo > "$root/$PKGDIR/.SRCINFO") +(cd "$work/arch" && TARBALL="file://$out/$tgz" makepkg -f -C --nodeps --noconfirm >"$work/makepkg.log" 2>&1) \ + || { tail -20 "$work/makepkg.log"; exit 1; } +cp "$work"/arch/"$APP"-bin-"$ver"-*-x86_64.pkg.tar.zst "$out/$NAME-$ver-arch-x86_64.pkg.tar.zst" + +# .deb: the tar.gz tree under /usr (licenses go to /usr/share/doc// as Debian expects). +d=$work/deb +mkdir -p "$d/root/usr" "$d/root/usr/share/doc/$APP" "$d/control" +for x in bin lib share; do [ ! -d "$t/$x" ] || cp -R "$t/$x" "$d/root/usr/"; done +if [ -d "$d/root/usr/share/licenses/$APP" ]; then + cp -R "$d/root/usr/share/licenses/$APP/." "$d/root/usr/share/doc/$APP/"; rm -rf "$d/root/usr/share/licenses" +fi +cp README.md "$d/root/usr/share/doc/$APP/" +{ echo "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/"; echo "Upstream-Name: $NAME" + echo "Source: $URL"; echo; echo "Files: *"; echo "License: $LICENSE"; } > "$d/root/usr/share/doc/$APP/copyright" +size=$(du -sk "$d/root" | cut -f1) +cat > "$d/control/control" < +Installed-Size: $size +Depends: libc6 (>= $glibc)${DEB_DEPENDS:+, $DEB_DEPENDS} +${DEB_RECOMMENDS:+Recommends: $DEB_RECOMMENDS +}Section: ${DEB_SECTION:-misc} +Priority: optional +Homepage: $URL +Description: $SUMMARY + Built from $URL (version $ver). Needs glibc $glibc or newer. +CTL +(cd "$d/root" && find . -type f -printf '%P\n' | sort | xargs -d '\n' md5sum) > "$d/control/md5sums" +find "$d/root" "$d/control" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + +echo 2.0 > "$d/debian-binary" +tar -C "$d/control" --sort=name --owner=0 --group=0 --numeric-owner -czf "$d/control.tar.gz" . +tar -C "$d/root" --sort=name --owner=0 --group=0 --numeric-owner -cJf "$d/data.tar.xz" . +deb=$out/$NAME-$ver-amd64.deb +(cd "$d" && ar rcD "$deb" debian-binary control.tar.gz data.tar.xz) +! command -v dpkg-deb >/dev/null || dpkg-deb --info "$deb" >/dev/null + +# Nix: packaging/nix/default.nix fetches this release's tar.gz (flake.nix at the top calls it). +mkdir -p packaging/nix +sri=sha256-$(openssl dgst -sha256 -binary "$out/$tgz" | base64 -w0) +cat > packaging/nix/default.nix < flake.nix </dev/null || { echo "Windows needs mingw-w64-gcc (sudo pacman -S mingw-w64-gcc), or NO_WIN=1." >&2; exit 1; } + if [ -n "${WIN_DLLS[*]:-}" ] && [ "${WIN_MPV:-0}" = 1 ]; then + # import library for libmpv-2.dll, so the cross linker can link "mpv" + lib=$tools/winlib; mkdir -p "$lib" + if [ ! -f "$lib/libmpv.dll.a" ]; then + { echo "LIBRARY libmpv-2.dll"; echo EXPORTS + x86_64-w64-mingw32-objdump -p "$tools/libmpv-2.dll" | sed -n '/\[Ordinal\/Name Pointer\] Table/,/^$/p' | awk '/^\s*\[ *[0-9]+\] \+base/ {print $NF}'; } > "$lib/mpv.def" + x86_64-w64-mingw32-dlltool -d "$lib/mpv.def" -D libmpv-2.dll -l "$lib/libmpv.dll.a" + fi + export RUSTFLAGS="${RUSTFLAGS:-} -L $lib" + fi + [ "${SKIP_BUILD:-}" = 1 ] || nice cargo build --release --locked -q -j 2 --target x86_64-pc-windows-gnu + w=$work/win/$NAME; mkdir -p "$w" + for b in "${BINS[@]}"; do install -m755 "$tdir/x86_64-pc-windows-gnu/release/$b.exe" "$w/"; done + for f in ${WIN_DLLS[@]+"${WIN_DLLS[@]}"}; do install -m644 "$tools/$f" "$w/"; done + install -m644 LICENSE "$w/LICENSE.txt" + find "$work/win" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} + + (cd "$work/win" && zip -qrX9 "$out/$NAME-$ver-Windows-portable.zip" "$NAME") + iscc="$HOME/.wine/drive_c/users/$USER/AppData/Local/Programs/Inno Setup 7/ISCC.exe" + WINEDEBUG=-all wine "$iscc" /Q "/DVersion=$ver" "/DSrc=Z:$w" "/DOut=Z:$out" "Z:$root/packaging/$APP.iss" >"$work/iscc.log" 2>&1 \ + || { tail -20 "$work/iscc.log"; exit 1; } +fi + +(cd "$out" && sha256sum "$NAME-$ver"-* > "SHA256SUMS-$ver") +echo "glibc floor: $glibc" +ls -l "$out"