Skip to content

Commit 14d52e8

Browse files
authored
Merge pull request #40 from stream-labs/macos-arm64-support
macOS arm64 support
2 parents 9e8a3f9 + ea1212f commit 14d52e8

4 files changed

Lines changed: 187 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ jobs:
131131
build_macos:
132132
name: 'Build a package MacOS'
133133
runs-on: macos-latest
134+
strategy:
135+
matrix:
136+
arch: ['x86_64', 'arm64']
134137
steps:
135138
- uses: actions/checkout@v3
136139
- name: Show GitHub context
@@ -151,6 +154,7 @@ jobs:
151154
run: './ci/build-osx.sh'
152155
env:
153156
SENTRY_AUTH_TOKEN: ${{secrets.SENTRY_AUTH_TOKEN}}
157+
ARCHITECTURE: ${{matrix.arch}}
154158
- name: Put version into package.json
155159
if: startsWith(github.ref, 'refs/tags/')
156160
run: node ./ci/bump-version.js "${{ steps.get_version.outputs.VERSION }}" "${{env.PACKAGE_PATH}}"
@@ -160,12 +164,15 @@ jobs:
160164
uses: actions/cache@v3
161165
with:
162166
path: ${{env.BUILD_DIRECTORY}}
163-
key: ${{ runner.os }}-build-${{ github.sha }}
167+
key: ${{ runner.os }}-${{ matrix.arch }}-build-${{ github.sha }}
164168

165169
upload_release_package_macos:
166170
needs: build_macos
167171
name: 'Upload release package macos'
168172
runs-on: macos-latest
173+
strategy:
174+
matrix:
175+
arch: ['x86_64', 'arm64']
169176
if: startsWith(github.ref, 'refs/tags/')
170177
env:
171178
OS_TAG: "osx"
@@ -179,14 +186,14 @@ jobs:
179186
uses: actions/cache@v3
180187
with:
181188
path: ${{env.BUILD_DIRECTORY}}
182-
key: ${{ runner.os }}-build-${{ github.sha }}
189+
key: ${{ runner.os }}-${{ matrix.arch }}-build-${{ github.sha }}
183190
- name: Check cache
184191
if: steps.cache-check.outputs.cache-hit != 'true'
185192
run: exit 1
186193
- name: Tar artifact for deployment
187194
run: tar -cvzf ${{env.TARGET_ARTIFACT}}.tar.gz -C "${{env.INSTALL_DISTRIBUTE_PATH}}" ${{env.PACKAGE_DIRECTORY}}
188195
env:
189-
TARGET_ARTIFACT: ${{env.PACKAGE_NAME}}-${{ steps.get_version.outputs.VERSION }}-${{env.OS_TAG}}
196+
TARGET_ARTIFACT: ${{env.PACKAGE_NAME}}-${{ steps.get_version.outputs.VERSION }}-${{env.OS_TAG}}-${{ matrix.arch }}
190197
INSTALL_DISTRIBUTE_PATH: "${{env.BUILD_DIRECTORY}}/${{env.DISTRIBUTE_DIRECTORY}}"
191198
- name: Configure AWS credentials
192199
uses: aws-actions/configure-aws-credentials@v1
@@ -197,4 +204,4 @@ jobs:
197204
- name: Deploy
198205
run: aws s3 cp ${{env.TARGET_ARTIFACT}}.tar.gz s3://${{env.RELEASE_BUCKET}} --acl public-read
199206
env:
200-
TARGET_ARTIFACT: ${{env.PACKAGE_NAME}}-${{ steps.get_version.outputs.VERSION }}-${{env.OS_TAG}}
207+
TARGET_ARTIFACT: ${{env.PACKAGE_NAME}}-${{ steps.get_version.outputs.VERSION }}-${{env.OS_TAG}}-${{ matrix.arch }}

CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
cmake_minimum_required(VERSION 3.0)
22
project(node_libuiohook)
33

4+
if(APPLE)
5+
if (NOT CMAKE_OSX_ARCHITECTURES)
6+
set(CMAKE_OSX_ARCHITECTURES "${CMAKE_HOST_SYSTEM_PROCESSOR}")
7+
endif()
8+
if (NOT CMAKE_OSX_DEPLOYMENT_TARGET)
9+
if ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64")
10+
set(CMAKE_OSX_DEPOLYMENT_TARGET "11.0")
11+
else()
12+
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
13+
endif()
14+
endif()
15+
endif()
16+
417
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
518

