diff --git a/.ci/build-mac-arm64.sh b/.ci/build-mac-arm64.sh new file mode 100755 index 000000000000..bd856f48977a --- /dev/null +++ b/.ci/build-mac-arm64.sh @@ -0,0 +1,134 @@ +#!/bin/sh -ex + +brew_arm64_install_packages() { + for pkg in "$@"; do + echo "Fetching bottle for $pkg..." + "$BREW_ARM64_PATH/bin/brew" fetch --force --bottle-tag=arm64_monterey "$pkg" + if [ $? -ne 0 ]; then + echo "Failed to fetch bottle for $pkg" + return 1 + fi + + echo "Installing $pkg..." + "$BREW_ARM64_PATH/bin/brew" install --ignore-dependencies $("$BREW_ARM64_PATH/bin/brew" --cache --bottle-tag=arm64_monterey "$pkg") || true + done +} + +export HOMEBREW_NO_AUTO_UPDATE=1 +export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 +export HOMEBREW_NO_INSTALL_CLEANUP=1 +export BREW_ARM64_PATH="/opt/homebrew1" + +sudo mkdir -p "$BREW_ARM64_PATH" +sudo chmod 777 "$BREW_ARM64_PATH" +curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C "$BREW_ARM64_PATH" + +brew_arm64_install_packages 0mq aom aribb24 ca-certificates cjson curl dav1d ffmpeg@5 fontconfig freetype freetype2 gettext glew gmp gnutls lame libbluray libidn2 libnettle libogg libpng librist libsodium libsoxr libtasn libtasn1 libunistring libvmaf libvorbis libvpx libx11 libxau libxcb libxdmcp llvm@18 mbedtls molten-vk nettle opencore-amr openjpeg openssl opus p11-kit pkg-config pkgconfig pzstd rav1e sdl2 snappy speex srt svt-av1 theora vulkan-headers webp x264 x265 xz z3 zeromq zmq zstd + +/usr/local/bin/brew install -f --overwrite nasm ninja p7zip ccache pipenv #create-dmg +/usr/local/bin/brew install llvm@18 cmake +/usr/local/bin/brew link -f llvm@18 + +# moltenvk based on commit for 1.2.10 release +wget https://raw.githubusercontent.com/Homebrew/homebrew-core/0d9f25fbd1658e975d00bd0e8cccd20a0c2cb74b/Formula/m/molten-vk.rb +/usr/local/bin/brew install -f --overwrite ./molten-vk.rb +#export MACOSX_DEPLOYMENT_TARGET=12.0 +export CXX=clang++ +export CC=clang + +export BREW_PATH; +BREW_PATH="$(brew --prefix)" +export BREW_X64_PATH; +BREW_X64_PATH="$("/usr/local/bin/brew" --prefix)" +export BREW_BIN="/usr/local/bin" +export BREW_SBIN="/usr/local/sbin" +export CMAKE_EXTRA_OPTS='-DLLVM_TARGETS_TO_BUILD=arm64' + +export WORKDIR; +WORKDIR="$(pwd)" + +# Get Qt +if [ ! -d "/tmp/Qt/$QT_VER" ]; then + mkdir -p "/tmp/Qt" + git clone https://github.com/engnr/qt-downloader.git + cd qt-downloader + git checkout f52efee0f18668c6d6de2dec0234b8c4bc54c597 + cd "/tmp/Qt" + "$BREW_X64_PATH/bin/pipenv" run pip3 install py7zr requests semantic_version lxml + mkdir -p "$QT_VER/macos" ; ln -s "macos" "$QT_VER/clang_64" + "$BREW_X64_PATH/bin/pipenv" run "$WORKDIR/qt-downloader/qt-downloader" macos desktop "$QT_VER" clang_64 --opensource --addons qtmultimedia +#fi + +cd "$WORKDIR" +ditto "/tmp/Qt/$QT_VER" "qt-downloader/$QT_VER" + +export Qt6_DIR="$WORKDIR/qt-downloader/$QT_VER/clang_64/lib/cmake/Qt$QT_VER_MAIN" +export SDL2_DIR="$BREW_ARM64_PATH/opt/sdl2/lib/cmake/SDL2" + +export PATH="$BREW_X64_PATH/opt/llvm@18/bin:$WORKDIR/qt-downloader/$QT_VER/clang_64/bin:$BREW_BIN:$BREW_SBIN:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:$PATH" +export LDFLAGS="-L$BREW_ARM64_PATH/lib $BREW_ARM64_PATH/opt/ffmpeg@5/lib/libavcodec.dylib $BREW_ARM64_PATH/opt/ffmpeg@5/lib/libavformat.dylib $BREW_ARM64_PATH/opt/ffmpeg@5/lib/libavutil.dylib $BREW_ARM64_PATH/opt/ffmpeg@5/lib/libswscale.dylib $BREW_ARM64_PATH/opt/ffmpeg@5/lib/libswresample.dylib $BREW_ARM64_PATH/opt/llvm@18/lib/c++/libc++.1.dylib $BREW_ARM64_PATH/lib/libSDL2.dylib /opt/homebrew/lib/libGLEW.dylib $BREW_ARM64_PATH/opt/llvm@18/lib/libunwind.1.dylib -Wl,-rpath,$BREW_ARM64_PATH/lib" +export CPPFLAGS="-I$BREW_ARM64_PATH/include -no-pie" +export LIBRARY_PATH="$BREW_ARM64_PATH/lib" +export LD_LIBRARY_PATH="$BREW_ARM64_PATH/lib" + +export VULKAN_SDK +VULKAN_SDK="$BREW_ARM64_PATH/opt/molten-vk" +ln -s "$VULKAN_SDK/lib/libMoltenVK.dylib" "$VULKAN_SDK/lib/libvulkan.dylib" || true +export VK_ICD_FILENAMES="$VULKAN_SDK/share/vulkan/icd.d/MoltenVK_icd.json" + +export LLVM_DIR +LLVM_DIR="$BREW_ARM64_PATH/opt/llvm@18" +# exclude ffmpeg, SPIRV and LLVM, and sdl from submodule update +# shellcheck disable=SC2046 +git submodule -q update --init --depth=1 --jobs=8 $(awk '/path/ && !/ffmpeg/ && !/llvm/ && !/SPIRV/ && !/SDL/ { print $3 }' .gitmodules) + +# 3rdparty fixes +sed -i '' "s/extern const double NSAppKitVersionNumber;/const double NSAppKitVersionNumber = 1343;/g" 3rdparty/hidapi/hidapi/mac/hid.c + +rm -rf build +mkdir build && cd build || exit 1 + +export CXXFLAGS="-DSDL_DISABLE_IMMINTRIN_H=1 -DSDL_DISABLE_MMINTRIN_H=1 -DSDL_DISABLE_XMMINTRIN_H=1 -DSDL_DISABLE_EMMINTRIN_H=1 -DSDL_DISABLE_PMMINTRIN_H=1" +export CFLAGS="-DSDL_DISABLE_IMMINTRIN_H=1 -DSDL_DISABLE_MMINTRIN_H=1 -DSDL_DISABLE_XMMINTRIN_H=1 -DSDL_DISABLE_EMMINTRIN_H=1 -DSDL_DISABLE_PMMINTRIN_H=1" +export CMAKE_SYSTEM_PROCESSOR=arm64 + +"$BREW_X64_PATH/bin/cmake" .. \ + -DUSE_SDL=ON \ + -DUSE_DISCORD_RPC=OFF \ + -DUSE_VULKAN=ON \ + -DUSE_ALSA=OFF \ + -DUSE_PULSE=OFF \ + -DUSE_AUDIOUNIT=ON \ + -DUSE_SYSTEM_FFMPEG=ON \ + -DLLVM_CCACHE_BUILD=OFF \ + -DLLVM_BUILD_RUNTIME=OFF \ + -DLLVM_BUILD_TOOLS=OFF \ + -DLLVM_INCLUDE_DOCS=OFF \ + -DLLVM_INCLUDE_EXAMPLES=OFF \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_INCLUDE_TOOLS=OFF \ + -DLLVM_INCLUDE_UTILS=OFF \ + -DLLVM_USE_PERF=OFF \ + -DLLVM_ENABLE_Z3_SOLVER=OFF \ + -DUSE_NATIVE_INSTRUCTIONS=OFF \ + -DUSE_SYSTEM_MVK=ON \ + -DUSE_SYSTEM_FAUDIO=OFF \ + -DUSE_SYSTEM_SDL=ON \ + $CMAKE_EXTRA_OPTS \ + -DLLVM_TARGET_ARCH=arm64 \ + -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DCMAKE_IGNORE_PATH="$BREW_X64_PATH/lib" \ + -DCMAKE_SYSTEM_PROCESSOR=arm64 \ + -DCMAKE_TOOLCHAIN_FILE=buildfiles/cmake/TCDarwinARM64.cmake \ + -G Ninja + +"$BREW_PATH/bin/ninja"; build_status=$?; + +cd .. + +{ [ "$CI_HAS_ARTIFACTS" = "true" ]; +} && SHOULD_DEPLOY="true" || SHOULD_DEPLOY="false" + +if [ "$build_status" -eq 0 ] && [ "$SHOULD_DEPLOY" = "true" ]; then + .ci/deploy-mac-arm64.sh +fi diff --git a/.ci/deploy-mac-arm64.sh b/.ci/deploy-mac-arm64.sh new file mode 100755 index 000000000000..e7fb8241f3fc --- /dev/null +++ b/.ci/deploy-mac-arm64.sh @@ -0,0 +1,62 @@ +#!/bin/sh -ex + +cd build || exit 1 + +# Gather explicit version number and number of commits +COMM_TAG=$(awk '/version{.*}/ { printf("%d.%d.%d", $5, $6, $7) }' ../rpcs3/rpcs3_version.cpp) +COMM_COUNT=$(git rev-list --count HEAD) +COMM_HASH=$(git rev-parse --short=8 HEAD) + +AVVER="${COMM_TAG}-${COMM_COUNT}" + +# AVVER is used for GitHub releases, it is the version number. +echo "AVVER=$AVVER" >> ../.ci/ci-vars.env + +cd bin +mkdir "rpcs3.app/Contents/lib/" || true + +cp "$(realpath /opt/homebrew/opt/llvm@18/lib/c++/libc++abi.1.0.dylib)" "rpcs3.app/Contents/Frameworks/libc++abi.1.dylib" +cp "$(realpath /opt/homebrew/lib/libsharpyuv.0.dylib)" "rpcs3.app/Contents/lib/libsharpyuv.0.dylib" +cp "$(realpath /opt/homebrew/lib/libintl.8.dylib)" "rpcs3.app/Contents/lib/libintl.8.dylib" + +rm -rf "rpcs3.app/Contents/Frameworks/QtPdf.framework" \ +"rpcs3.app/Contents/Frameworks/QtQml.framework" \ +"rpcs3.app/Contents/Frameworks/QtQmlModels.framework" \ +"rpcs3.app/Contents/Frameworks/QtQuick.framework" \ +"rpcs3.app/Contents/Frameworks/QtVirtualKeyboard.framework" \ +"rpcs3.app/Contents/Plugins/platforminputcontexts" \ +"rpcs3.app/Contents/Plugins/virtualkeyboard" \ +"rpcs3.app/Contents/Resources/git" + +# Need to do this rename hack due to case insensitive filesystem +mv rpcs3.app RPCS3_.app +mv RPCS3_.app RPCS3.app + +echo "[InternetShortcut]" > Quickstart.url +echo "URL=https://rpcs3.net/quickstart" >> Quickstart.url +echo "IconIndex=0" >> Quickstart.url + +#DMG_FILEPATH="$BUILD_ARTIFACTSTAGINGDIRECTORY/rpcs3-v${COMM_TAG}-${COMM_COUNT}-${COMM_HASH}_macos_arm64.dmg" +#"$BREW_X64_PATH/bin/create-dmg" --volname RPCS3 \ +#--window-size 800 400 \ +#--icon-size 100 \ +#--icon rpcs3.app 200 190 \ +#--add-file Quickstart.url Quickstart.url 400 20 \ +#--hide-extension rpcs3.app \ +#--hide-extension Quickstart.url \ +#--app-drop-link 600 185 \ +#--skip-jenkins \ +#--format ULMO \ +#"$DMG_FILEPATH" \ +#RPCS3.app +#FILESIZE=$(stat -f %z "$DMG_FILEPATH") +#SHA256SUM=$(shasum -a 256 "$DMG_FILEPATH" | awk '{ print $1 }') + +ARCHIVE_FILEPATH="$BUILD_ARTIFACTSTAGINGDIRECTORY/rpcs3-v${COMM_TAG}-${COMM_COUNT}-${COMM_HASH}_macos_arm64.7z" +"$BREW_X64_PATH/bin/7z" a -mx9 "$ARCHIVE_FILEPATH" RPCS3.app Quickstart.url +FILESIZE=$(stat -f %z "$ARCHIVE_FILEPATH") +SHA256SUM=$(shasum -a 256 "$ARCHIVE_FILEPATH" | awk '{ print $1 }') + +cd .. +echo "${SHA256SUM};${FILESIZE}B" > "$RELEASE_MESSAGE" +cd bin diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7072613a142f..7008b5a8567b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -180,3 +180,62 @@ jobs: displayName: Push build to GitHub env: RPCS3_TOKEN: $(RPCS3-Token) + +- job: Mac_Build_AppleSilicon + timeoutInMinutes: 180 + variables: + CCACHE_DIR: "/tmp/ccache_dir" + CCACHE_MAXSIZE: 300M + CI_HAS_ARTIFACTS: true + UPLOAD_COMMIT_HASH: 51ae32f468089a8169aaf1567de355ff4a3e0842 + UPLOAD_REPO_FULL_NAME: "RPCS3/rpcs3-binaries-mac" + RELEASE_MESSAGE: "../GitHubReleaseMessage.txt" + ARTDIR: $(Build.ArtifactStagingDirectory) + QT_VER: '6.6.3' + QT_VER_MAIN: '6' + + pool: + vmImage: "macOS-12" + + steps: + - task: Cache@2 + inputs: + key: ccache | "$(Agent.OS)" + path: $(CCACHE_DIR) + restoreKeys: | + ccache | "$(Agent.OS)" + displayName: Ccache cache + + - task: Cache@2 + inputs: + key: qt | "$(Agent.OS)" | "$(QT_VER)" + path: /tmp/Qt + restoreKeys: | + qt | "$(Agent.OS)" | "$(QT_VER)" + displayName: Qt cache + + - task: Cache@2 + inputs: + key: brew | "$(Agent.OS)" + path: /Users/runner/Library/Caches/Homebrew + restoreKeys: | + brew | "$(Agent.OS)" + displayName: Homebrew cache + + - bash: | + chmod +x ".ci/build-mac-arm64.sh" + chmod +x ".ci/deploy-mac-arm64.sh" + ".ci/build-mac-arm64.sh" + displayName: Build MacOS + + - publish: $(Build.ArtifactStagingDirectory) + condition: succeeded() + artifact: RPCS3 for Mac (Apple Silicon) + + - bash: | + source './.ci/export-cirrus-vars.sh' + .ci/github-upload.sh + condition: and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['Build.Repository.Name'], 'RPCS3/rpcs3'), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + displayName: Push build to GitHub + env: + RPCS3_TOKEN: $(RPCS3-Token) \ No newline at end of file diff --git a/buildfiles/cmake/TCDarwinARM64.cmake b/buildfiles/cmake/TCDarwinARM64.cmake new file mode 100644 index 000000000000..d38b2379108a --- /dev/null +++ b/buildfiles/cmake/TCDarwinARM64.cmake @@ -0,0 +1,2 @@ +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_PROCESSOR arm64)