Skip to content

Commit

Permalink
ci: build macOS on GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Dec 9, 2024
1 parent e326876 commit ffef021
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 5 deletions.
34 changes: 34 additions & 0 deletions .CI/MacDeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,37 @@ if [ -n "$MACOS_CODESIGN_CERTIFICATE" ]; then
# Validate that chatterino.app was codesigned correctly
codesign -v chatterino.app
fi

# Copy dynamic library dependencies into the Frameworks directory
cp /opt/universal-lib/libcrypto.dylib chatterino.app/Contents/Frameworks/libcrypto.3.dylib
cp /opt/universal-lib/libssl.dylib chatterino.app/Contents/Frameworks/libssl.3.dylib

# Fix the library IDs to match their new location
install_name_tool -id @executable_path/../Frameworks/libssl.3.dylib chatterino.app/Contents/Frameworks/libssl.3.dylib
install_name_tool -id @executable_path/../Frameworks/libcrypto.3.dylib chatterino.app/Contents/Frameworks/libcrypto.3.dylib

otool -L chatterino.app/Contents/Frameworks/libssl.3.dylib
# Fix the search path for libcrypto in libssl
otool -L chatterino.app/Contents/Frameworks/libssl.3.dylib \
| grep libcrypto.3.dylib \
| cut -d" " -f1 \
| cut -f2 \
| while read input_crypto_dylib; do \
install_name_tool -change \
"$input_crypto_dylib" \
@executable_path/../Frameworks/libcrypto.3.dylib \
chatterino.app/Contents/Frameworks/libssl.3.dylib; \
done
# Fix the search path for lib{crypto,ssl} in chatterino
otool -L chatterino.app/Contents/MacOS/chatterino \
| grep /opt \
| cut -d" " -f1 \
| cut -f2 \
| while read og_entry; do \
echo $og_entry; \
install_name_tool -change \
"$og_entry" \
@executable_path/../Frameworks/$(echo $og_entry | sed -E 's/.*(libssl|libcrypto)/\1/') \
chatterino.app/Contents/MacOS/chatterino; \
done

82 changes: 82 additions & 0 deletions .CI/SetupHomebrewDeps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash

set -e

# Prefix for where to find the ARM64 library
arm64_homebrew_dir="/opt/homebrew"
# Prefix for where to find the x86 library
x86_64_homebrew_dir="/opt/homebrew-x86_64"
# Directory where we place the finished universal library
universal_lib_dir="/opt/universal-lib"

# args: path-to-library (in homebrew dir)
c2-make-universal-dylib() {
local _input_lib="$1"
if [ -z "${_input_lib}" ]; then
echo "usage: $0 [lib-path-relative-to-homebrew] (e.g. $0 lib/libboost_random-mt.dylib)"
exit 1
fi

if [ ! -w "${universal_lib_dir}" ]; then
echo "error: The current user does not have write permission in the universal lib directory (${universal_lib_dir})"
exit 1
fi

local _input_lib_filename="$(basename "${_input_lib}")"

local _arm64_lib="${arm64_homebrew_dir}/${_input_lib}"
local _x86_64_lib="${x86_64_homebrew_dir}/${_input_lib}"
local _override_lib=$(realpath "${arm64_homebrew_dir}/${_input_lib}")

local _universal_lib="${universal_lib_dir}/${_input_lib_filename}"

if [ ! -f "${_arm64_lib}" ]; then
echo "error: The ARM64 library '${_input_lib}' cannot be found at '${_arm64_lib}'"
exit 1
fi

if [ ! -f "${_x86_64_lib}" ]; then
echo "error: The x86_64 library '${_input_lib}' cannot be found at '${_x86_64_lib}'"
exit 1
fi

# Create the combined library
if ! lipo "${_arm64_lib}" "${_x86_64_lib}" -create -output "${_universal_lib}"; then
echo "error: Something went wrong creating the combined library"
echo "Some errors can be solved by re-linking the original libraries (e.g. brew link --overwrite boost)"
exit 1
fi

echo "Created the combined library at '${_universal_lib}"

# Override
rm -v "${_override_lib}"
ln -v -s "${_universal_lib}" "${_override_lib}"
}

