Skip to content

Commit

Permalink
Attempt macOS Support
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Jun 12, 2024
1 parent 6872139 commit 06a8f80
Show file tree
Hide file tree
Showing 30 changed files with 145 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
submodules: recursive
- name: "Setup Environment"
run: |
mkdir build
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
types: [ "review_requested", "ready_for_review" ]
workflow_dispatch:
name: macOS
permissions:
id-token: write
contents: read
env:
GITHUB_ACTIONS: true
VCPKG_ROOT: ${{github.workspace}}/vcpkg
jobs:
build:
name: "Build on x64"
runs-on: macos-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
submodules: recursive
- name: "Setup Environment"
run: mkdir build
- name: "Vcpkg"
uses: johnwason/vcpkg-action@v6
id: vcpkg
with:
pkgs: curl gettext-libintl glib gtest jsoncpp libsecret libuuid maddy openssl
triplet: x64-osx
revision: b27651341123a59f7187b42ef2bc476284afb310
token: ${{ secrets.GITHUB_TOKEN }}
github-binarycache: true
- name: "Build"
working-directory: ${{github.workspace}}/build
run: |
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install
cmake --build .
- name: "Install"
working-directory: ${{github.workspace}}/build
run: cmake --install .
- name: "Test"
run: ${{github.workspace}}/build/libnick_test
- name: Upload
uses: actions/upload-artifact@v4
with:
path: ${{github.workspace}}/install
name: macOS-x64-Release
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include(CTest)

