Skip to content

Commit

Permalink
Fix up macOS and Windows builds (#1352)
Browse files Browse the repository at this point in the history
* Convert phazor to tabs, fix indents, add indents for ifdefs, add mingw ifdef

* Fix typo

* Fix opencc optdep

* run.sh: Don't install _optional.txt, it's already included

* myspac.txt: Add mingw-w64-x86_64-rust for pydantic source builds

* Indent couple missed ifdefs

* Try adding /mingw64/include/

* Pillow is needed on all platforms

* Move requirements for specific OSs and opts to extra as requirements.txt is now universal with all opts

* macOS CI: Use develop pyinstaller as the fix is now in master

* run.sh: Check python silently and in a function

* run.sh: Fix up script path for Windows build and remove Rsvg typelib hardcoded import as it was fixed upstream

* run.sh: Fix building Pillow on MINGW

* Phazor: Add .pyd for Windows DLLs and cleanup pyproject.toml comments

* Phazor: Fix dosctring

* Fix more docstrings

* Touch up error text

* Use is_file()

* phazor.c: Add missing space

* phazor.c: Format code better

* run.sh: Better note

* pyproject.toml: Fix broken opus include on Windows

* Init windows.spec

* windows.spec: Fix phazor

* windows.spec: Fix icons

* windows.spec: Stop copying lib dir and add note about Defender

* windows.spec: Make librespot optional in run.sh

* windows.spec: Add --noconfirm to pyinstaller

* windows.spec: Name TauonMusicBox

* windows.spec: Set scriptname and nicer file copying

* windows.spec: Yeet scriptname

* windows.spec: Small touchup

* main: add spaces to the correct place in the string

* Add (optimistic) changelog entry to not have to fix it later again

* phazor.c: Leave Python.h stuff only for MSVC

* Revert ifdefing python.h and migrate to WIN64 and __MINGW64__ ifdefs

* main: Do not attempt to load nonexistent file

* Fix Path function name

* test phazor EXPORTs

* phazor: Mark functions explicitly exported for Windows

* Fix up linebreaks

* scan_devices is supposed to be exported

* run.sh: Remove redundant comment

* Note portable installation directory change in changelog

* changelog: Remove newline that made the bulletpoints space more than wanted
  • Loading branch information
C0rn3j authored Dec 21, 2024
1 parent 51854aa commit 1c1939c
Show file tree
Hide file tree
Showing 15 changed files with 2,454 additions and 2,407 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_macOS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
pip install \
-r requirements.txt \
build
# Hack until https://github.com/pyinstaller/pyinstaller/issues/8936 is resolved
pip install https://github.com/rokm/pyinstaller/archive/refs/heads/macos-nested-framework-bundles.zip
# Hack until pyinstaller has a release newer than 6.11.1 - https://github.com/pyinstaller/pyinstaller/releases
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
# \
# pyinstaller
# pip uninstall pyinstaller
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
### v7.9.0

- **Added** TIDAL support
- **Added** macOS (experimental) and Linux automated CI builds
- **Changed** portable installations now save `cache` and `user-data` directiories in `src/tauon/`, move existing directories there if necessary
- **Fixed** Windows support
- **Fixed** crashes related to PipeWire [#1250](https://github.com/Taiko2k/Tauon/issues/1250)
- **Fixed** audio cutting out on the PipeWire backend with specific custom quantum settings [#1245](https://github.com/Taiko2k/Tauon/issues/1245)
- **Fixed** wrong encoding used for some tags in XSPF exports [#1331](https://github.com/Taiko2k/Tauon/issues/1331)
Expand All @@ -17,7 +20,6 @@ Changelog
- **Improved** Various changes to build system, Migrated to pyproject.toml
- ***Removed*** guitar chords feature - api.guitarchords.com it partially relied on is dead, replaced by newer API that would need implementing, and the chords feature was unmaintained
- ***Removed*** Spotify recommendations feature (API deprecated by Spotify)

- Many other bug fixes and code refactors [Special thanks to @C0rn3j for a lot of these]

### v7.8.3
Expand Down
9 changes: 5 additions & 4 deletions extra/msyspac.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
mingw-w64-x86_64-SDL2
mingw-w64-x86_64-SDL2_image
mingw-w64-x86_64-flac
mingw-w64-x86_64-gcc
mingw-w64-x86_64-gtk3
mingw-w64-x86_64-libgme
mingw-w64-x86_64-libopenmpt
mingw-w64-x86_64-libsamplerate
mingw-w64-x86_64-opusfile
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-wavpack
mingw-w64-x86_64-python3
mingw-w64-x86_64-python3-gobject
mingw-w64-x86_64-python3-pillow
mingw-w64-x86_64-python3-pip
mingw-w64-x86_64-python-websocket-client
mingw-w64-x86_64-libgme
mingw-w64-x86_64-rust
mingw-w64-x86_64-SDL2
mingw-w64-x86_64-SDL2_image
mingw-w64-x86_64-wavpack
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ colored_traceback
jxlpy; sys_platform != 'darwin' # macOS hates it - fails to find jxl/types.h - https://github.com/olokelo/jxlpy/issues/25#issuecomment-2547928563
#librespot - https://github.com/kokarare1212/librespot-python/pull/286
natsort
opencc
opencc; sys_platform != 'win32'
opencc-python-reimplemented; sys_platform == 'win32'
#picard - picard 2.12.3 requires charset-normalizer~=3.3.2, but you have charset-normalizer 3.4.0 which is incompatible.
plexapi
PyChromecast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ musicbrainzngs
mutagen
natsort # optdep
opencc-python-reimplemented # Windows version of openCC optdep
Pillow
PlexAPI
PyGObject
pyinstaller
Expand Down
12 changes: 4 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
# https://setuptools.pypa.io/en/latest/userguide/ext_modules.html
# This is terribly formatted as in TOML 1.0 it all has to be inline, can only be changed when TOML 1.1 ships

# Windows - MSVC - does not work as PyGobject, GTK, Cairo and et al won't build under MVSC
# Windows (MSVC) - does not work as PyGobject, GTK, Cairo and et al won't build under MVSC
# One option would be to test https://github.com/wingtk/gvsbuild + https://stackoverflow.com/a/72737752
# ./vcpkg.exe install libsndfile:x64-windows # TODO download the necessities instead of this bundle, libflac at minimum
# ./vcpkg.exe install mpg123:x64-windows # Hack 1.29.3 in first see https://sourceforge.net/p/mpg123/bugs/374/
# ./vcpkg.exe install mpg123:x64-windows
# ./vcpkg.exe install libsamplerate:x64-windows
# ./vcpkg.exe install libopenmpt:x64-windows
# ./vcpkg.exe install wavpack:x64-windows
Expand All @@ -85,18 +85,14 @@
# ext-modules = [
# {name = "phazor", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["src/phazor/miniaudio", "C:/Users/Yeet/Tauon/src/phazor/miniaudio", "C:/Users/Yeet/Tauon/vcpkg/installed/x64-windows/include", "C:/Users/Yeet/Tauon/src/phazor/kissfft", "C:/Users/Yeet/Tauon/src/phazor/miniaudio"], libraries=["samplerate", "wavpackdll", "opusfile", "ogg", "opus", "vorbisfile", "mpg123", "FLAC", "openmpt", "pthreadVC3", "gme"], library-dirs = ["vcpkg/installed/x64-windows/lib"] },]

# Linux + macOS
# Linux + macOS + Windows (MINGW64)
ext-modules = [
{name = "phazor", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["/usr/include/opus", "/opt/homebrew/include/opus", "/opt/homebrew/include"], libraries = ["samplerate", "wavpack", "opusfile", "vorbisfile", "mpg123", "FLAC", "openmpt", "gme"], library-dirs = ["/opt/homebrew/lib"] },
{name = "phazor", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["/usr/include/opus", "/opt/homebrew/include/opus", "/opt/homebrew/include", "C:/msys64/mingw64/include/opus"], libraries = ["samplerate", "wavpack", "opusfile", "vorbisfile", "mpg123", "FLAC", "openmpt", "gme"], library-dirs = ["/opt/homebrew/lib"] },
# Set as optional to allow soft-failure, it's expected not to build on Windows/macOS, but we don't want to fail the entire build on it
# I have not found a better way to solve this, ideally we would somehow tag this as Linux-exclusive
{name = "phazor-pw", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["/usr/include/opus"], libraries = ["samplerate", "wavpack", "opusfile", "vorbisfile", "mpg123", "FLAC", "openmpt", "gme", "pipewire-0.3"], optional = true },
]

# macOS
# ext-modules = [
# {name = "phazor", sources = ["src/phazor/kissfft/kiss_fftr.c", "src/phazor/kissfft/kiss_fft.c", "src/phazor/phazor.c"], include-dirs = ["/opt/homebrew/include/opus", "src/phazor/kissfft", "/opt/homebrew/include"], libraries=["samplerate", "wavpack", "opusfile", "vorbisfile", "mpg123", "FLAC", "openmpt", "gme"], library-dirs = ["/opt/homebrew/lib"] },]

package-dir = {"" = "src"}

# Should we care about these options or is it fine to omit them here?
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pysdl2-dll # Don't rely on system SDL2 https://github.com/py-sdl/py-sdl2#require
comtypes; sys_platform == 'win32'
infi.systray; sys_platform == 'win32'
keyboard; sys_platform == 'win32'
Pillow; sys_platform != 'win32'
Pillow
opencc; sys_platform != 'win32' # OPTDEP
opencc-python-reimplemented; sys_platform == 'win32' # OPTDEP
#pyinstaller # ; sys_platform != 'linux' # for macOS at least
Expand Down
57 changes: 35 additions & 22 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ set -euo pipefail

win_build() {
rm -rf dist/tauon
# Had to do Windows Security -> Virus & thread protection*2 -> Manage settings -> Windows Real-time protection: off

# TODO(Martin): pkg_resources is deprecated, does it still need to be there?
# https://setuptools.pypa.io/en/latest/pkg_resources.html
pyinstaller \
--name TauonMusicBox \
--noconfirm \
--additional-hooks-dir='extra\pyinstaller-hooks' \
--hidden-import 'infi.systray' \
--hidden-import 'pylast' \
--hidden-import 'tekore' \
--add-binary 'C:\msys64\mingw64\lib\girepository-1.0\Rsvg-2.0.typelib;gi_typelibs' \
--add-binary 'lib/libphazor.so;lib' \
--hidden-import 'phazor' \
--add-binary 'C:\msys64\mingw64\bin\libFLAC.dll;.' \
--add-binary 'C:\msys64\mingw64\bin\libmpg123-0.dll;.' \
--add-binary 'C:\msys64\mingw64\bin\libogg-0.dll;.' \
Expand All @@ -31,27 +33,40 @@ win_build() {
--hidden-import 'packaging.requirements' \
--hidden-import 'pkg_resources.py2_warn' \
--hidden-import 'requests' \
src/tauon/tauon.py \
-w -i assets/icon.ico
src/tauon/__main__.py \
-w -i src/tauon/assets/icon.ico

mkdir -p dist/tauon/tekore
mkdir -p dist/tauon/etc
mkdir -p dist/TauonMusicBox/tekore
mkdir -p dist/TauonMusicBox/etc

#cp C:/msys64/mingw64/lib/python3.13/site-packages/tekore/VERSION dist/tauon/tekore/VERSION

cp -r src/tauon/{theme,assets,locale,templates,lib} dist/tauon/
rm -rf dist/tauon/share/{icons,locale,tcl/tzdata} dist/tauon/tcl/tzdata
cp -r fonts dist/tauon/ || echo 'Fonts are not present!'
cp -r /mingw64/etc/fonts dist/tauon/etc
cp librespot.exe dist/tauon/
cp TaskbarLib.tlb dist/tauon/ || echo 'TLB is not present!'
cp -r src/tauon/{theme,assets,locale,templates} dist/TauonMusicBox/
rm -rf dist/tauon/share/{icons,locale,tcl/tzdata} dist/TauonMusicBox/tcl/tzdata
cp -r fonts dist/tauon/ || echo 'fonts directory is not present!'
cp -r /mingw64/etc/fonts dist/TauonMusicBox/etc
if [[ -e librespot.exe ]]; then
cp librespot.exe dist/TauonMusicBox/
else
echo 'librespot.exe is not present!'
fi
if [[ -e TaskbarLib.tlb ]]; then
cp TaskbarLib.tlb dist/TauonMusicBox/
else
echo 'TaskbarLib.tlb is not present!'
fi
echo -e "Packaged to dist/TauonMusicBox"
}

dirty_venv_run() {
if ! command -v python; then
python_check() {
if ! command -v python >/dev/null; then
echo -e "python executable not found? Is python installed? Debian(-based) distributions may need python-is-python3 installed via apt."
exit 1
fi
}

dirty_venv_run() {
python_check
# Ensure correct cwd, for example: ~/Projects/Tauon
cd "$(dirname "${0}")"
export PYTHONPATH=".":"${PYTHONPATH-}"
Expand All @@ -60,10 +75,7 @@ dirty_venv_run() {
}

clean_venv_run() {
if ! command -v python; then
echo -e "python executable not found? Is python installed? Debian(-based) distributions may need python-is-python3 installed via apt."
exit 1
fi
python_check
# Ensure correct cwd, for example: ~/Projects/Tauon
cd "$(dirname "${0}")"
export PYTHONPATH=".":"${PYTHONPATH-}"
Expand All @@ -82,14 +94,17 @@ clean_venv_run() {

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt -r requirements_optional.txt -r requirements_devel.txt build
# python -m pip install -U pip
# Necessary for Windows (MINGW64) if compiling things like Pillow
export CFLAGS="-I/mingw64/include"
# export LDFLAGS="-L/mingw64/lib"
pip install -r requirements.txt -r requirements_devel.txt build
python -m compile_translations
python -m build --wheel
pip install --prefix ".venv" dist/*.whl --force-reinstall
tauonmb # "${@}" # Passing args is broken atm
}


compile_phazor() {
outFile="build/libphazor.so"
mkdir -p build
Expand All @@ -100,7 +115,6 @@ compile_phazor() {
echo "Compiled as ${outFile}!"
}


compile_phazor_pipewire() {
outFile="build/libphazor-pw.so"
mkdir -p build
Expand All @@ -111,7 +125,6 @@ compile_phazor_pipewire() {
echo "Compiled as ${outFile}!"
}

# Display menu
show_menu() {
PS3="Select a script to run: "
select yn in "${answer_options[@]}"; do
Expand Down
Loading

0 comments on commit 1c1939c

Please sign in to comment.