sudo mkdir "$x86_64_homebrew_dir"
sudo mkdir "$universal_lib_dir"

sudo chown -R $USER "$universal_lib_dir"

echo "Installing x86_64 brew"
sudo curl -L https://github.com/Homebrew/brew/tarball/master | sudo tar xz --strip 1 -C "$x86_64_homebrew_dir"
sudo chown -R $USER "$x86_64_homebrew_dir"

echo "Installing ARM dependencies"
brew install "$@"

echo "Installing x86_64 dependencies"
for dep in "$@"
do
arch -x86_64 "$x86_64_homebrew_dir/bin/brew" fetch --force --bottle-tag=x86_64_ventura "$dep"
arch -x86_64 "$x86_64_homebrew_dir/bin/brew" install $(arch -x86_64 "$x86_64_homebrew_dir/bin/brew" --cache --bottle-tag=x86_64_ventura "$dep")
done

echo "Relinking boost libraries"
c2-make-universal-dylib lib/libboost_random-mt.dylib

echo "Relinking OpenSSL 3 libcrypto"
c2-make-universal-dylib lib/libcrypto.dylib
echo "Relinking OpenSSL 3 libssl"
c2-make-universal-dylib lib/libssl.dylib
40 changes: 35 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,16 @@ jobs:
strategy:
matrix:
include:
# macOS
- os: macos-13
qt-version: 5.15.2
# macOS (for 10.15)
- os: macos-latest
qt-version: 6.4.3
force-lto: false
plugins: true
skip-artifact: false
skip-crashpad: false
# macOS (for newer versions)
- os: macos-latest
qt-version: 6.7.0
force-lto: false
plugins: true
skip-artifact: false
Expand Down Expand Up @@ -294,7 +301,10 @@ jobs:
- name: Install dependencies (MacOS)
if: startsWith(matrix.os, 'macos')
run: |
brew install boost openssl rapidjson p7zip create-dmg cmake tree
# binary dependencies
./.CI/SetupHomebrewDeps.sh boost openssl@3
# build and header-only dependencies
brew install rapidjson p7zip create-dmg cmake tree
shell: bash

- name: Build (MacOS)
Expand All @@ -305,11 +315,11 @@ jobs:
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 \
-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
-DUSE_PRECOMPILED_HEADERS=OFF \
-DCHATTERINO_LTO="$C2_ENABLE_LTO" \
-DCHATTERINO_PLUGINS="$C2_PLUGINS" \
-DBUILD_WITH_QT6="$C2_BUILD_WITH_QT6" \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
..
make -j"$(sysctl -n hw.logicalcpu)"
shell: bash
Expand All @@ -323,6 +333,9 @@ jobs:
pwd
ls -la build || true
cd build
export MACOS_CODESIGN_CERTIFICATE="-"
echo "cert: '$MACOS_CODESIGN_CERTIFICATE'"
./../.CI/MacDeploy.sh
./../.CI/CreateDMG.sh
shell: bash
Expand Down Expand Up @@ -388,6 +401,19 @@ jobs:
name: Chatterino-ubuntu-24.04-Qt-6.7.2.deb
path: release-artifacts/

# macOS
- uses: actions/download-artifact@v4
name: macOS Qt 6.4.3
with:
name: chatterino-macos-Qt-6.4.3.dmg
path: release-artifacts/

- uses: actions/download-artifact@v4
name: macOS Qt 6.7.0
with:
name: chatterino-macos-Qt-6.7.0.dmg
path: release-artifacts/

- name: Copy flatpakref
run: |
cp .CI/chatterino-nightly.flatpakref release-artifacts/
Expand All @@ -399,6 +425,10 @@ jobs:
# Mark all Windows Qt5 builds as old
mv chatterino-windows-x86-64-Qt-5.15.2.zip chatterino-windows-old-x86-64-Qt-5.15.2.zip
# Mark Qt 6.4 macos build as old
mv chatterino-macos-Qt-6.4.3.dmg Chatterino-10.15.dmg
mv chatterino-macos-Qt-6.7.0.dmg Chatterino.dmg
working-directory: release-artifacts
shell: bash

Expand Down

0 comments on commit ffef021

Please sign in to comment.