Skip to content

Commit

Permalink
Add support for Mac Catalyst. Fixes #168
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhat committed May 7, 2024
1 parent c446595 commit de8833e
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 41 deletions.
140 changes: 115 additions & 25 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- '**'

jobs:
apple-arm64:
catalyst-arm64:
runs-on: macos-latest

steps:
Expand All @@ -17,13 +17,94 @@ jobs:
- name: Compile
env:
CC: clang
CFLAGS: '-O2 -g -target arm64-apple-macos10.5 -flto -fomit-frame-pointer -fno-stack-protector -pipe'
CFLAGS: '-O2 -g -target arm64-apple-ios-macabi -miphoneos-version-min=13.1 -flto -fomit-frame-pointer -fno-stack-protector -pipe'
LDFLAGS: '-Wl,-dead_strip_dylibs'
shell: bash
run: |
cmake -B ${{github.workspace}}/build \
-G "Unix Makefiles" \
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/darwin/arm64 \
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/catalyst/arm64 \
-D CMAKE_VERBOSE_MAKEFILE=true \
-D BUILD_SHARED_LIBS=ON \
-D USE_APPLICATION_SERVICES=OFF \
-D USE_IOKIT=OFF \
-D USE_APPKIT=OFF \
-D BUILD_DEMO=OFF
cmake --build ${{github.workspace}}/build \
--parallel 2 \
--config RelWithDebInfo \
--clean-first
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true

catalyst-x86_64:
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true

- name: Compile
env:
CC: clang
CFLAGS: '-O2 -g -target x86_64-apple-ios-macabi -miphoneos-version-min=13.1 -flto -fomit-frame-pointer -fno-stack-protector -pipe'
LDFLAGS: '-Wl,-dead_strip_dylibs'
shell: bash
run: |
cmake -B ${{github.workspace}}/build \
-G "Unix Makefiles" \
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/catalyst/x86_64 \
-D CMAKE_VERBOSE_MAKEFILE=true \
-D BUILD_SHARED_LIBS=ON \
-D USE_APPLICATION_SERVICES=OFF \
-D USE_IOKIT=OFF \
-D USE_APPKIT=OFF \
-D BUILD_DEMO=OFF
cmake --build ${{github.workspace}}/build \
--parallel 2 \
--config RelWithDebInfo \
--clean-first
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v4
with:
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true


macos-arm64:
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v1
with:
submodules: true

- name: Compile
env:
CC: clang
CFLAGS: '-O2 -g -target arm64-apple-macos -mmacosx-version-min=10.5 -flto -fomit-frame-pointer -fno-stack-protector -pipe'
LDFLAGS: '-Wl,-dead_strip_dylibs'
shell: bash
run: |
cmake -B ${{github.workspace}}/build \
-G "Unix Makefiles" \
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/macos/arm64 \
-D CMAKE_VERBOSE_MAKEFILE=true \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_DEMO=ON
Expand All @@ -36,12 +117,13 @@ jobs:
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true

apple-x86_64:
macos-x86_64:
runs-on: macos-latest

steps:
Expand All @@ -53,13 +135,13 @@ jobs:
- name: Compile
env:
CC: clang
CFLAGS: '-O2 -g -target x86_64-apple-macos10.5 -flto -fomit-frame-pointer -fno-stack-protector -pipe'
CFLAGS: '-O2 -g -target x86_64-apple-macos -mmacosx-version-min=10.5 -flto -fomit-frame-pointer -fno-stack-protector -pipe'
LDFLAGS: '-Wl,-dead_strip_dylibs'
shell: bash
run: |
cmake -B ${{github.workspace}}/build \
-G "Unix Makefiles" \
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/darwin/x86_64 \
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/dist/macos/x86_64 \
-D CMAKE_VERBOSE_MAKEFILE=true \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_DEMO=ON
Expand All @@ -72,10 +154,11 @@ jobs:
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true


linux-arm:
Expand All @@ -97,7 +180,7 @@ jobs:
deb [arch=amd64,i386] http://us.archive.ubuntu.com/ubuntu ${DISTRIB_CODENAME}-backports main universe
# This only seems to be required on GitHub images
deb [arch=amd64,i386] https://ppa.launchpadcontent.net/ubuntu-toolchain-r/test/ubuntu ${DISTRIB_CODENAME} main
deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports ${DISTRIB_CODENAME} main universe
deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports ${DISTRIB_CODENAME}-updates main universe
deb [arch=arm64,armhf] http://ports.ubuntu.com/ubuntu-ports ${DISTRIB_CODENAME}-backports main universe
Expand Down Expand Up @@ -145,10 +228,11 @@ jobs:
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true

