Skip to content

Commit

Permalink
libnick: new port in devel
Browse files Browse the repository at this point in the history
  • Loading branch information
barracuda156 committed Nov 14, 2024
1 parent 607ca44 commit 0b94324
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 0 deletions.
52 changes: 52 additions & 0 deletions devel/libnick/Portfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

Check warning on line 1 in devel/libnick/Portfile

View workflow job for this annotation

GitHub Actions / macos-14

port test libnick: Warning: libnick is configured to build for the architecture(s) 'arm64', but did not install any Mach-O files.

Check warning on line 1 in devel/libnick/Portfile

View workflow job for this annotation

GitHub Actions / macos-13

port test libnick: Warning: libnick is configured to build for the architecture(s) 'x86_64', but did not install any Mach-O files.

Check warning on line 1 in devel/libnick/Portfile

View workflow job for this annotation

GitHub Actions / macos-15

port test libnick: Warning: libnick is configured to build for the architecture(s) 'arm64', but did not install any Mach-O files.

PortSystem 1.0
PortGroup boost 1.0
PortGroup cmake 1.1
PortGroup conflicts_build 1.0
PortGroup github 1.0
PortGroup openssl 1.0

boost.version 1.81

github.setup NickvisionApps libnick 2024.10.0
revision 0
categories devel
license GPL-3
maintainers nomaintainer
description Cross-platform base for native Nickvision applications
long_description {*}${description}
checksums rmd160 bff651923b8f1acb368d6d3de24222d50c7dbf55 \
sha256 6117aae500f6932422da9305762b5968556b0b17e9808356e39bfb837a1c5e64 \
size 2570119
github.tarball_from archive

depends_build-append \
port:gtest \
port:maddy-parser \
path:bin/pkg-config:pkgconfig

depends_lib-append port:curl \
path:lib/pkgconfig/glib-2.0.pc:glib2 \
port:gettext-runtime

if {${os.platform} ne "darwin" || ${os.major} < 12} {
depends_lib-append \
port:libsecret
configure.args-append \
-DUSE_LIBSECRET=ON
}

compiler.cxx_standard 2020

# https://github.com/NickvisionApps/libnick/commit/ccd774186829414bfccdfa5d028ae4622c3a4bb7
patchfiles-append 0001-CMakeLists-improve-platform-logic.patch \
0002-Allow-using-libsecret-on-macOS.patch

# https://github.com/NickvisionApps/libnick/commit/aca9e1c2d3124b4bf58cdb078b82bec318da5d5f
patchfiles-append 0001-interprocesscommunicator.cpp-add-missing-cstring.patch \
0002-filesystemwatcher.cpp-provide-kFSEventStream-values-.patch \
0003-suspendinhibitor.cpp-fix-for-10.7.patch

# https://github.com/NickvisionApps/libnick/issues/50
conflicts_build boost
54 changes: 54 additions & 0 deletions devel/libnick/files/0001-CMakeLists-improve-platform-logic.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 4dd284f47f0ebea88b125e942d6b3b6cfd5188ad Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Thu, 14 Nov 2024 09:54:25 +0800
Subject: [PATCH] CMakeLists: improve platform logic

---
CMakeLists.txt | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git CMakeLists.txt CMakeLists.txt
index db21563..6eb5334 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -94,8 +94,12 @@ endif()
if(WIN32)
find_package(sqlcipher CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC sqlcipher::sqlcipher Advapi32 Dnsapi Dwmapi Gdiplus Kernel32 Shell32 UxTheme)
-elseif(LINUX)
+elseif(APPLE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
+ find_library(CF_LIBRARY CoreFoundation)
+ find_library(CS_LIBRARY CoreServices)
+ find_library(IOKIT_LIBRARY IOKit)
+ find_library(SECURITY_LIBRARY Security)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
@@ -104,14 +108,9 @@ elseif(LINUX)
pkg_check_modules(gmodule REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0)
- pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1)
- target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret)
-elseif(APPLE)
+ target_link_libraries(${PROJECT_NAME} PUBLIC ${CF_LIBRARY} ${CS_LIBRARY} ${IOKIT_LIBRARY} ${SECURITY_LIBRARY} Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread)
+else()
set(THREADS_PREFER_PTHREAD_FLAG ON)
- find_library(CF_LIBRARY CoreFoundation)
- find_library(CS_LIBRARY CoreServices)
- find_library(IOKIT_LIBRARY IOKit)
- find_library(SECURITY_LIBRARY Security)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
@@ -120,7 +119,8 @@ elseif(APPLE)
pkg_check_modules(gmodule REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0)
- target_link_libraries(${PROJECT_NAME} PUBLIC ${CF_LIBRARY} ${CS_LIBRARY} ${IOKIT_LIBRARY} ${SECURITY_LIBRARY} Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread)
+ pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1)
+ target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret)
endif()

