Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically build Apple ARM builds in CI #1300

Merged
merged 7 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,96 @@ jobs:
with:
files: ${{github.workspace}}/main/build/*.tar.gz

macos_aarch64:
name: macOS aarch64 ${{matrix.cfg.name}}
runs-on: ${{matrix.cfg.os}}
strategy:
fail-fast: false
matrix:
cfg:
- { os: macos-14, name: "Sonoma", dist: true }

steps:

- name: Checkout Etterna
uses: actions/checkout@v3
with:
path: main

- name: Checkout CrashpadTools
uses: actions/checkout@v3
with:
repository: etternagame/CrashpadTools
path: tools

- name: Install homebrew packages
run: brew install cmake nasm ninja openssl

- name: Setup Python 3
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Generate CMake
run: mkdir main/build && cd main/build && cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_CRASHPAD=OFF -G Ninja ..

- name: Build Project
run: cd main/build && ninja

- name: Generate binary
if: ${{matrix.cfg.dist}}
run: cd main/build && cpack

- name: Upload Binary
if: ${{matrix.cfg.dist}}
uses: actions/upload-artifact@v3
with:
name: "Etterna - macOS aarch64"
path: '${{github.workspace}}/main/build/*.dmg'

- name: Update Environment Variables
if: ${{matrix.cfg.dist}}
run: |
echo "${{github.workspace}}/tools/mac" >> $GITHUB_PATH
echo "ETTERNA_ARCH=aarch64" >> $GITHUB_ENV
- name: Generate Symbols
if: ${{matrix.cfg.dist}}
run: |
echo "Running dsymutil..."
dsymutil -o ${{github.workspace}}/main/Etterna.dsym main/Etterna.app/Contents/MacOS/Etterna > /dev/null
echo "Dumping Symbols..."
dump_syms ${{github.workspace}}/main/Etterna.dsym main/Etterna.app/Contents/MacOS/Etterna > ${{github.workspace}}/main/Etterna.sym
echo "Stripping debug symbols from binary..."
strip main/Etterna.app/Contents/MacOS/Etterna
- name: Prepare symbols for upload artifacts
if: ${{matrix.cfg.dist}}
run: cd main && ${{github.workspace}}/main/.ci/prepare_symbols.py

- name: Upload Symbols to action artifacts
if: ${{matrix.cfg.dist}}
uses: actions/upload-artifact@v3
with:
name: Etterna Symbols - ${{github.sha}}
path: '${{github.workspace}}/main/EtternaSymbolsUploadDir'

- name: Get version for CrashServer Upload
id: get_version
if: ${{ matrix.cfg.dist && github.event_name == 'release' && github.event.action == 'published' }}
run: |
echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Upload Symbols to Crash Server
if: ${{ matrix.cfg.dist && github.event_name == 'release' && github.event.action == 'published' }}
run: symupload ${{github.workspace}}/main/Etterna.sym "https://crash.etterna.dev/api/symbol/upload?api_key=${{secrets.CRASHSERVER_API_KEY}}&version=${{ steps.get_version.outputs.VERSION }}"

- name: Upload files to Release
uses: softprops/action-gh-release@v1
if: ${{ matrix.cfg.dist && github.event_name == 'release' && github.event.action == 'published' }}
with:
files: ${{github.workspace}}/main/build/*.dmg

macos:
name: macOS x64 ${{matrix.cfg.name}}
runs-on: ${{matrix.cfg.os}}
Expand Down
22 changes: 20 additions & 2 deletions CMake/Helpers/CMakeMacOS.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# TODO: Remove CPU_X86_64, CPU_X86, and CRASH_HANDLER
# CRASH_HANDLER is unnecessary as the game should have that as an option component
# CPU_X86_64, CPU_X86 already exists as compiler predefined macros. Use those instead.
list(APPEND cdefs _XOPEN_SOURCE CPU_X86_64 GL_SILENCE_DEPRECATION)

list(APPEND cdefs _XOPEN_SOURCE GL_SILENCE_DEPRECATION)
if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
list(APPEND cdefs CPU_X86_64)
endif()
set_target_properties(Etterna PROPERTIES COMPILE_DEFINITIONS "${cdefs}")

set_target_properties(Etterna PROPERTIES MACOSX_BUNDLE TRUE)
set(CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000")

if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
#TODO: Do we even need these on x86_64?
# For the ARM build, it breaks if they're present, and seems to work just fine without them...
# Seems to have made its way into this file eventually after 2d03a8163f5d10c6b569eb3c92543677c910e82e
# That commit appears to be copying part of luajit's CMakeLists, originating at f31f6eea7bf52400929fcfb303637741bb645818
# (https://github.com/LuaJIT/LuaJIT/commit/f31f6eea7bf52400929fcfb303637741bb645818)
# *That* appears to have originated from https://github.com/LuaJIT/LuaJIT/commit/f76e5a311ba543ae174acd3b585fb672fde8a3b5 which states
### /* OSX mmap() uses a naive first-fit linear search. That's perfect for us.
### ** But -pagezero_size must be set, otherwise the lower 4GB are blocked.
### */
set(CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000")
endif()

set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")

# Set AppBundle icon
Expand Down
15 changes: 11 additions & 4 deletions CMake/Helpers/SetupFFMPEG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ if (UNIX)
endif()

if(APPLE)
list(APPEND FFMPEG_CONFIGURE
"--arch=x86_64"
"--cc=clang -arch x86_64"
"--enable-sse")
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
list(APPEND FFMPEG_CONFIGURE
"--arch=arm64"
"--cc=clang -arch arm64"
"--enable-neon")
else()
list(APPEND FFMPEG_CONFIGURE
"--arch=x86_64"
"--cc=clang -arch x86_64"
"--enable-sse")
endif()
endif()
list(APPEND FFMPEG_CONFIGURE "--enable-gpl")
list(APPEND FFMPEG_CONFIGURE "--extra-cflags=-mmacosx-version-min=10.8 -w")
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ project(Etterna
set(CMAKE_CXX_STANDARD 20) # Minimum C++ Version
set(CMAKE_CXX_EXTENSIONS OFF) # True if compiler extensions are necessary. (Changes -std flag)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # True to require minimum C++ version to compile
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10) # Tell xcodebuild to target an older osx platform
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11) # First macOS version supporting M1 chips
else()
# Host is x86_64
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10) # Oldest platform we still support
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export compile commands for clang-tidy
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake/Modules) # Tell CMake where to access FindXXX.cmake files
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Enable folders/filters within IDEs
Expand Down Expand Up @@ -107,6 +112,10 @@ target_link_libraries(Etterna PRIVATE plog::plog)
target_link_libraries(Etterna PRIVATE nowide::nowide)
target_link_libraries(Etterna PRIVATE ghc_filesystem)

