From 0006c54c46c1ea87809adae0d027e3eb5045c25e Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 31 Jul 2022 14:46:30 +1000 Subject: [PATCH] Build: Add Mac dependencies and fix packaging --- .github/workflows/rolling-release.yml | 84 ++++++++++-------- scripts/build-dependencies-mac.sh | 122 ++++++++++++++++++++++++++ src/common/threading.cpp | 5 +- src/duckstation-qt/CMakeLists.txt | 58 ++++++------ src/frontend-common/fullscreen_ui.cpp | 1 + src/frontend-common/game_list.cpp | 1 + 6 files changed, 204 insertions(+), 67 deletions(-) create mode 100755 scripts/build-dependencies-mac.sh diff --git a/.github/workflows/rolling-release.yml b/.github/workflows/rolling-release.yml index c50cc8355..f3b7c3554 100644 --- a/.github/workflows/rolling-release.yml +++ b/.github/workflows/rolling-release.yml @@ -310,46 +310,51 @@ jobs: # name: "linux-x64-appimage-qt-zsync" # path: "build/duckstation-qt-x64.AppImage.zsync" -# Disabled until we switch to macdeployqt -# macos-build: -# runs-on: macos-11 -# steps: -# - uses: actions/checkout@v2.3.1 -# with: -# fetch-depth: 0 -# -# - name: Install packages -# shell: bash -# run: | -# brew install qt6 sdl2 curl ninja -# -# - name: Clone mac externals -# shell: bash -# run: | -# git clone https://github.com/stenzek/duckstation-ext-mac.git dep/mac -# -# - name: Compile and zip .app -# shell: bash -# run: | -# mkdir build -# cd build -# ls -lh /usr/local/opt -# export MACOSX_DEPLOYMENT_TARGET=10.14 -# cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_NOGUI_FRONTEND=OFF -DBUILD_QT_FRONTEND=ON -DUSE_SDL2=ON -DQt6_DIR=/usr/local/opt/qt@6/lib/cmake/Qt6 -G Ninja .. -# cmake --build . --parallel -# cd bin -# zip -r duckstation-mac-release.zip DuckStation.app/ -# -# - name: Upload macOS .app -# uses: actions/upload-artifact@v1 -# with: -# name: "macos-x64" -# path: "build/bin/duckstation-mac-release.zip" + + macos-build: + runs-on: macos-11 + steps: + - uses: actions/checkout@v2.3.1 + with: + fetch-depth: 0 + + - name: Install packages + shell: bash + run: | + brew install curl ninja + + - name: Cache Dependencies + id: cache-deps-mac + uses: actions/cache@v3 + with: + path: ~/deps + key: deps-mac ${{ hashFiles('scripts/build-dependencies-mac.sh') }} + + - name: Build Dependencies + if: steps.cache-deps-mac.outputs.cache-hit != 'true' + run: scripts/build-dependencies-mac.sh + + - name: Compile and zip .app + shell: bash + run: | + mkdir build + cd build + export MACOSX_DEPLOYMENT_TARGET=10.14 + cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_NOGUI_FRONTEND=OFF -DBUILD_QT_FRONTEND=ON -DUSE_SDL2=ON -DCMAKE_PREFIX_PATH=$HOME/deps -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -G Ninja .. + cmake --build . --parallel + cd bin + zip -r duckstation-mac-release.zip DuckStation.app/ + + - name: Upload macOS .app + uses: actions/upload-artifact@v1 + with: + name: "macos" + path: "build/bin/duckstation-mac-release.zip" create-release: #needs: [windows-build, windows-arm64-build, linux-build, windows-uwp-build] - needs: [windows-build, windows-arm64-build, linux-build] + needs: [windows-build, windows-arm64-build, linux-build, macos-build] runs-on: "ubuntu-20.04" if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' steps: @@ -388,6 +393,11 @@ jobs: # with: # name: "linux-x64-appimage-qt-zsync" + - name: Download MacOS Artifact + uses: actions/download-artifact@v1 + with: + name: "macos" + - name: Create preview release if: github.ref == 'refs/heads/master' uses: "marvinpinto/action-automatic-releases@latest" @@ -402,6 +412,7 @@ jobs: windows-arm64/duckstation-windows-arm64-release.zip windows-arm64/duckstation-windows-arm64-release-symbols.zip linux-x64-appimage-qt/DuckStation-x64.AppImage + macos/duckstation-mac-release.zip # linux-x64-appimage-qt/duckstation-qt-x64.AppImage # linux-x64-appimage-qt-zsync/duckstation-qt-x64.AppImage.zsync # windows-uwp/duckstation-uwp.appx @@ -423,6 +434,7 @@ jobs: windows-arm64/duckstation-windows-arm64-release.zip windows-arm64/duckstation-windows-arm64-release-symbols.zip linux-x64-appimage-qt/DuckStation-x64.AppImage + macos/duckstation-mac-release.zip # linux-x64-appimage-qt/duckstation-qt-x64.AppImage # linux-x64-appimage-qt-zsync/duckstation-qt-x64.AppImage.zsync # windows-uwp/duckstation-uwp.appx diff --git a/scripts/build-dependencies-mac.sh b/scripts/build-dependencies-mac.sh new file mode 100755 index 000000000..aa94541d2 --- /dev/null +++ b/scripts/build-dependencies-mac.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +set -e + +export MACOSX_DEPLOYMENT_TARGET=10.14 +INSTALLDIR="$HOME/deps" +NPROCS="$(getconf _NPROCESSORS_ONLN)" +SDL=SDL2-2.0.22 +QT=6.3.1 +MOLTENVK=1.1.10 +CURL=7.84.0 + +mkdir deps-build +cd deps-build + +export PKG_CONFIG_PATH="$INSTALLDIR/lib/pkgconfig:$PKG_CONFIG_PATH" +export LDFLAGS="-L$INSTALLDIR/lib -dead_strip $LDFLAGS" +export CFLAGS="-I$INSTALLDIR/include -Os $CFLAGS" +export CXXFLAGS="-I$INSTALLDIR/include -Os $CXXFLAGS" + +cat > SHASUMS < #include #include +#else #include #endif #endif @@ -382,7 +383,7 @@ void* Threading::Thread::ThreadProc(void* param) bool Threading::Thread::Start(EntryPoint func) { - pxAssertRel(!m_native_handle, "Can't start an already-started thread"); + AssertMsg(!m_native_handle, "Can't start an already-started thread"); std::unique_ptr func_clone(std::make_unique(std::move(func))); @@ -550,6 +551,8 @@ void Threading::SetNameOfCurrentThread(const char* name) // Extract of manpage: "The name can be up to 16 bytes long, and should be // null-terminated if it contains fewer bytes." prctl(PR_SET_NAME, name, 0, 0, 0); +#elif defined(__APPLE__) + pthread_setname_np(name); #else pthread_set_name_np(pthread_self(), name); #endif diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index b5320e34c..9190ad475 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -196,34 +196,31 @@ if(APPLE) MACOSX_BUNDLE true MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in OUTPUT_NAME DuckStation - ) + ) - # Copy qt.conf into the bundle - target_sources(duckstation-qt PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/qt.conf") - set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/qt.conf" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + # Use macdeployqt to inject Qt into the bundle. + get_target_property(MOC_EXECUTABLE_LOCATION Qt6::moc IMPORTED_LOCATION) + get_filename_component(QT_BINARY_DIRECTORY "${MOC_EXECUTABLE_LOCATION}" DIRECTORY) + find_program(MACDEPLOYQT_EXE macdeployqt HINTS "${QT_BINARY_DIRECTORY}") + add_custom_target(duckstation-postprocess-bundle ALL + COMMAND "${MACDEPLOYQT_EXE}" "${BUNDLE_PATH}" + ) + add_dependencies(duckstation-postprocess-bundle duckstation-qt) # Copy icon into the bundle target_sources(duckstation-qt PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/DuckStation.icns") set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/DuckStation.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) - # Copy Qt plugins into the bundle - get_target_property(qtcocoa_location Qt6::QCocoaIntegrationPlugin LOCATION) - target_sources(duckstation-qt PRIVATE "${qtcocoa_location}") - set_source_files_properties("${qtcocoa_location}" PROPERTIES MACOSX_PACKAGE_LOCATION MacOS/platforms) - - get_target_property(qtmacstyle_location Qt6::QMacStylePlugin LOCATION) - target_sources(duckstation-qt PRIVATE "${qtmacstyle_location}") - set_source_files_properties("${qtmacstyle_location}" PROPERTIES MACOSX_PACKAGE_LOCATION MacOS/styles) - # Copy resources into the bundle - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/data") - file(GLOB_RECURSE resources RELATIVE "${CMAKE_SOURCE_DIR}/data" "${CMAKE_SOURCE_DIR}/data/*") + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/data/resources") + file(GLOB_RECURSE resources RELATIVE "${CMAKE_SOURCE_DIR}/data/resources" "${CMAKE_SOURCE_DIR}/data/resources/*") foreach(res ${resources}) - target_sources(duckstation-qt PRIVATE "${CMAKE_SOURCE_DIR}/data/${res}") + message(STATUS "Resource: ${res}") + target_sources(duckstation-qt PRIVATE "${CMAKE_SOURCE_DIR}/data/resources/${res}") get_filename_component(resdir "${res}" DIRECTORY) - set_source_files_properties("${CMAKE_SOURCE_DIR}/data/${res}" PROPERTIES - MACOSX_PACKAGE_LOCATION "MacOS/${resdir}") - source_group("Resources" FILES "${CMAKE_SOURCE_DIR}/data/${res}") + set_source_files_properties("${CMAKE_SOURCE_DIR}/data/resources/${res}" PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources/${resdir}") + source_group("Resources" FILES "${CMAKE_SOURCE_DIR}/data/resources/${res}") endforeach() # Copy translations into the bundle @@ -233,16 +230,17 @@ if(APPLE) COMMAND cp ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/translations/*.qm $/translations) # Copy MoltenVK into the bundle - target_sources(duckstation-qt PRIVATE "${CMAKE_SOURCE_DIR}/dep/mac/MoltenVK/libvulkan.dylib") - set_source_files_properties("${CMAKE_SOURCE_DIR}/dep/mac/MoltenVK/libvulkan.dylib" PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks) - - # Update library references to make the bundle portable - include(DolphinPostprocessBundle) - dolphin_postprocess_bundle(duckstation-qt) - # Fix rpath - add_custom_command(TARGET duckstation-qt - POST_BUILD COMMAND - ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../Frameworks/" - $) + unset(MOLTENVK_PATH CACHE) + find_file(MOLTENVK_PATH NAMES + libMoltenVK.dylib + lib/libMoltenVK.dylib + ) + if (MOLTENVK_PATH) + target_sources(duckstation-qt PRIVATE "${MOLTENVK_PATH}") + set_source_files_properties("${MOLTENVK_PATH}" PROPERTIES MACOSX_PACKAGE_LOCATION Frameworks) + message(STATUS "Using MoltenVK from ${MOLTENVK_PATH}") + else() + message(WARNING "MoltenVK not found in path, it will depend on the target system having it.") + endif() endif() diff --git a/src/frontend-common/fullscreen_ui.cpp b/src/frontend-common/fullscreen_ui.cpp index b781bb268..691adeb03 100644 --- a/src/frontend-common/fullscreen_ui.cpp +++ b/src/frontend-common/fullscreen_ui.cpp @@ -34,6 +34,7 @@ #include "util/ini_settings_interface.h" #include #include +#include #include Log_SetChannel(FullscreenUI); diff --git a/src/frontend-common/game_list.cpp b/src/frontend-common/game_list.cpp index a0c40456a..99d3ab0da 100644 --- a/src/frontend-common/game_list.cpp +++ b/src/frontend-common/game_list.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include