linux-arm64:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -217,10 +301,11 @@ jobs:
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true

linux-x86:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -283,10 +368,11 @@ jobs:
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true

linux-x86_64:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -333,10 +419,11 @@ jobs:
cmake --install ${{github.workspace}}/build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true


windows-arm:
Expand Down Expand Up @@ -370,10 +457,11 @@ jobs:
cmake --install ${{github.workspace}}\build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true

windows-x86:
runs-on: windows-latest
Expand Down Expand Up @@ -406,10 +494,11 @@ jobs:
cmake --install ${{github.workspace}}\build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true

windows-x86_64:
runs-on: windows-latest
Expand Down Expand Up @@ -442,7 +531,8 @@ jobs:
cmake --install ${{github.workspace}}\build --config RelWithDebInfo
- name: Upload
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nightly-build
name: ${{github.job}}
path: ${{github.workspace}}/dist/**/*
overwrite: true
24 changes: 16 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,29 @@ if(UNIX AND NOT APPLE)
endif()
elseif(APPLE)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5")

find_package(Threads REQUIRED)
target_link_libraries(uiohook "${CMAKE_THREAD_LIBS_INIT}")

find_library(CARBON Carbon REQUIRED)
target_include_directories(uiohook PRIVATE "${CARBON}")
target_link_libraries(uiohook "${CARBON}")

option(USE_APPLICATION_SERVICES "ApplicationServices framework (default: ON)" ON)
if(USE_APPLICATION_SERVICES)
find_package(Threads REQUIRED)
target_link_libraries(uiohook "${CMAKE_THREAD_LIBS_INIT}")

find_library(CARBON Carbon REQUIRED)
target_include_directories(uiohook PRIVATE "${CARBON}")
target_link_libraries(uiohook "${CARBON}")

find_library(APPLICATION_SERVICES ApplicationServices REQUIRED)
add_compile_definitions(USE_APPLICATION_SERVICES)
target_include_directories(uiohook PRIVATE "${APPLICATION_SERVICES}")
target_link_libraries(uiohook "${APPLICATION_SERVICES}")
else()
# If we aren't using APPLICATION_SERVICES, we need to link against other required libraries.
find_library(CORE_FOUNDATION CoreFoundation REQUIRED)
target_include_directories(uiohook PRIVATE "${CORE_FOUNDATION}")
target_link_libraries(uiohook "${CORE_FOUNDATION}")

find_library(CORE_GRAPHICS CoreGraphics REQUIRED)
target_include_directories(uiohook PRIVATE "${CORE_GRAPHICS}")
target_link_libraries(uiohook "${CORE_GRAPHICS}")
endif()

option(USE_IOKIT "IOKit framework (default: ON)" ON)
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/dispatch_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
#include <stdbool.h>
#include <stdint.h>

#ifdef USE_APPLICATION_SERVICES
#include <ApplicationServices/ApplicationServices.h>
#else
#include <CoreGraphics/CoreGraphics.h>
#endif

extern bool dispatch_hook_enabled(uint64_t timestamp);

Expand Down
10 changes: 6 additions & 4 deletions src/darwin/input_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
#include <objc/objc-runtime.h>
#endif


// Dynamic library loading for dispatch_sync_f to offload tasks that must run on the main runloop.
#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_6) \
|| (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_4_0)
typedef struct dispatch_queue_s *dispatch_queue_t;
#endif
static struct dispatch_queue_s *dispatch_main_queue_s;
static void (*dispatch_sync_f_f)(dispatch_queue_t, void *, void (*function)(void *));

Expand Down Expand Up @@ -549,10 +552,10 @@ static void tis_message_to_nsevent(void *info) {
if (data_ref != NULL) {
if (CFDataGetLength(data_ref) >= 132) {
UInt8 buffer[4];
CFDataGetBytes(data_ref, CFRangeMake(120, 4), &buffer);
CFDataGetBytes(data_ref, CFRangeMake(120, 4), &buffer[0]);
tis->subtype = CFSwapInt32BigToHost(*((UInt32 *) &buffer));

CFDataGetBytes(data_ref, CFRangeMake(128, 4), &buffer);
CFDataGetBytes(data_ref, CFRangeMake(128, 4), &buffer[0]);
tis->data1 = CFSwapInt32BigToHost(*((UInt32 *) &buffer));

CFRelease(data_ref);
Expand Down Expand Up @@ -728,7 +731,6 @@ static void tis_message_to_unicode(void *info) {
tis->length = 0;
}
}

}
}

Expand Down
Loading

0 comments on commit de8833e

Please sign in to comment.