diff --git a/.github/workflows/prebuilt.yml b/.github/workflows/prebuilt.yml index 0fcd3b7b..51ffed5e 100644 --- a/.github/workflows/prebuilt.yml +++ b/.github/workflows/prebuilt.yml @@ -49,7 +49,7 @@ jobs: with: version: 6.10.3 arch: win64_msvc2022_64 - modules: qtshadertools + modules: qtshadertools qtwebsockets cache: true - name: build @@ -151,7 +151,7 @@ jobs: with: version: 6.12.0 arch: linux_gcc_64 - # soloist, which is only built for linux, talks to spotify's soloist over websockets + # soloist talks to spotify's soloist over websockets modules: qtshadertools qtwebsockets cache: true @@ -193,7 +193,7 @@ jobs: host: mac target: desktop arch: clang_64 - modules: qtshadertools + modules: qtshadertools qtwebsockets cache: true - name: build diff --git a/CMakeLists.txt b/CMakeLists.txt index 61d42984..4f43fb90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.24) project(Swiftify - VERSION 0.20.3 + VERSION 0.21.0 DESCRIPTION "A native Spotify client" LANGUAGES C CXX) @@ -40,8 +40,8 @@ endif() # can be built and tested on a development machine without them. option(SWIFTIFY_DESKTOP_INTEGRATION "Build the Linux desktop integration" ${SWIFTIFY_IS_LINUX}) # spotify soloist plays spotify's songs for accounts spotify no longer gives -# librespot the keys for. it is only built for linux. -option(SWIFTIFY_SOLOIST "Play Spotify songs through Spotify Soloist when it is installed" ${SWIFTIFY_IS_LINUX}) +# librespot the keys for. +option(SWIFTIFY_SOLOIST "Play Spotify songs through Spotify Soloist when it is installed" ON) find_package(Qt6 6.10 REQUIRED COMPONENTS Core Gui Network Concurrent Qml Quick QuickControls2 ShaderTools) diff --git a/README.md b/README.md index b63ae988..a7594922 100644 --- a/README.md +++ b/README.md @@ -48,22 +48,22 @@ first image shows equalizer, tempo and pitch settings. second picture shows how ### "spotify could not load this track" (soloist) spotify refuses librespot the keys to decrypt songs on newer accounts (librespot's -logs say `error audio key 0 1`), so every song fails. on linux swiftify can play +logs say `error audio key 0 1`), so every song fails. swiftify can play spotify's songs through [spotify soloist](https://developer.spotify.com/documentation/soloist) instead, spotify's own connect client, which isnt affected. 1. install soloist from its [getting started guide](https://developer.spotify.com/documentation/soloist/tutorials/getting-started) - (`~/.local/bin/soloist` is fine) + (`~/.local/bin/soloist`, `/opt/homebrew/bin/soloist`, on your `PATH`, or beside `swiftify.exe` on windows) 2. make a soloist api key in the [developer dashboard](https://developer.spotify.com/dashboard/soloist) - and put it in `~/.config/soloist/api-key` (or `SOLOIST_API_KEY`) + and put it in `~/.config/soloist/api-key` (or `%LOCALAPPDATA%\soloist\api-key` on windows, or `SOLOIST_API_KEY`) 3. start swiftify. it starts soloist itself, as a connect device called "Swiftify". the first time, pick "Swiftify" once in the devices list of the spotify desktop app on the same computer (or the phone app), so soloist is signed in 4. press play in swiftify -with soloist, swiftify makes a sink called "Swiftify (Soloist)" for soloist to play into, +on linux with pipewire, swiftify makes a sink called "Swiftify (Soloist)" for soloist to play into, and plays that on through its own output, so the equalizer and the visualizers still work. -this needs pipewire, under pulseaudio alone soloist plays straight to the speakers. +under pulseaudio alone, or on macos and windows, soloist plays straight to the speakers. `SWIFTIFY_SOLOIST_ROUTE=off` does that on purpose. tempo and pitch only work on your own music files, and crossfade waits for each song to end. soloist builds expire after 90 days, download a new one when it says so. @@ -101,7 +101,7 @@ and a macos dmg for apple silicon. ### Build requirements -- Qt 6.10 or newer: Qt Base, Qt Declarative and Qt Shader Tools, and on linux Qt WebSockets (for soloist) +- Qt 6.10 or newer: Qt Base, Qt Declarative, Qt Shader Tools and Qt WebSockets - QtKeychain and QCoro 0.10 or newer, both built for Qt 6 - CMake 3.24 or newer, Ninja, and a C++20 compiler - Rust (stable, from [rustup](https://rustup.rs)) @@ -118,7 +118,7 @@ build, drop that and run `ctest --test-dir build` if u want them. u need [homebrew](https://brew.sh) and apple's command line tools (`xcode-select --install`, or full xcode). then: ```sh -brew install qtbase qtdeclarative qtshadertools qtkeychain qcoro6 cmake ninja +brew install qtbase qtdeclarative qtshadertools qtwebsockets qtkeychain qcoro6 cmake ninja curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y source "$HOME/.cargo/env" @@ -196,7 +196,7 @@ the tray. `-DSWIFTIFY_DESKTOP_INTEGRATION=OFF` turns those off. **because most Windows users cant even use their own OS, i made a script that handles building so it's as simple as possible :)** -first install Qt 6.10+ with *Qt Shader Tools*, CMake and Ninja from the Qt online installer, +first install Qt 6.10+ with *Qt Shader Tools* and *Qt WebSockets*, CMake and Ninja from the Qt online installer, Rust from [rustup](https://rustup.rs), and Git. choose either Qt for *MSVC 2022 64-bit* with Visual Studio 2022 17.1+ (or Build Tools) and its *Desktop development with C++* workload, or Qt for *MinGW 64-bit* with its matching MinGW toolchain. diff --git a/src/soloist/SoloistCore.cpp b/src/soloist/SoloistCore.cpp index f3fde5eb..9d5e8cc8 100644 --- a/src/soloist/SoloistCore.cpp +++ b/src/soloist/SoloistCore.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -25,6 +26,11 @@ #ifdef Q_OS_LINUX #include #include +#elif defined(Q_OS_MACOS) +#include +#include +#elif defined(Q_OS_WIN) +#include #endif Q_LOGGING_CATEGORY(lcSoloist, "swiftify.soloist") @@ -72,6 +78,25 @@ SoloistCore::SoloistCore(PlaybackCore *fallback, SoloistConfig config, QObject * // soloist goes with a swiftify that crashes or is killed too. one left // behind holds the data directory, and the next soloist will not start m_process.setChildProcessModifier([] { ::prctl(PR_SET_PDEATHSIG, SIGTERM); }); +#elif defined(Q_OS_WIN) + m_process.setCreateProcessArgumentsModifier([](QProcess::CreateProcessArguments *args) { + args->flags |= CREATE_NO_WINDOW; + }); + m_job = ::CreateJobObjectW(nullptr, nullptr); + if (m_job) { + JOBOBJECT_EXTENDED_LIMIT_INFORMATION info{}; + info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; + ::SetInformationJobObject(m_job, JobObjectExtendedLimitInformation, &info, sizeof(info)); + } + connect(&m_process, &QProcess::started, this, [this] { + if (!m_job) { + return; + } + if (HANDLE child = ::OpenProcess(PROCESS_SET_QUOTA | PROCESS_TERMINATE, FALSE, DWORD(m_process.processId()))) { + ::AssignProcessToJobObject(m_job, child); + ::CloseHandle(child); + } + }); #endif connect(&m_process, &QProcess::readyRead, this, [this] { const QString output = QString::fromUtf8(m_process.readAll()); @@ -144,12 +169,22 @@ SoloistCore::~SoloistCore() m_socket.abort(); if (m_process.state() != QProcess::NotRunning) { m_process.disconnect(this); +#ifdef Q_OS_WIN + m_process.kill(); + m_process.waitForFinished(1000); +#else m_process.terminate(); if (!m_process.waitForFinished(2000)) { m_process.kill(); m_process.waitForFinished(1000); } +#endif } +#ifdef Q_OS_WIN + if (m_job) { + ::CloseHandle(m_job); + } +#endif } std::optional SoloistCore::detect() @@ -165,9 +200,19 @@ std::optional SoloistCore::detect() } if (config.program.isEmpty()) { // a launcher's PATH often leaves out ~/.local/bin, where soloist's - // guide installs it without sudo - config.program = QStandardPaths::findExecutable(QStringLiteral("soloist"), - {QDir::homePath() + QStringLiteral("/.local/bin")}); + // guide installs it without sudo, and homebrew's bin on macos + const QStringList extraPaths{ + QCoreApplication::applicationDirPath(), + QDir::homePath() + QStringLiteral("/.local/bin"), +#ifdef Q_OS_MACOS + QStringLiteral("/opt/homebrew/bin"), + QStringLiteral("/usr/local/bin"), +#elif defined(Q_OS_WIN) + QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/soloist"), + QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/Programs/soloist"), +#endif + }; + config.program = QStandardPaths::findExecutable(QStringLiteral("soloist"), extraPaths); } if (config.program.isEmpty()) { qCInfo(lcSoloist) << "Soloist not found; playing through librespot"; @@ -176,10 +221,24 @@ std::optional SoloistCore::detect() config.apiKey = qEnvironmentVariable("SOLOIST_API_KEY").trimmed(); if (config.apiKey.isEmpty()) { - QFile file(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) - + QStringLiteral("/soloist/api-key")); - if (file.open(QIODevice::ReadOnly)) { - config.apiKey = QString::fromUtf8(file.readAll()).trimmed(); + const QString configDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); + const QString dotConfig = QDir::homePath() + QStringLiteral("/.config"); + const QStringList candidates{ + configDir + QStringLiteral("/soloist/api-key"), + dotConfig + QStringLiteral("/soloist/api-key"), +#ifdef Q_OS_WIN + configDir + QStringLiteral("/soloist/api-key.txt"), + dotConfig + QStringLiteral("/soloist/api-key.txt"), +#endif + }; + for (const QString &path : candidates) { + QFile file(path); + if (file.open(QIODevice::ReadOnly)) { + config.apiKey = QString::fromUtf8(file.readAll()).trimmed(); + if (!config.apiKey.isEmpty()) { + break; + } + } } } if (config.apiKey.isEmpty()) { @@ -202,6 +261,19 @@ void SoloistCore::startDaemon() m_failure.clear(); m_processOutput.clear(); QDir().mkpath(m_config.dataDirectory); +#ifdef Q_OS_MACOS + // macos has no PR_SET_PDEATHSIG; a soloist left behind by a killed + // swiftify holds the data directory until it is stopped + if (QFile pidFile(m_config.dataDirectory + QStringLiteral("/soloist.pid")); pidFile.open(QIODevice::ReadOnly)) { + bool ok = false; + const pid_t pid = pidFile.readAll().trimmed().toInt(&ok); + char path[PROC_PIDPATHINFO_MAXSIZE]{}; + if (ok && pid > 1 && ::proc_pidpath(pid, path, sizeof(path)) > 0 + && QString::fromUtf8(path).endsWith(QLatin1StringView("/soloist"))) { + ::kill(pid, SIGTERM); + } + } +#endif #ifdef SWIFTIFY_DESKTOP_INTEGRATION if (!m_route && qEnvironmentVariable("SWIFTIFY_SOLOIST_ROUTE") != QLatin1StringView("off")) { // recorded at the rate swiftify's output plays at, so it is played diff --git a/src/soloist/SoloistCore.h b/src/soloist/SoloistCore.h index 74b56f96..6e7cffb5 100644 --- a/src/soloist/SoloistCore.h +++ b/src/soloist/SoloistCore.h @@ -127,6 +127,9 @@ class SoloistCore : public PlaybackCore { std::unique_ptr m_liveBuffer; #ifdef SWIFTIFY_DESKTOP_INTEGRATION std::unique_ptr m_route; +#endif +#ifdef Q_OS_WIN + void *m_job = nullptr; #endif /// soloist plays into m_route's sink bool m_routed = false; diff --git a/src/system/windows/WindowsIntegration.cpp b/src/system/windows/WindowsIntegration.cpp index 3ad14e89..06cdb78f 100644 --- a/src/system/windows/WindowsIntegration.cpp +++ b/src/system/windows/WindowsIntegration.cpp @@ -235,6 +235,13 @@ struct WindowsIntegration::Native { void WindowsIntegration::initializeProcess() { SetCurrentProcessExplicitAppUserModelID(L"dev.addenator.Swiftify.Qt"); + const HANDLE err = GetStdHandle(STD_ERROR_HANDLE); + if ((err && err != INVALID_HANDLE_VALUE && GetFileType(err) != FILE_TYPE_UNKNOWN) + || AttachConsole(ATTACH_PARENT_PROCESS)) { + if (!qEnvironmentVariableIsSet("QT_FORCE_STDERR_LOGGING")) { + qputenv("QT_FORCE_STDERR_LOGGING", "1"); + } + } } void WindowsIntegration::setNativeTitleBar(QWindow *window, bool enabled) diff --git a/tests/check_windows_build.ps1 b/tests/check_windows_build.ps1 index 641817da..075522c3 100644 --- a/tests/check_windows_build.ps1 +++ b/tests/check_windows_build.ps1 @@ -105,7 +105,7 @@ try { $buildRoot = Join-Path $fixture 'build' $installPrefix = Join-Path $fixture 'installed' New-FixtureFile "$qtPath\mkspecs\qconfig.pri" "QT_VERSION = 6.12.0`nQT_ARCH = x86_64`nQT_GCC_MAJOR_VERSION = 15`nQT_GCC_MINOR_VERSION = 1`nQT_GCC_PATCH_VERSION = 0" - foreach ($module in @('Qt6Core', 'Qt6Widgets', 'Qt6Quick', 'Qt6QuickControls2', 'Qt6ShaderTools')) { + foreach ($module in @('Qt6Core', 'Qt6Widgets', 'Qt6Quick', 'Qt6QuickControls2', 'Qt6ShaderTools', 'Qt6WebSockets')) { New-FixtureFile "$qtPath\lib\cmake\$module\${module}Config.cmake" } foreach ($file in @('gcc.exe', 'g++.exe', 'libstdc++-6.dll', 'libgcc_s_seh-1.dll', 'libwinpthread-1.dll')) { diff --git a/tests/tst_soloist.cpp b/tests/tst_soloist.cpp index 4cafe37e..57ac3dad 100644 --- a/tests/tst_soloist.cpp +++ b/tests/tst_soloist.cpp @@ -171,6 +171,24 @@ private slots: QVERIFY(m_dir->isValid()); // stands in for the soloist binary: writes the port the fake listens // on where soloist would, and waits to be stopped +#ifdef Q_OS_WIN + m_program = m_dir->filePath(QStringLiteral("soloist.cmd")); + QFile script(m_program); + QVERIFY(script.open(QIODevice::WriteOnly)); + script.write("@echo off\r\n" + ":loop\r\n" + "if \"%~1\"==\"\" goto done\r\n" + "if \"%~1\"==\"--data-dir\" (\r\n" + " set \"d=%~2\"\r\n" + " shift\r\n" + ")\r\n" + "shift\r\n" + "goto loop\r\n" + ":done\r\n" + " \"%d%\\ws.port\"\r\n" + "ping -n 600 127.0.0.1 >nul\r\n"); + script.close(); +#else m_program = m_dir->filePath(QStringLiteral("soloist")); QFile script(m_program); QVERIFY(script.open(QIODevice::WriteOnly)); @@ -180,6 +198,7 @@ private slots: "exec sleep 600\n"); script.close(); script.setPermissions(script.permissions() | QFile::ExeOwner); +#endif m_soloist = std::make_unique(); qputenv("FAKE_SOLOIST_PORT", QByteArray::number(m_soloist->port())); // no sink in the real sound server for a test @@ -417,6 +436,22 @@ private slots: QVERIFY(m_fallback->log.contains(QStringLiteral("pause"))); } + void detectsSoloistAndApiKey() + { + qputenv("SWIFTIFY_SOLOIST", m_program.toUtf8()); + qputenv("SOLOIST_API_KEY", "test-api-key"); + qputenv("SWIFTIFY_PLAYBACK", "librespot"); + QVERIFY(!SoloistCore::detect().has_value()); + + qunsetenv("SWIFTIFY_PLAYBACK"); + const auto detected = SoloistCore::detect(); + QVERIFY(detected.has_value()); + QCOMPARE(detected->program, m_program); + QCOMPARE(detected->apiKey, QStringLiteral("test-api-key")); + qunsetenv("SWIFTIFY_SOLOIST"); + qunsetenv("SOLOIST_API_KEY"); + } + void settingVolumeSendsSetVolumeToSoloist() { QCoro::waitFor(m_core->playTrack(QStringLiteral("spotify:track:a"))); diff --git a/tools/build-windows-from-linux.sh b/tools/build-windows-from-linux.sh new file mode 100755 index 00000000..34a82970 --- /dev/null +++ b/tools/build-windows-from-linux.sh @@ -0,0 +1,278 @@ +#!/usr/bin/env bash +# cross-builds a self-contained windows x86_64 folder and zip of swiftify from +# linux, downloading the matching windows mingw qt kit from download.qt.io on +# the first run so nothing has to be installed or built on windows +# this is mainly intended for testing on windows without needing to deal with this qt account crap +# +# +# usage +# ./tools/build-windows-from-linux.sh +# ./tools/build-windows-from-linux.sh --install-deps +# ./tools/build-windows-from-linux.sh --qt /path/to/Qt/6.12.0/mingw_64 --out dist +# +# needs mingw-w64-gcc, host qt6 (qt6-base, qt6-declarative, qt6-shadertools, +# qt6-websockets), cmake, ninja, git, curl, python3, bsdtar, zip and rust + +set -euo pipefail + +QT="" +HOST_QT="/usr" +OUT="dist" +JOBS="$(nproc 2>/dev/null || echo 4)" +INSTALL_DEPS=false + +while [[ $# -gt 0 ]]; do + case $1 in + --qt) QT="$2"; shift 2 ;; + --host-qt) HOST_QT="$2"; shift 2 ;; + --out) OUT="$2"; shift 2 ;; + --jobs) JOBS="$2"; shift 2 ;; + --install-deps) INSTALL_DEPS=true; shift ;; + -h|--help) + sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//' + exit 0 + ;; + *) echo "unknown option $1" >&2; exit 1 ;; + esac +done + +fail() { echo "error: $1" >&2; exit 1; } + +if $INSTALL_DEPS; then + if command -v pacman >/dev/null 2>&1; then + sudo pacman -S --needed mingw-w64-gcc qt6-base qt6-declarative qt6-shadertools qt6-websockets \ + cmake ninja git curl libarchive + elif command -v apt-get >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get install -y g++-mingw-w64-x86-64-posix qt6-base-dev qt6-base-dev-tools \ + qt6-declarative-dev qt6-declarative-dev-tools qt6-shader-baker qt6-shadertools-dev \ + qt6-websockets-dev cmake ninja-build git curl libarchive-tools + else + fail "--install-deps supports pacman and apt-get; install mingw-w64-gcc and host qt6 manually" + fi +fi + +for tool in x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc x86_64-w64-mingw32-windres x86_64-w64-mingw32-objdump \ + cmake ninja git curl bsdtar; do + command -v "$tool" >/dev/null 2>&1 || fail "$tool is missing (run with --install-deps or install mingw-w64-gcc)" +done + +SOURCE="$(cd "$(dirname "$0")/.." && pwd)" +VERSION="$(sed -n '/^project(Swiftify/,/VERSION/s/^ *VERSION \([0-9.]*\).*/\1/p' "$SOURCE/CMakeLists.txt")" +[[ -n "$VERSION" ]] || fail "could not read the version from CMakeLists.txt" +NAME="swiftify-$VERSION-windows-x86_64" +mkdir -p "$OUT" +OUT="$(cd "$OUT" && pwd)" +WORK="$SOURCE/build-windows-cross" +DEPS="$WORK/deps" +STAGE="$OUT/$NAME" +mkdir -p "$WORK/sources" + +# host qt version, which the windows qt kit must match for moc/qmlcachegen/qsb +HOST_QT_VERSION="$(pkg-config --modversion Qt6Core 2>/dev/null || true)" +if [[ -z "$HOST_QT_VERSION" && -x "$HOST_QT/bin/qmake6" ]]; then + HOST_QT_VERSION="$("$HOST_QT/bin/qmake6" -query QT_VERSION)" +fi +[[ -n "$HOST_QT_VERSION" ]] || fail "could not detect host Qt6 version; install qt6-base" + +# rust target x86_64-pc-windows-gnu: use system rustup if present, or a local +# rustup inside build-windows-cross when the system uses a plain distro rust package +RUST_TARGET="x86_64-pc-windows-gnu" +RUST_CMAKE_ARGS=("-DRust_CARGO_TARGET=$RUST_TARGET") +has_rust_target() { + local rustc_bin="$1" sysroot + sysroot="$("$rustc_bin" --print target-libdir --target "$RUST_TARGET" 2>/dev/null || true)" + [[ -n "$sysroot" && -d "$sysroot" ]] && compgen -G "$sysroot/libstd*" >/dev/null +} +if ! has_rust_target rustc; then + if command -v rustup >/dev/null 2>&1; then + rustup target add "$RUST_TARGET" + else + export RUSTUP_HOME="$WORK/rustup" + export CARGO_HOME="$WORK/cargo" + export PATH="$CARGO_HOME/bin:$PATH" + if [[ ! -x "$CARGO_HOME/bin/rustup" ]]; then + echo "installing a local rust toolchain with $RUST_TARGET in $WORK/rustup..." + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \ + --no-modify-path --profile minimal --default-toolchain stable --target "$RUST_TARGET" + else + "$CARGO_HOME/bin/rustup" target add "$RUST_TARGET" + fi + RUST_CMAKE_ARGS+=( + "-DRust_COMPILER=$CARGO_HOME/bin/rustc" + "-DRust_CARGO=$CARGO_HOME/bin/cargo" + ) + fi +fi + +# download the matching windows mingw_64 qt kit from download.qt.io if --qt was not given +if [[ -z "$QT" ]]; then + QT_NODOT="${HOST_QT_VERSION//./}" + QT="$WORK/qt" + if [[ ! -f "$QT/lib/cmake/Qt6Core/Qt6CoreConfig.cmake" ]]; then + echo "downloading Windows Qt $HOST_QT_VERSION (mingw_64) into $QT..." + mkdir -p "$WORK/qt/archives" "$QT" + BASE_URL="" + UPDATES_XML="" + for candidate in \ + "https://download.qt.io/online/qtsdkrepository/windows_x86/desktop/qt6_${QT_NODOT}/qt6_${QT_NODOT}_mingw" \ + "https://download.qt.io/online/qtsdkrepository/windows_x86/desktop/qt6_${QT_NODOT}"; do + if UPDATES_XML="$(curl -fsSL "$candidate/Updates.xml" 2>/dev/null)" && [[ -n "$UPDATES_XML" ]]; then + BASE_URL="$candidate" + break + fi + done + [[ -n "$BASE_URL" ]] || fail "could not find Qt $HOST_QT_VERSION Windows MinGW repository on download.qt.io" + + while read -r pkg ver archive; do + case "$pkg:$archive" in + "qt.qt6.${QT_NODOT}.win64_mingw":qtbase-* | \ + "qt.qt6.${QT_NODOT}.win64_mingw":qtsvg-* | \ + "qt.qt6.${QT_NODOT}.win64_mingw":qtdeclarative-* | \ + "qt.qt6.${QT_NODOT}.win64_mingw":d3dcompiler_47-* | \ + "qt.qt6.${QT_NODOT}.win64_mingw":MinGW-w64-* | \ + "qt.qt6.${QT_NODOT}.addons.qtshadertools.win64_mingw":qtshadertools-* | \ + "qt.qt6.${QT_NODOT}.addons.qtwebsockets.win64_mingw":qtwebsockets-* | \ + "qt.qt6.${QT_NODOT}.addons.qtimageformats.win64_mingw":qtimageformats-*) + dest="$WORK/qt/archives/${ver}${archive}" + if [[ ! -f "$dest" ]]; then + echo " fetching $archive..." + curl -fL --retry 3 -o "$dest.part" "$BASE_URL/$pkg/${ver}${archive}" + mv "$dest.part" "$dest" + fi + bsdtar -xf "$dest" -C "$QT" + ;; + esac + done < <(awk -F'[<>]' ' + // { name = $3 } + // { ver = $3 } + // { + n = split($3, arr, ",") + for (i = 1; i <= n; i++) { + gsub(/^[ \t]+|[ \t]+$/, "", arr[i]) + if (arr[i] != "") print name, ver, arr[i] + } + } + ' <<< "$UPDATES_XML") + fi +fi +QT="$(cd "$QT" && pwd)" +[[ -f "$QT/lib/cmake/Qt6Core/Qt6CoreConfig.cmake" ]] || fail "no Qt6CoreConfig.cmake in $QT" + +# 1. build the native host shape_atlas tool first +SHAPE_ATLAS="$WORK/host-tools/shape_atlas" +if [[ ! -x "$SHAPE_ATLAS" ]]; then + echo "building host shape_atlas tool..." + mkdir -p "$WORK/host-tools" + g++ -std=c++20 -O2 -fPIC "$SOURCE/tools/shape_atlas/main.cpp" \ + -I"$SOURCE/tools/shape_atlas" \ + $(pkg-config --cflags --libs Qt6Core Qt6Gui Qt6Qml) \ + -o "$SHAPE_ATLAS" +fi + +# 2. write a cmake toolchain file for x86_64-w64-mingw32 +TOOLCHAIN="$WORK/mingw-toolchain.cmake" +cat > "$TOOLCHAIN" </dev/null \ + | awk '/DLL Name:/ { print $3 }' | sort -u) + $copied || break +done + +cat > "$BIN/qt.conf" <<'EOF' +[Paths] +Plugins = . +QmlImports = qml +EOF + +echo "built $STAGE (run $BIN/swiftify.exe)" diff --git a/tools/build-windows.ps1 b/tools/build-windows.ps1 index adf512eb..cc5fc282 100644 --- a/tools/build-windows.ps1 +++ b/tools/build-windows.ps1 @@ -158,9 +158,9 @@ function Invoke-WindowsBuild { if (-not $qtVersion -or [version]$qtVersion -lt [version]'6.10' -or $qtConfiguration -notmatch '(?m)^QT_ARCH\s*=\s*x86_64\s*$') { throw 'Swiftify requires a Qt 6.10+ x64 kit.' } - foreach ($module in @('Qt6Core', 'Qt6Widgets', 'Qt6Quick', 'Qt6QuickControls2', 'Qt6ShaderTools')) { + foreach ($module in @('Qt6Core', 'Qt6Widgets', 'Qt6Quick', 'Qt6QuickControls2', 'Qt6ShaderTools', 'Qt6WebSockets')) { if (-not (Test-Path -LiteralPath "$QtPath\lib\cmake\$module\${module}Config.cmake")) { - throw "The selected Qt kit is missing $module. Install Qt Base, Qt Declarative and Qt Shader Tools with the Qt installer." + throw "The selected Qt kit is missing $module. Install Qt Base, Qt Declarative, Qt Shader Tools and Qt WebSockets with the Qt installer." } } $qtTools = Join-Path (Split-Path -Parent (Split-Path -Parent $QtPath)) 'Tools'