#libnick Install
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From f33ad59adddfa4b273100533681727954d35db8c Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Thu, 14 Nov 2024 08:16:11 +0800
Subject: [PATCH] interprocesscommunicator.cpp: add missing cstring

---
src/app/interprocesscommunicator.cpp | 1 +
1 file changed, 1 insertion(+)

diff --git src/app/interprocesscommunicator.cpp src/app/interprocesscommunicator.cpp
index 5968cf1..af602e7 100644
--- src/app/interprocesscommunicator.cpp
+++ src/app/interprocesscommunicator.cpp
@@ -1,5 +1,6 @@
#include "app/interprocesscommunicator.h"
#include <cstdlib>
+#include <cstring>
#include <stdexcept>
#include "helpers/stringhelpers.h"
#ifndef _WIN32
240 changes: 240 additions & 0 deletions devel/libnick/files/0002-Allow-using-libsecret-on-macOS.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
From b26d943e70866f9ddd8f936654fa08b79b7bb2d6 Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Thu, 14 Nov 2024 10:10:48 +0800
Subject: [PATCH] Allow using libsecret on macOS

---
CMakeLists.txt | 14 +++-
src/keyring/systemcredentials.cpp | 114 +++++++++++++++---------------
2 files changed, 69 insertions(+), 59 deletions(-)

diff --git CMakeLists.txt CMakeLists.txt
index 6eb5334..a081708 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -25,6 +25,10 @@ include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(CTest)