619
#############################
720
# CMake Settings
821
#############################
922

10-
SET(NODEJS_URL "https://electronjs.org/headers" CACHE STRING "Node.JS URL")
23+
SET(NODEJS_URL "https://artifacts.electronjs.org/headers/dist" CACHE STRING "Node.JS URL")
1124
SET(NODEJS_NAME "iojs" CACHE STRING "Node.JS Name")
1225
SET(NODEJS_VERSION "v17.4.11" CACHE STRING "Node.JS Version")
1326

ci/build-osx.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,35 @@ set -e
22

33
brew install wget
44

5+
if [ ! -n "${ARCHITECTURE}" ]
6+
then
7+
ARCHITECTURE=$(uname -m)
8+
fi
9+
510
# Download libuiohook dependency
6-
export DEPS="libuiohook-osx-1.2-sl.0"
7-
wget --quiet --retry-connrefused --waitretry=1 https://obs-studio-deployment.s3-us-west-2.amazonaws.com/libuiohook-osx-1.2-sl.0.tar.gz
11+
export DEPS="libuiohook-osx-1.2.2-b230208-${ARCHITECTURE}"
12+
wget --quiet --retry-connrefused --waitretry=1 https://obs-studio-deployment.s3-us-west-2.amazonaws.com/libuiohook-osx-1.2.2-b230208-${ARCHITECTURE}.tar.gz
813

914
mkdir build
1015
cd build
1116

1217
mkdir deps
1318
tar -xf ../${DEPS}.tar.gz -C ./deps
1419

20+
if [ -n "${ELECTRON_VERSION}" ]
21+
then
22+
NODEJS_VERSION_PARAM="-DNODEJS_VERSION=${ELECTRON_VERSION}"
23+
else
24+
NODEJS_VERSION_PARAM=""
25+
fi
26+
1527
# Configure
1628
cmake .. \
17-
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.11 \
29+
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 \
1830
-DUIOHOOKDIR=${PWD}/deps/${DEPS} \
1931
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
20-
-DNODEJS_VERSION=${ELECTRON_VERSION} \
32+
${NODEJS_VERSION_PARAM} \
33+
-DCMAKE_OSX_ARCHITECTURES=${ARCHITECTURE} \
2134
-DCMAKE_INSTALL_PREFIX=${DISTRIBUTE_DIRECTORY}/node-libuiohook
2235

