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

Support Apple Clang and fix building on macOS Sonoma #14452

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
62 changes: 46 additions & 16 deletions .ci/build-mac.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
#!/bin/sh -ex

export HOMEBREW_NO_AUTO_UPDATE=1
brew install -f --overwrite nasm ninja git p7zip create-dmg ccache pipenv

#/usr/sbin/softwareupdate --install-rosetta --agree-to-license
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
arch -x86_64 /usr/local/bin/brew update
arch -x86_64 /usr/local/bin/brew install -f --overwrite llvm@16 glew cmake sdl2 vulkan-headers ffmpeg
arch -x86_64 /usr/local/bin/brew link -f llvm@16

# moltenvk based on commit for 1.2.4 release
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/b233d4f9f40f26d81da11140defbfd578cfe4a69/Formula/molten-vk.rb
arch -x86_64 /usr/local/bin/brew install -f --overwrite ./molten-vk.rb
if [ "$(arch -x86_64 echo test)" = "test" ]; then
echo "Rosetta is installed or building on Intel"
else
echo "Installing Rosetta"
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
fi

if [ -z "$INSTALL_DEPS" ]; then
export INSTALL_DEPS="true"
fi

if [ "$INSTALL_DEPS" = "true" ] ; then
export HOMEBREW_NO_AUTO_UPDATE=1
brew -v || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install -f --overwrite nasm ninja git p7zip create-dmg ccache pipenv

arch -x86_64 /usr/local/bin/brew -v || arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
arch -x86_64 /usr/local/bin/brew install -f --overwrite llvm@16 glew cmake sdl2 vulkan-headers ffmpeg
arch -x86_64 /usr/local/bin/brew link -f llvm@16

# moltenvk based on commit for 1.2.4 release
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/b233d4f9f40f26d81da11140defbfd578cfe4a69/Formula/molten-vk.rb
arch -x86_64 /usr/local/bin/brew install -f --overwrite ./molten-vk.rb
fi

#export MACOSX_DEPLOYMENT_TARGET=12.0
export CXX=clang++
export CC=clang
Expand All @@ -28,8 +41,13 @@ export WORKDIR;
WORKDIR="$(pwd)"

# Get Qt
if [ -z "$QT_VER" ]; then
export QT_VER="6.5.2"
fi

if [ ! -d "/tmp/Qt/$QT_VER" ]; then
mkdir -p "/tmp/Qt"
rm -rf qt-downloader
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why thou?
Maybe it would be better to check if dir exists and is git repo.

git clone https://github.com/engnr/qt-downloader.git
cd qt-downloader
git checkout f52efee0f18668c6d6de2dec0234b8c4bc54c597
Expand All @@ -45,27 +63,39 @@ 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_X64_PATH/opt/sdl2/lib/cmake/SDL2"

export PATH="$BREW_X64_PATH/opt/llvm@16/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 PATH="$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"

if [ "$USE_APPLE_CLANG" = "true" ]; then
echo "Building using Apple Clang"
else
echo "Building using Homebrew Clang"
export PATH="$BREW_X64_PATH/opt/llvm@16/bin:$PATH"
fi

export LDFLAGS="-L$BREW_X64_PATH/lib -Wl,-rpath,$BREW_X64_PATH/lib"
export CPPFLAGS="-I$BREW_X64_PATH/include -msse -msse2 -mcx16 -no-pie"
export LIBRARY_PATH="$BREW_X64_PATH/lib"
export LD_LIBRARY_PATH="$BREW_X64_PATH/lib"

export VULKAN_SDK
VULKAN_SDK="$BREW_X64_PATH/opt/molten-vk"
ln -s "$VULKAN_SDK/lib/libMoltenVK.dylib" "$VULKAN_SDK/lib/libvulkan.dylib"
ln -s "$VULKAN_SDK/lib/libMoltenVK.dylib" "$VULKAN_SDK/lib/libvulkan.dylib" || echo "Using existing libvulkan.dylib"
export VK_ICD_FILENAMES="$VULKAN_SDK/share/vulkan/icd.d/MoltenVK_icd.json"

export LLVM_DIR
LLVM_DIR="BREW_X64_PATH/opt/llvm@16"
LLVM_DIR="$BREW_X64_PATH/opt/llvm@16"
# exclude FAudio, SPIRV and LLVM, and sdl from submodule update
# shellcheck disable=SC2046
git submodule -q update --init --depth=1 --jobs=8 $(awk '/path/ && !/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

mkdir build && cd build || exit 1
if [ "$CLEAN_BUILDDIR" = "true" ]; then
rm -rf build || echo "build directory not deleted"
fi

mkdir -p build && cd build || exit 1

"$BREW_X64_PATH/bin/cmake" .. \
-DUSE_SDL=ON \
Expand Down
4 changes: 3 additions & 1 deletion .ci/deploy-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ echo "AVVER=$AVVER" >> ../.ci/ci-vars.env
cd bin
mkdir "rpcs3.app/Contents/lib/"

cp "/usr/local/opt/llvm@16/lib/c++/libc++abi.1.0.dylib" "rpcs3.app/Contents/lib/libc++abi.1.dylib"
if [ "$USE_APPLE_CLANG" != "true" ]; then
cp "/usr/local/opt/llvm@16/lib/c++/libc++abi.1.0.dylib" "rpcs3.app/Contents/lib/libc++abi.1.dylib"
fi

rm -rf "rpcs3.app/Contents/Frameworks/QtPdf.framework" \
"rpcs3.app/Contents/Frameworks/QtQml.framework" \
Expand Down
3 changes: 3 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ macos_task:
UPLOAD_COMMIT_HASH: 51ae32f468089a8169aaf1567de355ff4a3e0842
UPLOAD_REPO_FULL_NAME: "rpcs3/rpcs3-binaries-mac"
RELEASE_MESSAGE: "../GitHubReleaseMessage.txt"
INSTALL_DEPS: true
USE_APPLE_CLANG: true
CLEAN_BUILDDIR: true
artifacts:
name: Artifact
path: "artifacts/*"
Expand Down
4 changes: 4 additions & 0 deletions darwin/util/sysinfo_darwin.mm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wold-style-cast"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to fix this by changing get<>Version methods to return static_cast<int>(osver.<>) instead of suppressing this warning.

#endif

#import <Foundation/Foundation.h>

namespace Darwin_Version
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/display_sleep_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <windows.h>

#elif defined(__APPLE__)
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wold-style-cast"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think You're Holding It Wrong.
https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
You need to push, then ignore and finally pop before #elif defined(HAVE_QTDBUS) line

#endif

#include <IOKit/pwr_mgt/IOPMLib.h>

static IOPMAssertionID s_pm_assertion = kIOPMNullAssertionID;
Expand Down