Skip to content

Commit

Permalink
Support Apple Clang and fix building on macOS Sonoma
Browse files Browse the repository at this point in the history
  • Loading branch information
nastys committed Aug 8, 2023
1 parent edf4f7e commit 7751b63
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
63 changes: 47 additions & 16 deletions .ci/build-mac.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
#!/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 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
fi

#export MACOSX_DEPLOYMENT_TARGET=12.0
export CXX=clang++
export CC=clang
Expand All @@ -28,8 +42,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
git clone https://github.com/engnr/qt-downloader.git
cd qt-downloader
git checkout f52efee0f18668c6d6de2dec0234b8c4bc54c597
Expand All @@ -45,27 +64,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
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"
#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"
#endif

#include <IOKit/pwr_mgt/IOPMLib.h>

static IOPMAssertionID s_pm_assertion = kIOPMNullAssertionID;
Expand Down

0 comments on commit 7751b63

Please sign in to comment.