+if(APPLE)
+ option(USE_LIBSECRET "Use libsecret on macOS instead of Apple keychain" OFF)
+endif()
+
#libnick Setup
add_compile_definitions(SQLITE_HAS_CODEC)
if(NOT WIN32)
@@ -99,7 +103,6 @@ elseif(APPLE)
find_library(CF_LIBRARY CoreFoundation)
find_library(CS_LIBRARY CoreServices)
find_library(IOKIT_LIBRARY IOKit)
- find_library(SECURITY_LIBRARY Security)
find_package(Threads REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
@@ -108,7 +111,14 @@ elseif(APPLE)
pkg_check_modules(gmodule REQUIRED IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(gobject REQUIRED IMPORTED_TARGET gobject-2.0)
pkg_check_modules(gthread REQUIRED IMPORTED_TARGET gthread-2.0)
- target_link_libraries(${PROJECT_NAME} PUBLIC ${CF_LIBRARY} ${CS_LIBRARY} ${IOKIT_LIBRARY} ${SECURITY_LIBRARY} Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread)
+ if(USE_LIBSECRET)
+ pkg_check_modules(libsecret REQUIRED IMPORTED_TARGET libsecret-1)
+ add_compile_definitions(APPLE_USE_LIBSECRET)
+ target_link_libraries(${PROJECT_NAME} PUBLIC ${CF_LIBRARY} ${CS_LIBRARY} ${IOKIT_LIBRARY} Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread PkgConfig::libsecret)
+ else()
+ find_library(SECURITY_LIBRARY Security)
+ target_link_libraries(${PROJECT_NAME} PUBLIC ${CF_LIBRARY} ${CS_LIBRARY} ${IOKIT_LIBRARY} ${SECURITY_LIBRARY} Threads::Threads OpenSSL::SSL OpenSSL::Crypto PkgConfig::glib PkgConfig::gio PkgConfig::gmodule PkgConfig::gobject PkgConfig::gthread)
+ endif()
else()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
diff --git src/keyring/systemcredentials.cpp src/keyring/systemcredentials.cpp
index 76b1994..970490c 100644
--- src/keyring/systemcredentials.cpp
+++ src/keyring/systemcredentials.cpp
@@ -5,18 +5,18 @@
#ifdef _WIN32
#include <windows.h>
#include <wincred.h>
-#elif defined(__linux__)
-#include <libsecret/secret.h>
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && !defined(APPLE_USE_LIBSECRET)
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
+#else
+#include <libsecret/secret.h>
#endif

using namespace Nickvision::Helpers;

namespace Nickvision::Keyring
{
-#ifdef __linux__
+#if !defined(_WIN32) && (!defined(__APPLE__) || defined(APPLE_USE_LIBSECRET))
static const SecretSchema KEYRING_SCHEMA = { "org.nickvision.libnick", SECRET_SCHEMA_NONE, { { "application", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "NULL", SECRET_SCHEMA_ATTRIBUTE_STRING } } };
#endif

@@ -37,20 +37,7 @@ namespace Nickvision::Keyring
return Credential{ StringHelpers::str(credName), StringHelpers::str(credUrl), StringHelpers::str(credUsername), StringHelpers::str(credPassword) };
}
}
-#elif defined(__linux__)
- GError* error{ nullptr };
- char* password{ secret_password_lookup_sync(&KEYRING_SCHEMA, nullptr, &error, "application", name.c_str(), nullptr) };
- if (!error && password)
- {
- Credential c{ name, "", "default", password };
- secret_password_free(password);
- return c;
- }
- if (error)
- {
- g_error_free(error);
- }
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && !defined(APPLE_USE_LIBSECRET)
CFStringRef nameRef{ CFStringCreateWithCString(nullptr, name.c_str(), kCFStringEncodingUTF8) };
CFMutableDictionaryRef query{ CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) };
CFDictionaryAddValue(query, kSecClass, kSecClassGenericPassword);
@@ -86,6 +73,19 @@ namespace Nickvision::Keyring
}
CFRelease(query);
CFRelease(nameRef);
+#else
+ GError* error{ nullptr };
+ char* password{ secret_password_lookup_sync(&KEYRING_SCHEMA, nullptr, &error, "application", name.c_str(), nullptr) };
+ if (!error && password)
+ {
+ Credential c{ name, "", "default", password };
+ secret_password_free(password);
+ return c;
+ }
+ if (error)
+ {
+ g_error_free(error);
+ }
#endif
return std::nullopt;
}
@@ -123,16 +123,7 @@ namespace Nickvision::Keyring
cred.CredentialBlobSize = static_cast<unsigned long>(password.size() * sizeof(wchar_t));
cred.CredentialBlob = LPBYTE(password.c_str());
return CredWriteW(&cred, 0);
-#elif defined(__linux__)
- GError* error{ nullptr };
- secret_password_store_sync(&KEYRING_SCHEMA, SECRET_COLLECTION_DEFAULT, credential.getName().c_str(), credential.getPassword().c_str(), nullptr, &error, "application", credential.getName().c_str(), nullptr);
- if (error)
- {
- g_error_free(error);
- return false;
- }
- return true;
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && !defined(APPLE_USE_LIBSECRET)
CFStringRef name{ CFStringCreateWithCString(nullptr, credential.getName().c_str(), kCFStringEncodingUTF8) };
CFStringRef uri{ CFStringCreateWithCString(nullptr, credential.getUri().c_str(), kCFStringEncodingUTF8) };
CFStringRef username{ CFStringCreateWithCString(nullptr, credential.getUsername().c_str(), kCFStringEncodingUTF8) };
@@ -153,6 +144,15 @@ namespace Nickvision::Keyring
CFRelease(name);
CFRelease(query);
return status == errSecSuccess;
+#else
+ GError* error{ nullptr };
+ secret_password_store_sync(&KEYRING_SCHEMA, SECRET_COLLECTION_DEFAULT, credential.getName().c_str(), credential.getPassword().c_str(), nullptr, &error, "application", credential.getName().c_str(), nullptr);
+ if (error)
+ {
+ g_error_free(error);
+ return false;
+ }
+ return true;
#endif
}