#libnick Setup
add_compile_definitions(SQLITE_HAS_CODEC)
if(LINUX)
if(NOT WIN32)
add_compile_definitions(HAVE_USLEEP)
endif()
add_library (${PROJECT_NAME}
Expand Down Expand Up @@ -92,7 +92,7 @@ endif()
if(WIN32)
find_package(sqlcipher CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC sqlcipher::sqlcipher Advapi32 Dwmapi Gdiplus Kernel32 Shell32 UxTheme)
elseif(LINUX)
else()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
Expand Down
4 changes: 4 additions & 0 deletions docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ Path: `Nickvision::App::Aura`
bool IsRunningOnLinux: get
```
- Whether or not the app is running on Linux
- ```
bool IsRunningOnMac: get
```
- Whether or not the app is running on macOS
- ```
bool IsRunningViaFlatpak: get
```
Expand Down
5 changes: 5 additions & 0 deletions include/app/aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ namespace Nickvision::App
* @return True if running on Linux, else false
*/
bool isRunningOnLinux() const;
/**
* @brief Gets whether or not the app is running on macOS.
* @return True if running on macOS, else false
*/
bool isRunningOnMac() const;
/**
* @brief Gets whether or not the app is running via Flatpak.
* @return True if running via Flatpak, else false
Expand Down
4 changes: 2 additions & 2 deletions include/app/interprocesscommunicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "events/parameventargs.h"
#ifdef _WIN32
#include <windows.h>
#elif defined(__linux__)
#else
#include <sys/un.h>
#endif

Expand Down Expand Up @@ -67,7 +67,7 @@ namespace Nickvision::App
std::string m_path;
#ifdef _WIN32
HANDLE m_serverPipe;
#elif defined(__linux__)
#else
struct sockaddr_un m_sockaddr;
int m_serverSocket;
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/database/sqlcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>
#ifdef _WIN32
#include <sqlcipher/sqlite3.h>
#elif defined(__linux__)
#else
#include "sqlite3.h"
#endif
#include "sqlvalue.h"
Expand Down
2 changes: 1 addition & 1 deletion include/database/sqldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <unordered_map>
#ifdef _WIN32
#include <sqlcipher/sqlite3.h>
#elif defined(__linux__)
#else
#include "sqlite3.h"
#endif
#include "sqlcontext.h"
Expand Down
4 changes: 2 additions & 2 deletions include/database/sqlite3.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef __linux__
#ifndef _WIN32

/*
** 2001-09-15
Expand Down Expand Up @@ -12897,4 +12897,4 @@ struct fts5_api {

/******** End of fts5.h *********/

#endif //__linux__
#endif //_WIN32
2 changes: 1 addition & 1 deletion include/database/sqlstatement.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <utility>
#ifdef _WIN32
#include <sqlcipher/sqlite3.h>
#elif defined(__linux__)
#else
#include "sqlite3.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/database/sqlvalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <utility>
#ifdef _WIN32
#include <sqlcipher/sqlite3.h>
#elif defined(__linux__)
#else
#include "sqlite3.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/filesystem/filesystemwatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace Nickvision::Filesystem
std::jthread m_watchThread;
#ifdef _WIN32
HANDLE m_terminateEvent;
#elif defined(__linux__)
#else
int m_notify;
#endif
};
Expand Down
2 changes: 1 addition & 1 deletion include/network/networkmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace Nickvision::Network
CComPtr<INetworkListManager> m_netListManager;
CComPtr<IConnectionPoint> m_connectionPoint;
DWORD m_cookie;
#elif defined(__linux__)
#else
unsigned long m_networkChangedHandlerId;
#endif
};
Expand Down
4 changes: 2 additions & 2 deletions include/system/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "processexitedeventargs.h"
#ifdef _WIN32
#include <windows.h>
#elif defined(__linux__)
#else
#include <sys/types.h>
#endif

Expand Down Expand Up @@ -102,7 +102,7 @@ namespace Nickvision::System
HANDLE m_read;
HANDLE m_write;
PROCESS_INFORMATION m_pi;
#elif defined(__linux__)
#else
pid_t m_pid;
std::filesystem::path m_consoleFilePath;
#endif
Expand Down
13 changes: 11 additions & 2 deletions src/app/aura.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace Nickvision::App
{
throw std::runtime_error("Unable to get executable directory.");
}
#elif defined(__linux__)
#else
m_executableDirectory = std::filesystem::canonical("/proc/self/exe").parent_path();
#endif
//Setup AppInfo
Expand Down Expand Up @@ -96,6 +96,15 @@ namespace Nickvision::App
#endif
}

bool Aura::isRunningOnMac() const
{
#ifdef __APPLE__
return true;
#else
return false;
#endif
}

bool Aura::isRunningViaFlatpak() const
{
return std::filesystem::exists("/.flatpak-info");
Expand Down Expand Up @@ -185,7 +194,7 @@ namespace Nickvision::App
sysLocale = StringHelpers::str(name);
sysLocale = StringHelpers::replace(sysLocale, "-", "_");
}
#elif defined(__linux__)
#else
std::string sysLocale{ StringHelpers::split(std::locale("").name(), ".")[0] }; //split to remove the .UTF-8
#endif
if (!sysLocale.empty() && sysLocale != "C" && sysLocale != "en_US" && sysLocale != "*")
Expand Down
10 changes: 5 additions & 5 deletions src/app/interprocesscommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <cstdlib>
#include <stdexcept>
#include "helpers/stringhelpers.h"
#ifdef __linux__
#ifndef _WIN32
#include <unistd.h>
#include <sys/socket.h>
#endif
Expand Down Expand Up @@ -30,7 +30,7 @@ namespace Nickvision::App
m_serverRunning = true;
FindClose(find);
}
#elif defined(__linux__)
#else
m_path = "/tmp/" + id;
if (m_path.size() >= 108)
{
Expand Down Expand Up @@ -73,7 +73,7 @@ namespace Nickvision::App
CancelSynchronousIo(m_serverPipe);
CloseHandle(m_serverPipe);
}
#elif defined(__linux__)
#else
if (m_serverSocket != -1)
{
int clientSocket{ socket(AF_UNIX, SOCK_SEQPACKET, 0) };
Expand Down Expand Up @@ -123,7 +123,7 @@ namespace Nickvision::App
WriteFile(clientPipe, arg.c_str(), DWORD(arg.size()), nullptr, nullptr);
}
CloseHandle(clientPipe);
#elif defined(__linux__)
#else
int clientSocket{ socket(AF_UNIX, SOCK_SEQPACKET, 0) };
if (connect(clientSocket, (const struct sockaddr*)&m_sockaddr, sizeof(m_sockaddr)) == -1)
{
Expand Down Expand Up @@ -163,7 +163,7 @@ namespace Nickvision::App
m_commandReceived({ args });
DisconnectNamedPipe(m_serverPipe);
}
#elif defined(__linux__)
#else
int clientSocket{ accept(m_serverSocket, nullptr, nullptr) };
if (!m_serverRunning)
{
Expand Down
4 changes: 2 additions & 2 deletions src/database/sqlite3.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef __linux__
#ifndef _WIN32

/******************************************************************************
** This file is an amalgamation of many separate C source files from SQLite
Expand Down Expand Up @@ -247126,4 +247126,4 @@ SQLITE_API int sqlite3_stmt_init(
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
/************************** End of sqlite3.c ******************************/

#endif //__linux__
#endif //_WIN32
8 changes: 4 additions & 4 deletions src/filesystem/filesystemwatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <cstdlib>
#include <algorithm>
#include <stdexcept>
#ifdef __linux__
#ifndef _WIN32
#include <unistd.h>
#include <sys/inotify.h>
#endif
Expand All @@ -21,7 +21,7 @@ namespace Nickvision::Filesystem
{
throw std::runtime_error("Unable to create event.");
}
#elif defined(__linux__)
#else
m_notify = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (m_notify == -1)
{
Expand All @@ -37,7 +37,7 @@ namespace Nickvision::Filesystem
#ifdef _WIN32
SetEvent(m_terminateEvent);
CloseHandle(m_terminateEvent);
#elif defined(__linux__)
#else
close(m_notify);
#endif
}
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace Nickvision::Filesystem
GetOverlappedResult(folder, &overlapped, &bytes, TRUE);
}
CloseHandle(folder);
#elif defined(__linux__)
#else
int mask{ 0 };
if ((m_watcherFlags & WatcherFlags::FileName) == WatcherFlags::FileName)
{
Expand Down
2 changes: 1 addition & 1 deletion src/filesystem/systemdirectories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Nickvision::Filesystem
{
#ifdef _WIN32
return StringHelpers::split<std::filesystem::path>(env, ";");
#elif defined(__linux__)
#else
return StringHelpers::split<std::filesystem::path>(env, ":");
#endif
}
Expand Down
Loading

0 comments on commit 06a8f80

Please sign in to comment.