mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
Ports: Add libuv
We've had a half-arsed port of libuv inside the cmake port, but let's just port it properly. Note that this pins a specific commit (which is currently the latest commit in their default branch).
This commit is contained in:
parent
727403746f
commit
fcd56f2172
|
@ -73,6 +73,7 @@ Please make sure to keep this list up to date when adding and updating ports. :^
|
|||
| [`libtheora`](libtheora/) | libtheora | 1.1.1 | https://www.theora.org/ |
|
||||
| [`libtiff`](libtiff/) | libtiff | 4.2.0 | http://www.libtiff.org/ |
|
||||
| [`libtool`](libtool/) | libtool | 2.4 | https://www.gnu.org/software/libtool/ |
|
||||
| [`libuv`](libuv/) | libuv | b12699b | https://github.com/libuv/libuv |
|
||||
| [`libvorbis`](libvorbis/) | libvorbis | 1.3.7 | https://github.com/xiph/vorbis |
|
||||
| [`libxml2`](libxml2/) | libxml2 | 2.9.12 | http://www.xmlsoft.org/ |
|
||||
| [`libzip`](libzip/) | libzip | 1.7.3 | https://libzip.org/ |
|
||||
|
|
19
Ports/libuv/package.sh
Executable file
19
Ports/libuv/package.sh
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env -S bash ../.port_include.sh
|
||||
port=libuv
|
||||
version=b12699b1efabfd241324f4ab6cfd6ce576db491e
|
||||
useconfigure=true
|
||||
files="https://github.com/libuv/libuv/archive/$version.tar.gz $port-$version.tar.gz bbbfa2bb50437047efc8fb29c243c914ae0de94107d7cc641c2f84e292904eb5"
|
||||
auth_type=sha256
|
||||
configopts="-DCMAKE_TOOLCHAIN_FILE=$SERENITY_SOURCE_DIR/Toolchain/CMake/CMakeToolchain.txt -GNinja"
|
||||
|
||||
configure() {
|
||||
run cmake $configopts .
|
||||
}
|
||||
|
||||
build() {
|
||||
run ninja
|
||||
}
|
||||
|
||||
install() {
|
||||
run ninja install
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
From 5ac8ded61c9bcddb7b1df3ad8a23b90a777349bc Mon Sep 17 00:00:00 2001
|
||||
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
||||
Date: Fri, 9 Jul 2021 04:44:26 +0430
|
||||
Subject: [PATCH 1/7] unix: Stub out {get,set}priority for serenity
|
||||
|
||||
---
|
||||
src/unix/core.c | 6 ++++++
|
||||
1 file changed, 6 insertions(+)
|
||||
|
||||
diff --git a/src/unix/core.c b/src/unix/core.c
|
||||
index 71e9c52..004a589 100644
|
||||
--- a/src/unix/core.c
|
||||
+++ b/src/unix/core.c
|
||||
@@ -1421,7 +1421,11 @@ int uv_os_getpriority(uv_pid_t pid, int* priority) {
|
||||
return UV_EINVAL;
|
||||
|
||||
errno = 0;
|
||||
+#ifndef __serenity__
|
||||
r = getpriority(PRIO_PROCESS, (int) pid);
|
||||
+#else
|
||||
+ r = 1;
|
||||
+#endif
|
||||
|
||||
if (r == -1 && errno != 0)
|
||||
return UV__ERR(errno);
|
||||
@@ -1435,8 +1439,10 @@ int uv_os_setpriority(uv_pid_t pid, int priority) {
|
||||
if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW)
|
||||
return UV_EINVAL;
|
||||
|
||||
+#ifndef __serenity__
|
||||
if (setpriority(PRIO_PROCESS, (int) pid, priority) != 0)
|
||||
return UV__ERR(errno);
|
||||
+#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
--
|
||||
2.32.0
|
||||
|
115
Ports/libuv/patches/0002-fs-Stub-out-unsupported-syscalls.patch
Normal file
115
Ports/libuv/patches/0002-fs-Stub-out-unsupported-syscalls.patch
Normal file
|
@ -0,0 +1,115 @@
|
|||
From ef46efb9fb0a1faa306fb1e74a0b44faf6c6d41f Mon Sep 17 00:00:00 2001
|
||||
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
||||
Date: Fri, 9 Jul 2021 04:56:55 +0430
|
||||
Subject: [PATCH 2/7] fs: Stub out unsupported syscalls
|
||||
|
||||
---
|
||||
src/unix/fs.c | 24 +++++++++++++++++++++++-
|
||||
1 file changed, 23 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/unix/fs.c b/src/unix/fs.c
|
||||
index eb17fb4..93b457b 100644
|
||||
--- a/src/unix/fs.c
|
||||
+++ b/src/unix/fs.c
|
||||
@@ -90,6 +90,8 @@
|
||||
defined(__HAIKU__) || \
|
||||
defined(__QNX__)
|
||||
# include <sys/statvfs.h>
|
||||
+#elif defined(__serenity__)
|
||||
+// No statfs
|
||||
#else
|
||||
# include <sys/statfs.h>
|
||||
#endif
|
||||
@@ -659,13 +661,16 @@ static int uv__fs_statfs(uv_fs_t* req) {
|
||||
struct statvfs buf;
|
||||
|
||||
if (0 != statvfs(req->path, &buf))
|
||||
+#elif defined(__serenity__)
|
||||
+ char buf = 0;
|
||||
+ if (1)
|
||||
#else
|
||||
struct statfs buf;
|
||||
|
||||
if (0 != statfs(req->path, &buf))
|
||||
#endif /* defined(__sun) */
|
||||
return -1;
|
||||
-
|
||||
+#if !defined(__serenity__)
|
||||
stat_fs = uv__malloc(sizeof(*stat_fs));
|
||||
if (stat_fs == NULL) {
|
||||
errno = ENOMEM;
|
||||
@@ -689,6 +694,7 @@ static int uv__fs_statfs(uv_fs_t* req) {
|
||||
stat_fs->f_files = buf.f_files;
|
||||
stat_fs->f_ffree = buf.f_ffree;
|
||||
req->ptr = stat_fs;
|
||||
+#endif // !defined(__serenity__)
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1167,7 +1173,11 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
|
||||
r = writev(req->file, (struct iovec*) req->bufs, req->nbufs);
|
||||
} else {
|
||||
if (req->nbufs == 1) {
|
||||
+#ifdef __serenity__
|
||||
+ r = 0;
|
||||
+#else
|
||||
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
|
||||
+#endif
|
||||
goto done;
|
||||
}
|
||||
#if HAVE_PREADV
|
||||
@@ -1177,7 +1187,11 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
|
||||
if (no_pwritev) retry:
|
||||
# endif
|
||||
{
|
||||
+#ifdef __serenity__
|
||||
+ r = 0;
|
||||
+#else
|
||||
r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
|
||||
+#endif
|
||||
}
|
||||
# if defined(__linux__)
|
||||
else {
|
||||
@@ -1666,7 +1680,9 @@ static void uv__fs_work(struct uv__work* w) {
|
||||
X(COPYFILE, uv__fs_copyfile(req));
|
||||
X(FCHMOD, fchmod(req->file, req->mode));
|
||||
X(FCHOWN, fchown(req->file, req->uid, req->gid));
|
||||
+#ifndef __serenity__
|
||||
X(LCHOWN, lchown(req->path, req->uid, req->gid));
|
||||
+#endif
|
||||
X(FDATASYNC, uv__fs_fdatasync(req));
|
||||
X(FSTAT, uv__fs_fstat(req->file, &req->statbuf));
|
||||
X(FSYNC, uv__fs_fsync(req));
|
||||
@@ -1690,7 +1706,9 @@ static void uv__fs_work(struct uv__work* w) {
|
||||
X(RMDIR, rmdir(req->path));
|
||||
X(SENDFILE, uv__fs_sendfile(req));
|
||||
X(STAT, uv__fs_stat(req->path, &req->statbuf));
|
||||
+#ifndef __serenity__
|
||||
X(STATFS, uv__fs_statfs(req));
|
||||
+#endif
|
||||
X(SYMLINK, symlink(req->path, req->new_path));
|
||||
X(UNLINK, unlink(req->path));
|
||||
X(UTIME, uv__fs_utime(req));
|
||||
@@ -1805,7 +1823,9 @@ int uv_fs_lchown(uv_loop_t* loop,
|
||||
uv_uid_t uid,
|
||||
uv_gid_t gid,
|
||||
uv_fs_cb cb) {
|
||||
+#ifndef __serenity__
|
||||
INIT(LCHOWN);
|
||||
+#endif
|
||||
PATH;
|
||||
req->uid = uid;
|
||||
req->gid = gid;
|
||||
@@ -2196,7 +2216,9 @@ int uv_fs_statfs(uv_loop_t* loop,
|
||||
uv_fs_t* req,
|
||||
const char* path,
|
||||
uv_fs_cb cb) {
|
||||
+#ifndef __serenity__
|
||||
INIT(STATFS);
|
||||
+#endif
|
||||
PATH;
|
||||
POST;
|
||||
}
|
||||
--
|
||||
2.32.0
|
||||
|
37
Ports/libuv/patches/0003-stream-Don-t-use-AF_INET6.patch
Normal file
37
Ports/libuv/patches/0003-stream-Don-t-use-AF_INET6.patch
Normal file
|
@ -0,0 +1,37 @@
|
|||
From 774eb9413fb32bc3656ddcd9ccb22af3d2083278 Mon Sep 17 00:00:00 2001
|
||||
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
||||
Date: Fri, 9 Jul 2021 04:57:31 +0430
|
||||
Subject: [PATCH 3/7] stream: Don't use AF_INET6
|
||||
|
||||
---
|
||||
src/unix/stream.c | 8 +++++++-
|
||||
1 file changed, 7 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/unix/stream.c b/src/unix/stream.c
|
||||
index f64c01c..96f6417 100644
|
||||
--- a/src/unix/stream.c
|
||||
+++ b/src/unix/stream.c
|
||||
@@ -995,13 +995,19 @@ uv_handle_type uv__handle_type(int fd) {
|
||||
case AF_UNIX:
|
||||
return UV_NAMED_PIPE;
|
||||
case AF_INET:
|
||||
+#ifndef __serenity__
|
||||
case AF_INET6:
|
||||
+#endif
|
||||
return UV_TCP;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == SOCK_DGRAM &&
|
||||
- (ss.ss_family == AF_INET || ss.ss_family == AF_INET6))
|
||||
+ (ss.ss_family == AF_INET
|
||||
+#ifndef __serenity__
|
||||
+ || ss.ss_family == AF_INET6
|
||||
+#endif
|
||||
+ ))
|
||||
return UV_UDP;
|
||||
|
||||
return UV_UNKNOWN_HANDLE;
|
||||
--
|
||||
2.32.0
|
||||
|
36
Ports/libuv/patches/0004-tcp-Don-t-use-SO_LINGER.patch
Normal file
36
Ports/libuv/patches/0004-tcp-Don-t-use-SO_LINGER.patch
Normal file
|
@ -0,0 +1,36 @@
|
|||
From 91c2345d42459232d958eaf0eba5b10786ac3475 Mon Sep 17 00:00:00 2001
|
||||
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
||||
Date: Fri, 9 Jul 2021 04:59:05 +0430
|
||||
Subject: [PATCH 4/7] tcp: Don't use SO_LINGER
|
||||
|
||||
---
|
||||
src/unix/tcp.c | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/unix/tcp.c b/src/unix/tcp.c
|
||||
index bc0fb66..e78259a 100644
|
||||
--- a/src/unix/tcp.c
|
||||
+++ b/src/unix/tcp.c
|
||||
@@ -313,15 +313,19 @@ int uv_tcp_getpeername(const uv_tcp_t* handle,
|
||||
|
||||
int uv_tcp_close_reset(uv_tcp_t* handle, uv_close_cb close_cb) {
|
||||
int fd;
|
||||
+#ifndef __serenity__
|
||||
struct linger l = { 1, 0 };
|
||||
+#endif
|
||||
|
||||
/* Disallow setting SO_LINGER to zero due to some platform inconsistencies */
|
||||
if (handle->flags & UV_HANDLE_SHUTTING)
|
||||
return UV_EINVAL;
|
||||
|
||||
fd = uv__stream_fd(handle);
|
||||
+#ifndef __serenity__
|
||||
if (0 != setsockopt(fd, SOL_SOCKET, SO_LINGER, &l, sizeof(l)))
|
||||
return UV__ERR(errno);
|
||||
+#endif
|
||||
|
||||
uv_close((uv_handle_t*) handle, close_cb);
|
||||
return 0;
|
||||
--
|
||||
2.32.0
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
From 1c95dc0ae7732d4389eac1688d3a13ba942f316d Mon Sep 17 00:00:00 2001
|
||||
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
||||
Date: Fri, 9 Jul 2021 05:01:05 +0430
|
||||
Subject: [PATCH 5/7] build: Add SerenityOS platform definitions
|
||||
|
||||
---
|
||||
CMakeLists.txt | 15 +++++++++++++++
|
||||
1 file changed, 15 insertions(+)
|
||||
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index de1272a..f30ec26 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -356,6 +356,21 @@ if(CMAKE_SYSTEM_NAME STREQUAL "QNX")
|
||||
list(APPEND uv_libraries socket)
|
||||
endif()
|
||||
|
||||
+if(CMAKE_SYSTEM_NAME STREQUAL "SerenityOS")
|
||||
+ list(APPEND uv_headers
|
||||
+ include/uv/posix.h
|
||||
+ )
|
||||
+ list(APPEND uv_sources
|
||||
+ src/unix/posix-hrtime.c
|
||||
+ src/unix/posix-poll.c
|
||||
+ src/unix/no-fsevents.c
|
||||
+ src/unix/no-proctitle.c
|
||||
+ )
|
||||
+ list(APPEND uv_libraries
|
||||
+ dl
|
||||
+ )
|
||||
+endif()
|
||||
+
|
||||
if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|Linux|NetBSD|OpenBSD")
|
||||
list(APPEND uv_test_libraries util)
|
||||
endif()
|
||||
--
|
||||
2.32.0
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
From b9992fdc37570ae7ca15b50c37ef431289cdc497 Mon Sep 17 00:00:00 2001
|
||||
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
||||
Date: Fri, 9 Jul 2021 05:02:01 +0430
|
||||
Subject: [PATCH 6/7] include: Teach the header about serenity
|
||||
|
||||
---
|
||||
include/uv/unix.h | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/include/uv/unix.h b/include/uv/unix.h
|
||||
index e3cf7bd..35f1433 100644
|
||||
--- a/include/uv/unix.h
|
||||
+++ b/include/uv/unix.h
|
||||
@@ -71,6 +71,8 @@
|
||||
# include "uv/posix.h"
|
||||
#elif defined(__QNX__)
|
||||
# include "uv/posix.h"
|
||||
+#elif defined(__serenity__)
|
||||
+# include "uv/posix.h"
|
||||
#endif
|
||||
|
||||
#ifndef NI_MAXHOST
|
||||
--
|
||||
2.32.0
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
From 5c53f32b401baffb4c6dc896ca07beff2add2a42 Mon Sep 17 00:00:00 2001
|
||||
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
||||
Date: Fri, 9 Jul 2021 05:32:00 +0430
|
||||
Subject: [PATCH 7/7] build: Add platform-specific stubs and implementations
|
||||
|
||||
---
|
||||
CMakeLists.txt | 2 +
|
||||
src/unix/serenity-core.c | 137 +++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 139 insertions(+)
|
||||
create mode 100644 src/unix/serenity-core.c
|
||||
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index f30ec26..6f0bf0c 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -365,9 +365,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "SerenityOS")
|
||||
src/unix/posix-poll.c
|
||||
src/unix/no-fsevents.c
|
||||
src/unix/no-proctitle.c
|
||||
+ src/unix/serenity-core.c
|
||||
)
|
||||
list(APPEND uv_libraries
|
||||
dl
|
||||
+ pthread
|
||||
)
|
||||
endif()
|
||||
|
||||
diff --git a/src/unix/serenity-core.c b/src/unix/serenity-core.c
|
||||
new file mode 100644
|
||||
index 0000000..821cf37
|
||||
--- /dev/null
|
||||
+++ b/src/unix/serenity-core.c
|
||||
@@ -0,0 +1,137 @@
|
||||
+#include "uv.h"
|
||||
+#include "internal.h"
|
||||
+
|
||||
+#include <errno.h>
|
||||
+#include <stddef.h>
|
||||
+
|
||||
+#include <net/if.h>
|
||||
+#include <unistd.h>
|
||||
+
|
||||
+static int uv__ifaddr_exclude(void *ent, int exclude_type) {
|
||||
+ return 1;
|
||||
+}
|
||||
+
|
||||
+int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
|
||||
+ *count = 0;
|
||||
+ *addresses = NULL;
|
||||
+ return UV_ENOSYS;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+void uv_free_interface_addresses(uv_interface_address_t* addresses,
|
||||
+ int count) {
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = 0; i < count; i++) {
|
||||
+ uv__free(addresses[i].name);
|
||||
+ }
|
||||
+
|
||||
+ uv__free(addresses);
|
||||
+}
|
||||
+
|
||||
+static int uv__slurp(const char* filename, char* buf, size_t len) {
|
||||
+ ssize_t n;
|
||||
+ int fd;
|
||||
+
|
||||
+ assert(len > 0);
|
||||
+
|
||||
+ fd = uv__open_cloexec(filename, O_RDONLY);
|
||||
+ if (fd < 0)
|
||||
+ return fd;
|
||||
+
|
||||
+ do
|
||||
+ n = read(fd, buf, len - 1);
|
||||
+ while (n == -1 && errno == EINTR);
|
||||
+
|
||||
+ if (uv__close_nocheckstdio(fd))
|
||||
+ abort();
|
||||
+
|
||||
+ if (n < 0)
|
||||
+ return UV__ERR(errno);
|
||||
+
|
||||
+ buf[n] = '\0';
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static uint64_t uv__read_proc_memstat(const char* what) {
|
||||
+ uint64_t rc;
|
||||
+ char* p;
|
||||
+ char buf[4096]; /* Large enough to hold all of /proc/memstat. */
|
||||
+
|
||||
+ if (uv__slurp("/proc/memstat", buf, sizeof(buf)))
|
||||
+ return 0;
|
||||
+
|
||||
+ p = strstr(buf, what);
|
||||
+
|
||||
+ if (p == NULL)
|
||||
+ return 0;
|
||||
+
|
||||
+ p += strlen(what);
|
||||
+
|
||||
+ rc = 0;
|
||||
+ sscanf(p, "%" PRIu64, &rc);
|
||||
+
|
||||
+ return rc;
|
||||
+}
|
||||
+
|
||||
+uint64_t uv_get_free_memory(void) {
|
||||
+ return uv__read_proc_memstat("user_physical_available\":") * PAGE_SIZE;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+uint64_t uv_get_total_memory(void) {
|
||||
+ return (uv__read_proc_memstat("user_physical_allocated\":") + uv__read_proc_memstat("user_physical_available\":")) * PAGE_SIZE;
|
||||
+}
|
||||
+
|
||||
+void uv_loadavg(double avg[3]) {
|
||||
+ avg[0] = 0.0f;
|
||||
+ avg[1] = 0.0f;
|
||||
+ avg[2] = 0.0f;
|
||||
+}
|
||||
+
|
||||
+int uv_uptime(double* uptime) {
|
||||
+ char buf[128];
|
||||
+ struct timespec now;
|
||||
+ int r;
|
||||
+
|
||||
+ /* Try /proc/uptime first, then fallback to clock_gettime(). */
|
||||
+
|
||||
+ if (0 == uv__slurp("/proc/uptime", buf, sizeof(buf)))
|
||||
+ if (1 == sscanf(buf, "%lf", uptime))
|
||||
+ return 0;
|
||||
+
|
||||
+ r = clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
+ if (r)
|
||||
+ return UV__ERR(errno);
|
||||
+
|
||||
+ *uptime = now.tv_sec;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+uint64_t uv_get_constrained_memory(void) {
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
||||
+ *cpu_infos = NULL;
|
||||
+ *count = 0;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int uv_exepath(char* buffer, size_t* size) {
|
||||
+ if (buffer == NULL || size == NULL || *size == 0)
|
||||
+ return UV_EINVAL;
|
||||
+
|
||||
+ int rc = readlink("/proc/self/exe", buffer, *size);
|
||||
+ if (rc < 0)
|
||||
+ return UV__ERR(errno);
|
||||
+ *size = rc;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int uv_resident_set_memory(size_t* rss) {
|
||||
+ *rss = 0;
|
||||
+ return 0;
|
||||
+}
|
||||
--
|
||||
2.32.0
|
||||
|
Loading…
Reference in a new issue