From 3efae5bff73be9dfc75c3bcd5c98ea26408f1b97 Mon Sep 17 00:00:00 2001 From: adam-bloom Date: Sun, 12 Sep 2021 17:33:01 -0600 Subject: [PATCH 1/7] minor changes and point at alpha dependencies --- CMakeLists.txt | 56 +++++++++++++++++++++++++--------- src/openrct2-ui/CMakeLists.txt | 14 +++++++-- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90b62508cc..ee40b371fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,12 +20,27 @@ if (CCache_FOUND) endif (CCache_FOUND) if (APPLE) - set(CMAKE_OSX_ARCHITECTURES "x86_64") - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14") -endif () + execute_process(COMMAND /usr/bin/uname -m OUTPUT_VARIABLE SYSTEM_MACOS_ARCH OUTPUT_STRIP_TRAILING_WHITESPACE) + if (NOT DEFINED ARCH) + set(ARCH "${SYSTEM_MACOS_ARCH}") + endif () + set(CMAKE_OSX_ARCHITECTURES "${ARCH}" CACHE STRING "") + + if("${ARCH}" MATCHES "^x86_64") + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "") + elseif("${ARCH}" MATCHES "^arm64") + set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "") + else() + message("Unknown macOS architecture: ${ARCH}. Behavior may be unexpected.") + endif() +endif () project(openrct2 CXX) +if (APPLE) + set(CMAKE_SYSTEM_PROCESSOR "${CMAKE_OSX_ARCHITECTURES}" CACHE STRING "") +endif () + include(cmake/platform.cmake) include(CMakeDependentOption) @@ -110,11 +125,16 @@ if (MACOS_USE_DEPENDENCIES) # if we're building on macOS, then we need the dependencies include(cmake/download.cmake) - set(MACOS_DYLIBS_VERSION "28") - set(MACOS_DYLIBS_ZIPFILE "openrct2-libs-v${MACOS_DYLIBS_VERSION}-x64-macos-dylibs.zip") - set(MACOS_DYLIBS_SHA1 "29e5480376cf4ac5943f114387e32685204c8b78") + # TODO - change back before merging + # set(MACOS_DYLIBS_VERSION "28") + # set(MACOS_DYLIBS_ZIPFILE "openrct2-libs-v${MACOS_DYLIBS_VERSION}-x64-macos-dylibs.zip") + # set(MACOS_DYLIBS_SHA1 "29e5480376cf4ac5943f114387e32685204c8b78") + set(MACOS_DYLIBS_VERSION "29-alpha2") + set(MACOS_DYLIBS_ZIPFILE "openrct2-libs-v${MACOS_DYLIBS_VERSION}-universal-macos-dylibs.zip") + set(MACOS_DYLIBS_SHA1 "bb8899c4120f1add232af7f9ac774ea622e01ad3") set(MACOS_DYLIBS_DIR "${ROOT_DIR}/lib/macos") - set(MACOS_DYLIBS_URL "https://github.com/OpenRCT2/Dependencies/releases/download/v${MACOS_DYLIBS_VERSION}/${MACOS_DYLIBS_ZIPFILE}") + # set(MACOS_DYLIBS_URL "https://github.com/OpenRCT2/Dependencies/releases/download/v${MACOS_DYLIBS_VERSION}/${MACOS_DYLIBS_ZIPFILE}") + set(MACOS_DYLIBS_URL "https://github.com/adam-bloom/Dependencies/releases/download/v${MACOS_DYLIBS_VERSION}/${MACOS_DYLIBS_ZIPFILE}") download_openrct2_zip( ZIP_VERSION ${MACOS_DYLIBS_VERSION} @@ -209,6 +229,10 @@ if (NOT DISABLE_DISCORD_RPC) endif() endif() +# ensure X86 and X86_64 are always initialized +# may be overwritten below +set(X86 0) +set(X86_64 0) # Copied from https://github.com/opencv/opencv/blob/dcdd6af5a856826fe62c95322145731e702e54c5/cmake/OpenCVDetectCXXCompiler.cmake#L63-L70 if(MSVC64 OR MINGW64) set(X86_64 1) @@ -368,14 +392,16 @@ endif () # g2 -add_custom_command( - OUTPUT g2.dat - COMMAND ./openrct2-cli sprite build \"${CMAKE_BINARY_DIR}/g2.dat\" \"${ROOT_DIR}/resources/g2/sprites.json\" - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} -) -add_custom_target(g2 DEPENDS ${PROJECT_NAME} g2.dat) - -project(openrct2 CXX) +if (NOT (MACOS_BUNDLE AND (NOT CMAKE_OSX_ARCHITECTURES MATCHES "${SYSTEM_MACOS_ARCH}"))) + add_custom_command( + OUTPUT g2.dat + COMMAND ./openrct2-cli sprite build \"${CMAKE_BINARY_DIR}/g2.dat\" \"${ROOT_DIR}/resources/g2/sprites.json\" + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + add_custom_target(g2 DEPENDS ${PROJECT_NAME} g2.dat) +else () + message("Skipping g2.dat generation in macOS cross-compile") +endif () # Include tests if (WITH_TESTS) diff --git a/src/openrct2-ui/CMakeLists.txt b/src/openrct2-ui/CMakeLists.txt index ce14758338..953652bb98 100644 --- a/src/openrct2-ui/CMakeLists.txt +++ b/src/openrct2-ui/CMakeLists.txt @@ -35,6 +35,11 @@ file(GLOB_RECURSE OPENRCT2_UI_HEADERS if (APPLE) file(GLOB_RECURSE OPENRCT2_UI_MM_SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.mm") set_source_files_properties(${OPENRCT2_UI_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++ -fmodules") + if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm64") + # cross-compilation workaround for SDL2 + set(SDL_DISABLE_IMMINTRIN_H "-DSDL_DISABLE_IMMINTRIN_H") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL_DISABLE_IMMINTRIN_H}") + endif () endif () # Outputs @@ -141,7 +146,6 @@ if(MACOS_BUNDLE) target_sources(${PROJECT_NAME} PUBLIC ${ROOT_DIR}/distribution/readme.txt PUBLIC ${ROOT_DIR}/distribution/changelog.txt - PUBLIC ${CMAKE_BINARY_DIR}/g2.dat PUBLIC ${ROOT_DIR}/resources/mac/openrct2.icns ) @@ -149,10 +153,16 @@ if(MACOS_BUNDLE) set(BUNDLE_RESOURCES ${ROOT_DIR}/distribution/readme.txt ${ROOT_DIR}/distribution/changelog.txt - ${CMAKE_BINARY_DIR}/g2.dat ${ROOT_DIR}/resources/mac/openrct2.icns ) + if (CMAKE_OSX_ARCHITECTURES MATCHES "${SYSTEM_MACOS_ARCH}") + target_sources(${PROJECT_NAME} + PUBLIC ${CMAKE_BINARY_DIR}/g2.dat + ) + list(APPEND BUNDLE_RESOURCES ${CMAKE_BINARY_DIR}/g2.dat) + endif() + if(${OPENRCT2_BRANCH} EQUAL master) set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${OPENRCT2_VERSION_TAG}") From cac7438b041af479784c7b8d7bfed3f27334c9df Mon Sep 17 00:00:00 2001 From: adam-bloom Date: Sun, 12 Sep 2021 17:33:34 -0600 Subject: [PATCH 2/7] build arm/x64 macOS app bundles, make universal bundle --- .github/workflows/ci.yml | 60 +++++++++++++++++++++++++++++++--- scripts/create-macos-universal | 28 ++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) create mode 100755 scripts/create-macos-universal diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14fac2badb..d9f1d29f97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,21 +146,35 @@ jobs: echo 'Not going to push build' fi macos-cmake: - name: macOS (x64) using CMake + name: macOS using CMake runs-on: macos-latest needs: check-code-formatting + strategy: + fail-fast: false + matrix: + arch: [x86_64, arm64] + include: + - arch: x86_64 + cache_key: macos-x64 + build_flags: -DARCH="x86_64" -DWITH_TESTS=on + run_tests: true + - arch: arm64 + cache_key: macos-arm64 + build_flags: -DARCH="arm64" + run_tests: false steps: - name: Checkout uses: actions/checkout@v2 - name: ccache uses: hendrikmuhs/ccache-action@v1 with: - key: macos + key: ${{ matrix.cache_key }} - name: Build OpenRCT2 run: | HOMEBREW_NO_ANALYTICS=1 brew install ninja - . scripts/setenv -q && build -DWITH_TESTS=on -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=on + . scripts/setenv -q && build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=on ${{ matrix.build_flags }} - name: Run Tests + if: ${{matrix.run_tests}} run: . scripts/setenv -q && run-tests - name: Build artifacts run: | @@ -173,7 +187,45 @@ jobs: - name: Upload artifacts (CI) uses: actions/upload-artifact@v2 with: - name: OpenRCT2-${{ runner.os }}-cmake + name: OpenRCT2-${{ runner.os }}-${{ matrix.arch }}-cmake + path: artifacts/openrct2-macos.zip + if-no-files-found: error + macos-universal: + name: macOS universal app bundle + runs-on: macos-latest + needs: macos-cmake + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: download x64 app bundle + uses: actions/download-artifact@v2 + with: + name: OpenRCT2-${{ runner.os }}-x86_64-cmake + path: macos_universal/x64 + - name: download arm64 app bundle + uses: actions/download-artifact@v2 + with: + name: OpenRCT2-${{ runner.os }}-arm64-cmake + path: macos_universal/arm64 + - name: Make Universal app bundle + run: | + . scripts/setenv + cd macos_universal + unzip x64/openrct2-macos.zip -d x64 + unzip arm64/openrct2-macos.zip -d arm64 + create-macos-universal + - name: Create artifact + run: | + . scripts/setenv + mkdir -p artifacts + mv macos_universal/OpenRCT2-universal.app artifacts/OpenRCT2.app + echo -e "\033[0;36mCompressing OpenRCT2.app...\033[0m" + cd artifacts + zip -rqy openrct2-macos.zip OpenRCT2.app + - name: Upload artifacts (CI) + uses: actions/upload-artifact@v2 + with: + name: OpenRCT2-${{ runner.os }}-universal path: artifacts/openrct2-macos.zip if-no-files-found: error linux-portable: diff --git a/scripts/create-macos-universal b/scripts/create-macos-universal new file mode 100755 index 0000000000..2b8f94a412 --- /dev/null +++ b/scripts/create-macos-universal @@ -0,0 +1,28 @@ +#!/bin/bash -e + +echo "Creating macOS universal app bundle" +# create app skeleton +mkdir OpenRCT2-universal.app +mkdir OpenRCT2-universal.app/Contents + +# copy all resources (most will overwrite) +mkdir OpenRCT2-universal.app/Contents/Resources +# Note: g2.dat is expected to only be in one (matching OS of build machine) +rsync -ah x64/OpenRCT2.app/Contents/Resources/* OpenRCT2-universal.app/Contents/Resources/ +rsync -ah arm64/OpenRCT2.app/Contents/Resources/* OpenRCT2-universal.app/Contents/Resources/ + +# create a universal binary +mkdir OpenRCT2-universal.app/Contents/MacOS +lipo -create x64/OpenRCT2.app/Contents/MacOS/OpenRCT2 arm64/OpenRCT2.app/Contents/MacOS/OpenRCT2 -output OpenRCT2-universal.app/Contents/MacOS/OpenRCT2 + +# copy frameworks +mkdir OpenRCT2-universal.app/Contents/Frameworks +# with the exception of libopenrct2.dylib, the Frameworks are identical and are already universal dylibs +rsync -ah --exclude 'libopenrct2.dylib' x64/OpenRCT2.app/Contents/Frameworks/* OpenRCT2-universal.app/Contents/Frameworks +lipo -create x64/OpenRCT2.app/Contents/Frameworks/libopenrct2.dylib arm64/OpenRCT2.app/Contents/Frameworks/libopenrct2.dylib -output OpenRCT2-universal.app/Contents/Frameworks/libopenrct2.dylib + +# handle Info.plist +defaults import $PWD/OpenRCT2-universal.app/Contents/Info $PWD/x64/OpenRCT2.app/Contents/Info.plist $PWD/arm64/OpenRCT2.app/Contents/Info.plist +arm64_min_ver=$(defaults read $PWD/arm64/OpenRCT2.app/Contents/Info LSMinimumSystemVersion) +x64_min_ver=$(defaults read $PWD/x64/OpenRCT2.app/Contents/Info LSMinimumSystemVersion) +defaults write $PWD/OpenRCT2-universal.app/Contents/Info LSMinimumSystemVersionByArchitecture -dict x86_64 ${x64_min_ver} arm64 ${arm64_min_ver} From 3f7a69e1f76e37d3d6b05d80bf9624726c36f3b3 Mon Sep 17 00:00:00 2001 From: adam-bloom Date: Wed, 15 Sep 2021 20:33:14 -0600 Subject: [PATCH 3/7] rename CI job to match original naming convention --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9f1d29f97..1f132cb78c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,16 +146,18 @@ jobs: echo 'Not going to push build' fi macos-cmake: - name: macOS using CMake + name: macOS (${{ matrix.arch }}) using CMake runs-on: macos-latest needs: check-code-formatting strategy: fail-fast: false matrix: - arch: [x86_64, arm64] + arch: [x64, arm64] include: - - arch: x86_64 + - arch: x64 cache_key: macos-x64 + # Note: only build/run tests on the native architecture of the CI agent + # Github macos-latest agents are currently all Intel build_flags: -DARCH="x86_64" -DWITH_TESTS=on run_tests: true - arch: arm64 @@ -200,7 +202,7 @@ jobs: - name: download x64 app bundle uses: actions/download-artifact@v2 with: - name: OpenRCT2-${{ runner.os }}-x86_64-cmake + name: OpenRCT2-${{ runner.os }}-x64-cmake path: macos_universal/x64 - name: download arm64 app bundle uses: actions/download-artifact@v2 From 9dc065c2a70c7276826db2cfc7ba09e54a1a3667 Mon Sep 17 00:00:00 2001 From: adam-bloom Date: Wed, 15 Sep 2021 20:34:26 -0600 Subject: [PATCH 4/7] edit contributors --- contributors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.md b/contributors.md index 34c3d18bde..2562ce29e3 100644 --- a/contributors.md +++ b/contributors.md @@ -189,6 +189,7 @@ The following people are not part of the development team, but have been contrib * Michał Janiszewski (janisozaur) - Linux, Travis CI * Lewis Fox (LRFLEW) - macOS * Andrew Rimpici (Andy608) - macOS +* Adam Bloom (adam-bloom) - macOS, CI ## Documentation * (honzi) From ab1b0449257384984de2cfd40cc73ebd6f11b334 Mon Sep 17 00:00:00 2001 From: adam-bloom Date: Wed, 15 Sep 2021 20:35:59 -0600 Subject: [PATCH 5/7] Fix #13524: add changelog entry --- distribution/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 744d2249c1..d1fb7b809e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -35,6 +35,7 @@ - Fix: [#15503] Freeze when doing specific coaster merges with block brakes. - Fix: [#15514] Two different “quit to menu” menu items are available in track designer and track design manager. - Improved: [#3417] Crash dumps are now placed in their own folder. +- Improved: [#13524] macOS arm64 native (universal) app - Improved: [#15538] Software rendering can now draw in parallel when Multithreading is enabled. - Change: [#8601] Revert ToonTower base block fix to re-enable support blocking. - Change: [#15174] [Plugin] Deprecate the type "peep" and add support to target a specific scripting api version. From 793eba68d1bb9c1a114fd49ef98c69b5eeeaed44 Mon Sep 17 00:00:00 2001 From: adam-bloom Date: Sat, 25 Sep 2021 14:31:35 -0600 Subject: [PATCH 6/7] add additional comments on SDL resolution --- src/openrct2-ui/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/openrct2-ui/CMakeLists.txt b/src/openrct2-ui/CMakeLists.txt index 953652bb98..e1545cbd4b 100644 --- a/src/openrct2-ui/CMakeLists.txt +++ b/src/openrct2-ui/CMakeLists.txt @@ -37,6 +37,12 @@ if (APPLE) set_source_files_properties(${OPENRCT2_UI_MM_SOURCES} PROPERTIES COMPILE_FLAGS "-x objective-c++ -fmodules") if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm64") # cross-compilation workaround for SDL2 + # This has been addressed upstream in https://github.com/libsdl-org/SDL/commit/bf1d7a3a15a6c090188974bec8ca84eb1903d4f7 + # Remove this workaround after: + # 1) a new SDL release is made containing that fix + # 2) The vcpkg port is updated to use that release + # 3) A new Dependencies release is made with that latest vcpkg version + # 4) That new release is used in this build set(SDL_DISABLE_IMMINTRIN_H "-DSDL_DISABLE_IMMINTRIN_H") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SDL_DISABLE_IMMINTRIN_H}") endif () From bd99738e3c697241a0b860ea874f0fafca5f2010 Mon Sep 17 00:00:00 2001 From: adam-bloom Date: Fri, 8 Oct 2021 16:09:25 -0600 Subject: [PATCH 7/7] use new v29 release --- CMakeLists.txt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee40b371fc..b422d41619 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,16 +125,11 @@ if (MACOS_USE_DEPENDENCIES) # if we're building on macOS, then we need the dependencies include(cmake/download.cmake) - # TODO - change back before merging - # set(MACOS_DYLIBS_VERSION "28") - # set(MACOS_DYLIBS_ZIPFILE "openrct2-libs-v${MACOS_DYLIBS_VERSION}-x64-macos-dylibs.zip") - # set(MACOS_DYLIBS_SHA1 "29e5480376cf4ac5943f114387e32685204c8b78") - set(MACOS_DYLIBS_VERSION "29-alpha2") + set(MACOS_DYLIBS_VERSION "29") set(MACOS_DYLIBS_ZIPFILE "openrct2-libs-v${MACOS_DYLIBS_VERSION}-universal-macos-dylibs.zip") - set(MACOS_DYLIBS_SHA1 "bb8899c4120f1add232af7f9ac774ea622e01ad3") + set(MACOS_DYLIBS_SHA1 "86cf2db4d87173112a00042418d0d18cae360e41") set(MACOS_DYLIBS_DIR "${ROOT_DIR}/lib/macos") - # set(MACOS_DYLIBS_URL "https://github.com/OpenRCT2/Dependencies/releases/download/v${MACOS_DYLIBS_VERSION}/${MACOS_DYLIBS_ZIPFILE}") - set(MACOS_DYLIBS_URL "https://github.com/adam-bloom/Dependencies/releases/download/v${MACOS_DYLIBS_VERSION}/${MACOS_DYLIBS_ZIPFILE}") + set(MACOS_DYLIBS_URL "https://github.com/OpenRCT2/Dependencies/releases/download/v${MACOS_DYLIBS_VERSION}/${MACOS_DYLIBS_ZIPFILE}") download_openrct2_zip( ZIP_VERSION ${MACOS_DYLIBS_VERSION}