From 83b3403b526a3d68400e32bc1fa6995908ff6413 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 24 Oct 2022 19:24:58 +0200 Subject: [PATCH] Ports: Add Lite-XL --- Ports/AvailablePorts.md | 1 + Ports/lite-xl/package.sh | 41 ++++ ...0001-Add-SerenityOS-platform-support.patch | 192 ++++++++++++++++++ Ports/lite-xl/patches/ReadMe.md | 7 + 4 files changed, 241 insertions(+) create mode 100755 Ports/lite-xl/package.sh create mode 100644 Ports/lite-xl/patches/0001-Add-SerenityOS-platform-support.patch create mode 100644 Ports/lite-xl/patches/ReadMe.md diff --git a/Ports/AvailablePorts.md b/Ports/AvailablePorts.md index 87ae5df7f02..eaf7a883b90 100644 --- a/Ports/AvailablePorts.md +++ b/Ports/AvailablePorts.md @@ -143,6 +143,7 @@ This list is also available at [ports.serenityos.net](https://ports.serenityos.n | [`libyaml`](libyaml/) | libyaml | 0.2.5 | https://pyyaml.org/wiki/LibYAML | | [`libzip`](libzip/) | libzip | 1.8.0 | https://libzip.org/ | | [`links`](links/) | Links web browser | 2.26 | http://links.twibright.com/ | +| [`lite-xl`](lite-xl/) | Lite-XL | 2.1.0 | https://lite-xl.com/ | | [`llvm`](llvm/) | LLVM | 15.0.3 | https://llvm.org/ | | [`lua`](lua/) | Lua | 5.4.4 | https://www.lua.org/ | | [`luajit`](luajit/) | LuaJIT | 2.1.0-beta3 | https://luajit.org/luajit.html | diff --git a/Ports/lite-xl/package.sh b/Ports/lite-xl/package.sh new file mode 100755 index 00000000000..6db07e6752b --- /dev/null +++ b/Ports/lite-xl/package.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env -S bash ../.port_include.sh +port='lite-xl' +version='2.1.0' +commit_hash='97ba91af8b855a10a14bdc5cad774c877156f4a9' +useconfigure='true' +configopts=( + "--buildtype=release" + "--cross-file=${SERENITY_BUILD_DIR}/meson-cross-file.txt" +) +depends=( + 'freetype' + 'lua' + 'pcre2' + 'SDL2' +) +files="https://github.com/lite-xl/lite-xl/archive/${commit_hash}.tar.gz lite-xl-97ba91af8.tar.gz 25a0dd0a6ef856fd312eecd54983d401224eb8d7a5d5aa4a37c9131ac77bd9ca" +workdir="lite-xl-${commit_hash}" +auth_type='sha256' +launcher_name='Lite-XL' +icon_file='resources/icons/icon.ico' +launcher_category='Development' +launcher_command='/usr/local/bin/lite-xl' +launcher_run_in_terminal='false' + +configure() { + # TODO: Figure out why GCC doesn't autodetect that libgcc_s is needed. + if [ "${SERENITY_TOOLCHAIN}" = "GNU" ]; then + export LDFLAGS="-lgcc_s" + fi + + run meson build "${configopts[@]}" +} + +build() { + run ninja -C build +} + +install() { + export DESTDIR="${SERENITY_INSTALL_ROOT}" + run meson install -C build +} diff --git a/Ports/lite-xl/patches/0001-Add-SerenityOS-platform-support.patch b/Ports/lite-xl/patches/0001-Add-SerenityOS-platform-support.patch new file mode 100644 index 00000000000..694fd889c90 --- /dev/null +++ b/Ports/lite-xl/patches/0001-Add-SerenityOS-platform-support.patch @@ -0,0 +1,192 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jan200101 +Date: Mon, 24 Oct 2022 19:23:31 +0200 +Subject: [PATCH] Add SerenityOS platform support + +Signed-off-by: Jan200101 +--- + meson.build | 3 +- + src/api/dirmonitor/inodewatcher.cpp | 75 +++++++++++++++++++++++++++++ + src/main.c | 7 ++- + src/meson.build | 16 +++--- + 4 files changed, 92 insertions(+), 9 deletions(-) + create mode 100644 src/api/dirmonitor/inodewatcher.cpp + +diff --git a/meson.build b/meson.build +index adb7ceb..963bd17 100644 +--- a/meson.build ++++ b/meson.build +@@ -1,10 +1,11 @@ + project('lite-xl', +- ['c'], ++ ['c', 'cpp'], + version : '2.1.0', + license : 'MIT', + meson_version : '>= 0.47', + default_options : [ + 'c_std=gnu11', ++ 'cpp_std=c++20', + 'wrap_mode=nofallback' + ] + ) +diff --git a/src/api/dirmonitor/inodewatcher.cpp b/src/api/dirmonitor/inodewatcher.cpp +new file mode 100644 +index 0000000..e749f5b +--- /dev/null ++++ b/src/api/dirmonitor/inodewatcher.cpp +@@ -0,0 +1,75 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++extern "C" { ++struct dirmonitor_internal* init_dirmonitor(); ++void deinit_dirmonitor(struct dirmonitor_internal*); ++int get_changes_dirmonitor(struct dirmonitor_internal*, char*, int); ++int translate_changes_dirmonitor(struct dirmonitor_internal*, char*, int, int (*)(int, const char*, void*), void*); ++int add_dirmonitor(struct dirmonitor_internal*, const char*); ++void remove_dirmonitor(struct dirmonitor_internal*, int); ++int get_mode_dirmonitor(); ++} ++ ++struct dirmonitor_internal { ++ int fd; ++ // a pipe is used to wake the thread in case of exit ++ int sig[2]; ++}; ++ ++ ++struct dirmonitor_internal* init_dirmonitor() { ++ struct dirmonitor_internal* monitor = (struct dirmonitor_internal*)calloc(sizeof(struct dirmonitor_internal), 1); ++ monitor->fd = create_inode_watcher(0); ++ pipe(monitor->sig); ++ fcntl(monitor->sig[0], F_SETFD, FD_CLOEXEC); ++ fcntl(monitor->sig[1], F_SETFD, FD_CLOEXEC); ++ return monitor; ++} ++ ++ ++void deinit_dirmonitor(struct dirmonitor_internal* monitor) { ++ close(monitor->fd); ++ close(monitor->sig[0]); ++ close(monitor->sig[1]); ++} ++ ++ ++ ++int get_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int length) { ++ struct pollfd fds[2] = { { .fd = monitor->fd, .events = POLLIN | POLLERR, .revents = 0 }, { .fd = monitor->sig[0], .events = POLLIN | POLLERR, .revents = 0 } }; ++ poll(fds, 2, -1); ++ return read(monitor->fd, buffer, length); ++} ++ ++ ++int translate_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int length, int (*change_callback)(int, const char*, void*), void* data) { ++ InodeWatcherEvent* event = (InodeWatcherEvent*)buffer; ++ change_callback(event->watch_descriptor, NULL, data); ++ return 0; ++} ++ ++ ++int add_dirmonitor(struct dirmonitor_internal* monitor, const char* path) { ++ return inode_watcher_add_watch(monitor->fd, path, strlen(path), ++ static_cast( ++ InodeWatcherEvent::Type::MetadataModified | ++ InodeWatcherEvent::Type::ContentModified | ++ InodeWatcherEvent::Type::Deleted | ++ InodeWatcherEvent::Type::ChildCreated | ++ InodeWatcherEvent::Type::ChildDeleted ++ )); ++} ++ ++ ++void remove_dirmonitor(struct dirmonitor_internal* monitor, int fd) { ++ inode_watcher_remove_watch(monitor->fd, fd); ++} ++ ++int get_mode_dirmonitor() { return 2; } +diff --git a/src/main.c b/src/main.c +index 9784c0a..232b9a9 100644 +--- a/src/main.c ++++ b/src/main.c +@@ -7,7 +7,7 @@ + + #ifdef _WIN32 + #include +-#elif __linux__ || __FreeBSD__ ++#elif __linux__ || __FreeBSD__ || __serenity__ + #include + #include + #elif __APPLE__ +@@ -31,7 +31,7 @@ static void get_exe_filename(char *buf, int sz) { + #if _WIN32 + int len = GetModuleFileName(NULL, buf, sz - 1); + buf[len] = '\0'; +-#elif __linux__ ++#elif __linux__ || __serenity__ + char path[] = "/proc/self/exe"; + int len = readlink(path, buf, sz - 1); + buf[len] = '\0'; +@@ -101,6 +101,9 @@ void set_macos_bundle_resources(lua_State *L); + #define ARCH_PLATFORM "freebsd" + #elif __APPLE__ + #define ARCH_PLATFORM "darwin" ++ #elif __serenity__ ++ #define ARCH_PLATFORM "serenity" ++ #else + #endif + + #if !defined(ARCH_PROCESSOR) || !defined(ARCH_PLATFORM) +diff --git a/src/meson.build b/src/meson.build +index 06bb397..8dd25c4 100644 +--- a/src/meson.build ++++ b/src/meson.build +@@ -11,20 +11,30 @@ lite_sources = [ + 'main.c', + ] + ++lite_sources += 'api/dirmonitor.c' + # dirmonitor backend + if get_option('dirmonitor_backend') == '' + if cc.has_function('inotify_init', prefix : '#include') + dirmonitor_backend = 'inotify' ++ lite_sources += 'api/dirmonitor/inotify.c' + elif host_machine.system() == 'darwin' and cc.check_header('CoreServices/CoreServices.h') + dirmonitor_backend = 'fsevents' ++ lite_sources += 'api/dirmonitor/fsevents.c' + elif cc.has_function('kqueue', prefix : '#include') + dirmonitor_backend = 'kqueue' ++ lite_sources += 'api/dirmonitor/kqueue.c' ++ elif cc.has_function('create_inode_watcher', prefix : '#include') ++ dirmonitor_backend = 'inodewatcher' ++ lite_sources += 'api/dirmonitor/inodewatcher.cpp' + elif dependency('libkqueue', required : false).found() + dirmonitor_backend = 'kqueue' ++ lite_sources += 'api/dirmonitor/kqueue.c' + elif host_machine.system() == 'windows' + dirmonitor_backend = 'win32' ++ lite_sources += 'api/dirmonitor/win32.c' + else + dirmonitor_backend = 'dummy' ++ lite_sources += 'api/dirmonitor/dummy.c' + warning('no suitable backend found, defaulting to dummy backend') + endif + else +@@ -40,12 +50,6 @@ if dirmonitor_backend == 'kqueue' + endif + endif + +-lite_sources += [ +- 'api/dirmonitor.c', +- 'api/dirmonitor/' + dirmonitor_backend + '.c', +-] +- +- + lite_rc = [] + if host_machine.system() == 'windows' + windows = import('windows') diff --git a/Ports/lite-xl/patches/ReadMe.md b/Ports/lite-xl/patches/ReadMe.md new file mode 100644 index 00000000000..d9bee552d76 --- /dev/null +++ b/Ports/lite-xl/patches/ReadMe.md @@ -0,0 +1,7 @@ +# Patches for Lite-XL on SerenityOS + +## `0001-Add-SerenityOS-platform-support.patch` + +Add SerenityOS platform support + +