2336
cd ..
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#!/bin/zsh
2+
3+
# 1. Put the script to an empty folder
4+
# 2. ./create-libuiohook-package.zsh --architecture=arm64
5+
# 3. ./create-libuiohook-package.zsh --architecture=x86_64
6+
7+
download_libuihook() {
8+
# Check if the webrtc folder exists
9+
if [ -d "${GIT_FOLDER}" ]
10+
then
11+
echo "### The '${GIT_FOLDER}' folder exists. It will be reused. Remove it if you want to clone the git repositoty again."
12+
return
13+
fi
14+
15+
echo "### Downloading sources ..."
16+
17+
# Clone
18+
git clone --recurse-submodules https://github.com/kwhat/libuiohook ${GIT_FOLDER}
19+
if [ $? -ne 0 ]
20+
then
21+
echo "### Could not clone libuihook!"
22+
exit 1
23+
fi
24+
25+
# Checkout correct tag
26+
cd "${GIT_FOLDER_NAME}"
27+
git checkout -b branch-for-tag-${GIT_TAG} ${GIT_TAG}
28+
if [ $? -ne 0 ]
29+
then
30+
echo "### Could not checkout the appropriate branch."
31+
cd "${INITIAL_WORKING_FOLDER}"
32+
exit 1
33+
fi
34+
35+
# Check if the source folder name is correct and the folder exists
36+
if [ ! -d "${GIT_FOLDER}" ]
37+
then
38+
echo "### The source folder '${GIT_FOLDER}' could not be found. Probably the 'git clone' command failed. Please check manually!"
39+
exit 1
40+
fi
41+
}
42+
43+
build_libuihook() {
44+
45+
echo "### Building ..."
46+
47+
# Prepare build parameters
48+
case "${ARCHITECTURE}" in
49+
arm64)
50+
MIN_MACOS_VERSION=11.0
51+
;;
52+
x86_64)
53+
MIN_MACOS_VERSION=10.15
54+
;;
55+
*)
56+
echo "### Unknown architecture! Only 'arm64' or 'x86_64' is supported."
57+
exit 1
58+
;;
59+
esac
60+
61+
cd "${GIT_FOLDER}"
62+
63+
# Check if the build folder exists
64+
if [ -d "${BUILD_FOLDER}" ]
65+
then
66+
echo "### The '${BUILD_FOLDER}' folder exists. Configuring will be skiped. Remove the folder if you want to configure from scratch."
67+
cd "${BUILD_FOLDER}"
68+
else
69+
echo "### Configuring ..."
70+
71+
mkdir -p "${BUILD_FOLDER}"
72+
if [ $? -ne 0 ]
73+
then
74+
echo "### Could not create the build folder: ${BUILD_FOLDER}!"
75+
exit 1
76+
fi
77+
cd "${BUILD_FOLDER}"
78+
cmake -S .. -DBUILD_SHARED_LIBS=ON -DCMAKE_OSX_ARCHITECTURES="${ARCHITECTURE}" -DCMAKE_OSX_DEPLOYMENT_TARGET=${MIN_MACOS_VERSION} -DCMAKE_INSTALL_PREFIX=${PACKAGE_FOLDER}
79+
if [ $? -ne 0 ]
80+
then
81+
echo "### Could not configure!"
82+
cd "${INITIAL_WORKING_FOLDER}"
83+
exit 1
84+
fi
85+
fi
86+
87+
echo "### Building ..."
88+
89+
cmake --build . --target install
90+
if [ $? -ne 0 ]
91+
then
92+
echo "### Build failed!"
93+
cd "${INITIAL_WORKING_FOLDER}"
94+
exit 1
95+
fi
96+
}
97+
98+
package_libuihook() {
99+
# Copy the script
100+
echo "### Copying this script ..."
101+
cp "${SCRIPT_PATH}" "${PACKAGE_FOLDER}"
102+
103+
cd ${INITIAL_WORKING_FOLDER}
104+
105+
# Compress
106+
echo "### Compressing ..."
107+
tar cvzf ${PACKAGE_FOLDER_NAME}.tar.gz ${PACKAGE_FOLDER_NAME}
108+
}
109+
110+
# SCRIPT START
111+
112+
ARCHITECTURE=$(uname -m)
113+
114+
while [ $# -gt 0 ]; do
115+
case "$1" in
116+
--architecture=*)
117+
ARCHITECTURE="${1#*=}"
118+
;;
119+
*)
120+
echo "### Error: Invalid command line parameter. Please use --architecture=arm64 or --architecture=x86_64"
121+
exit 1
122+
esac
123+
shift
124+
done
125+
126+
INITIAL_WORKING_FOLDER=${PWD}
127+
SCRIPT_PATH=$(realpath $0)
128+
GIT_FOLDER_NAME=libuiohook
129+
GIT_FOLDER=${INITIAL_WORKING_FOLDER}/${GIT_FOLDER_NAME}
130+
GIT_TAG=1.2.2
131+
BUILD_FOLDER_NAME=build-${ARCHITECTURE}
132+
BUILD_FOLDER=${GIT_FOLDER}/${BUILD_FOLDER_NAME}
133+
PACKAGE_FOLDER_NAME=libuiohook-osx-${GIT_TAG}-b$(date +'%y%m%d')-${ARCHITECTURE}
134+
PACKAGE_FOLDER=${INITIAL_WORKING_FOLDER}/${PACKAGE_FOLDER_NAME}
135+
136+
# Check if git is available
137+
if ! command -v git &> /dev/null
138+
then
139+
echo "'git' could not be found. Please install 'git' and start the script again."
140+
exit 1
141+
fi
142+
143+
download_libuihook
144+
build_libuihook
145+
package_libuihook

0 commit comments

Comments
 (0)