@@ -183,25 +183,7 @@ namespace Nickvision::Keyring
CredFree(cred);
return res;
}
-#elif defined(__linux__)
- GError* error{ nullptr };
- char* password{ secret_password_lookup_sync(&KEYRING_SCHEMA, nullptr, &error, "application", credential.getName().c_str(), nullptr) };
- if (!error && password)
- {
- secret_password_free(password);
- secret_password_store_sync(&KEYRING_SCHEMA, SECRET_COLLECTION_DEFAULT, credential.getName().c_str(), credential.getPassword().c_str(), nullptr, &error, "application", credential.getName().c_str(), nullptr);
- if (error)
- {
- g_error_free(error);
- return false;
- }
- return true;
- }
- if (error)
- {
- g_error_free(error);
- }
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && !defined(APPLE_USE_LIBSECRET)
CFStringRef name{ CFStringCreateWithCString(nullptr, credential.getName().c_str(), kCFStringEncodingUTF8) };
CFMutableDictionaryRef query{ CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) };
CFDictionaryAddValue(query, kSecClass, kSecClassGenericPassword);
@@ -233,6 +215,24 @@ namespace Nickvision::Keyring
}
CFRelease(query);
CFRelease(name);
+#else
+ GError* error{ nullptr };
+ char* password{ secret_password_lookup_sync(&KEYRING_SCHEMA, nullptr, &error, "application", credential.getName().c_str(), nullptr) };
+ if (!error && password)
+ {
+ secret_password_free(password);
+ secret_password_store_sync(&KEYRING_SCHEMA, SECRET_COLLECTION_DEFAULT, credential.getName().c_str(), credential.getPassword().c_str(), nullptr, &error, "application", credential.getName().c_str(), nullptr);
+ if (error)
+ {
+ g_error_free(error);
+ return false;
+ }
+ return true;
+ }
+ if (error)
+ {
+ g_error_free(error);
+ }
#endif
return false;
}
@@ -242,7 +242,16 @@ namespace Nickvision::Keyring
#ifdef _WIN32
std::wstring wName{ StringHelpers::wstr(name) };
return CredDeleteW(wName.c_str(), CRED_TYPE_GENERIC, 0);
-#elif defined(__linux__)
+#elif defined(__APPLE__) && !defined(APPLE_USE_LIBSECRET)
+ CFStringRef nameRef{ CFStringCreateWithCString(nullptr, name.c_str(), kCFStringEncodingUTF8) };
+ CFMutableDictionaryRef query{ CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) };
+ CFDictionaryAddValue(query, kSecClass, kSecClassGenericPassword);
+ CFDictionaryAddValue(query, kSecAttrService, nameRef);
+ OSStatus status{ SecItemDelete(query) };
+ CFRelease(query);
+ CFRelease(nameRef);
+ return status == errSecSuccess;
+#else
GError* error{ nullptr };
bool res{ secret_password_clear_sync(&KEYRING_SCHEMA, nullptr, &error, "application", name.c_str(), nullptr) };
if (!error)
@@ -254,15 +263,6 @@ namespace Nickvision::Keyring
g_error_free(error);
}
return false;
-#elif defined(__APPLE__)
- CFStringRef nameRef{ CFStringCreateWithCString(nullptr, name.c_str(), kCFStringEncodingUTF8) };
- CFMutableDictionaryRef query{ CFDictionaryCreateMutable(nullptr, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks) };
- CFDictionaryAddValue(query, kSecClass, kSecClassGenericPassword);
- CFDictionaryAddValue(query, kSecAttrService, nameRef);
- OSStatus status{ SecItemDelete(query) };
- CFRelease(query);
- CFRelease(nameRef);
- return status == errSecSuccess;
#endif
}
}
\ No newline at end of file

Loading

0 comments on commit 0b94324

Please sign in to comment.