if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
target_link_libraries(Etterna PRIVATE sse2neon)
endif()

# If the user wants crashpad, and the target exists (in-case
# the user wants it, but crashpad couldn't find python)
if(WITH_CRASHPAD AND TARGET crashpad)
Expand Down
6 changes: 6 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ set(RAPIDJSON_BUILD_EXAMPLES OFF)
add_subdirectory(rapidjson)
add_subdirectory(stb)

if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
# Used for providing ARM's NEON equivalents of x86_64 SSE SIMD instructions
add_subdirectory(sse2neon)
endif()


set(JWT_SSL_LIBRARY OpenSSL)
add_subdirectory(jwt-cpp-0.6.0)

Expand Down
2 changes: 2 additions & 0 deletions extern/sse2neon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(sse2neon INTERFACE)
target_include_directories(sse2neon INTERFACE sse2neon)
11 changes: 11 additions & 0 deletions extern/sse2neon/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SSE2Neon is used by us to allow the calc to use x86_64 vector intrinsic
instructions on ARM64.

x86_64's SSE SIMD instrinsics are transparently replaced with equivalent
ARM Neon instructions by this header-only library.

The project is available at https://github.com/DLTcollab/sse2neon and is
MIT licensed.

This particular file was copied from the v1.7.0 release, available at
https://github.com/DLTcollab/sse2neon/releases/tag/v1.7.0
21 changes: 21 additions & 0 deletions extern/sse2neon/sse2neon/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2015-2023 SSE2NEON 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.
Loading
Loading