1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:24:58 +00:00

AK+Lagom: Make it possible to build for iOS

This commit makes it possible to build AK and most of Lagom for iOS,
based on the work for the Ladybird build demoed on discord:
1211987732
This commit is contained in:
Filiph Siitam Sandström 2024-02-27 14:32:29 +01:00 committed by Andrew Kaster
parent 2dce453f11
commit fd694e8672
17 changed files with 44 additions and 31 deletions

View file

@ -68,11 +68,16 @@
# define AK_OS_LINUX # define AK_OS_LINUX
#endif #endif
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__) && !defined(__IOS__)
# define AK_OS_MACOS # define AK_OS_MACOS
# define AK_OS_BSD_GENERIC # define AK_OS_BSD_GENERIC
#endif #endif
#if defined(__IOS__)
# define AK_OS_IOS
# define AK_OS_BSD_GENERIC
#endif
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
# define AK_OS_BSD_GENERIC # define AK_OS_BSD_GENERIC
# define AK_OS_FREEBSD # define AK_OS_FREEBSD

View file

@ -12,9 +12,9 @@
#ifdef AK_OS_SERENITY #ifdef AK_OS_SERENITY
# include <serenity.h> # include <serenity.h>
#elif defined(AK_OS_LINUX) or defined(AK_LIBC_GLIBC) or defined(AK_OS_MACOS) or defined(AK_OS_NETBSD) or defined(AK_OS_SOLARIS) or defined(AK_OS_HAIKU) #elif defined(AK_OS_LINUX) || defined(AK_LIBC_GLIBC) || defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_NETBSD) || defined(AK_OS_SOLARIS) || defined(AK_OS_HAIKU)
# include <pthread.h> # include <pthread.h>
#elif defined(AK_OS_FREEBSD) or defined(AK_OS_OPENBSD) #elif defined(AK_OS_FREEBSD) || defined(AK_OS_OPENBSD)
# include <pthread.h> # include <pthread.h>
# include <pthread_np.h> # include <pthread_np.h>
#elif defined(AK_OS_WINDOWS) #elif defined(AK_OS_WINDOWS)
@ -54,7 +54,7 @@ StackInfo::StackInfo()
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
#elif defined(AK_OS_MACOS) #elif defined(AK_OS_MACOS) || defined(AK_OS_IOS)
// NOTE: !! On MacOS, pthread_get_stackaddr_np gives the TOP of the stack, not the bottom! // NOTE: !! On MacOS, pthread_get_stackaddr_np gives the TOP of the stack, not the bottom!
FlatPtr top_of_stack = (FlatPtr)pthread_get_stackaddr_np(pthread_self()); FlatPtr top_of_stack = (FlatPtr)pthread_get_stackaddr_np(pthread_self());
m_size = (size_t)pthread_get_stacksize_np(pthread_self()); m_size = (size_t)pthread_get_stacksize_np(pthread_self());

View file

@ -8,7 +8,7 @@ project(ladybird
include(GNUInstallDirs) include(GNUInstallDirs)
if (ANDROID) if (ANDROID OR IOS)
set(BUILD_SHARED_LIBS OFF) set(BUILD_SHARED_LIBS OFF)
endif() endif()

View file

@ -42,7 +42,7 @@ if (ENABLE_QT)
endif() endif()
else() else()
set(LIB_TYPE STATIC) set(LIB_TYPE STATIC)
if (ANDROID) if (ANDROID OR IOS)
set(LIB_TYPE SHARED) set(LIB_TYPE SHARED)
endif() endif()
add_library(webcontent ${LIB_TYPE} ${WEBCONTENT_SOURCES}) add_library(webcontent ${LIB_TYPE} ${WEBCONTENT_SOURCES})

View file

@ -4,7 +4,7 @@ if (NOT ENABLE_ACCELERATED_GRAPHICS OR EMSCRIPTEN)
return() return()
endif() endif()
if (APPLE) if (APPLE AND NOT IOS)
set(HAS_ACCELERATED_GRAPHICS ON CACHE BOOL "" FORCE) set(HAS_ACCELERATED_GRAPHICS ON CACHE BOOL "" FORCE)
set(ACCEL_GFX_LIBS "-framework OpenGL" CACHE STRING "" FORCE) set(ACCEL_GFX_LIBS "-framework OpenGL" CACHE STRING "" FORCE)
else() else()

View file

@ -539,7 +539,7 @@ if (BUILD_LAGOM)
add_serenity_subdirectory(Userland/Shell) add_serenity_subdirectory(Userland/Shell)
if (NOT ENABLE_FUZZERS AND NOT ENABLE_COMPILER_EXPLORER_BUILD AND NOT ANDROID) if (NOT ENABLE_FUZZERS AND NOT ENABLE_COMPILER_EXPLORER_BUILD AND NOT ANDROID AND NOT IOS)
# Lagom Services # Lagom Services
add_serenity_subdirectory(Userland/Services) add_serenity_subdirectory(Userland/Services)

View file

@ -42,7 +42,7 @@ if (HAVE_PULSEAUDIO)
target_compile_definitions(LibAudio PRIVATE HAVE_PULSEAUDIO=1) target_compile_definitions(LibAudio PRIVATE HAVE_PULSEAUDIO=1)
endif() endif()
if (APPLE) if (APPLE AND NOT IOS)
target_sources(LibAudio PRIVATE PlaybackStreamAudioUnit.cpp) target_sources(LibAudio PRIVATE PlaybackStreamAudioUnit.cpp)
find_library(AUDIO_UNIT AudioUnit REQUIRED) find_library(AUDIO_UNIT AudioUnit REQUIRED)

View file

@ -9,7 +9,7 @@
// Include the 119.9 KiB of dictionary data from a binary file // Include the 119.9 KiB of dictionary data from a binary file
extern u8 const brotli_dictionary_data[]; extern u8 const brotli_dictionary_data[];
#if defined(AK_OS_MACOS) #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
asm(".const_data\n" asm(".const_data\n"
".globl _brotli_dictionary_data\n" ".globl _brotli_dictionary_data\n"
"_brotli_dictionary_data:\n"); "_brotli_dictionary_data:\n");

View file

@ -55,7 +55,7 @@ if (SERENITYOS)
list(APPEND SOURCES FileWatcherSerenity.cpp) list(APPEND SOURCES FileWatcherSerenity.cpp)
elseif (LINUX AND NOT EMSCRIPTEN) elseif (LINUX AND NOT EMSCRIPTEN)
list(APPEND SOURCES FileWatcherLinux.cpp) list(APPEND SOURCES FileWatcherLinux.cpp)
elseif (APPLE) elseif (APPLE AND NOT IOS)
list(APPEND SOURCES FileWatcherMacOS.mm) list(APPEND SOURCES FileWatcherMacOS.mm)
else() else()
list(APPEND SOURCES FileWatcherUnimplemented.cpp) list(APPEND SOURCES FileWatcherUnimplemented.cpp)

View file

@ -10,7 +10,7 @@
#include "Environment.h" #include "Environment.h"
#include <AK/ByteString.h> #include <AK/ByteString.h>
#if defined(AK_OS_MACOS) #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
# include <crt_externs.h> # include <crt_externs.h>
#else #else
extern char** environ; extern char** environ;
@ -20,7 +20,7 @@ namespace Core::Environment {
char** raw_environ() char** raw_environ()
{ {
#if defined(AK_OS_MACOS) #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
return *_NSGetEnviron(); return *_NSGetEnviron();
#else #else
return environ; return environ;

View file

@ -81,7 +81,7 @@ bool LocalServer::listen(ByteString const& address)
fcntl(m_fd, F_SETFD, FD_CLOEXEC); fcntl(m_fd, F_SETFD, FD_CLOEXEC);
#endif #endif
VERIFY(m_fd >= 0); VERIFY(m_fd >= 0);
#ifndef AK_OS_MACOS #if !defined(AK_OS_MACOS) && !defined(AK_OS_IOS)
rc = fchmod(m_fd, 0600); rc = fchmod(m_fd, 0600);
if (rc < 0) { if (rc < 0) {
perror("fchmod"); perror("fchmod");
@ -118,7 +118,7 @@ ErrorOr<NonnullOwnPtr<LocalSocket>> LocalServer::accept()
VERIFY(m_listening); VERIFY(m_listening);
sockaddr_un un; sockaddr_un un;
socklen_t un_size = sizeof(un); socklen_t un_size = sizeof(un);
#if !defined(AK_OS_MACOS) && !defined(AK_OS_HAIKU) #if !defined(AK_OS_MACOS) && !defined(AK_OS_IOS) && !defined(AK_OS_HAIKU)
int accepted_fd = ::accept4(m_fd, (sockaddr*)&un, &un_size, SOCK_NONBLOCK | SOCK_CLOEXEC); int accepted_fd = ::accept4(m_fd, (sockaddr*)&un, &un_size, SOCK_NONBLOCK | SOCK_CLOEXEC);
#else #else
int accepted_fd = ::accept(m_fd, (sockaddr*)&un, &un_size); int accepted_fd = ::accept(m_fd, (sockaddr*)&un, &un_size);
@ -127,7 +127,7 @@ ErrorOr<NonnullOwnPtr<LocalSocket>> LocalServer::accept()
return Error::from_syscall("accept"sv, -errno); return Error::from_syscall("accept"sv, -errno);
} }
#if defined(AK_OS_MACOS) || defined(AK_OS_HAIKU) #if defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_HAIKU)
int option = 1; int option = 1;
ioctl(m_fd, FIONBIO, &option); ioctl(m_fd, FIONBIO, &option);
(void)fcntl(accepted_fd, F_SETFD, FD_CLOEXEC); (void)fcntl(accepted_fd, F_SETFD, FD_CLOEXEC);

View file

@ -358,7 +358,7 @@ ErrorOr<void> LocalSocket::send_fd(int fd)
ErrorOr<pid_t> LocalSocket::peer_pid() const ErrorOr<pid_t> LocalSocket::peer_pid() const
{ {
#ifdef AK_OS_MACOS #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
pid_t pid; pid_t pid;
socklen_t pid_size = sizeof(pid); socklen_t pid_size = sizeof(pid);
#elif defined(AK_OS_FREEBSD) #elif defined(AK_OS_FREEBSD)
@ -380,7 +380,7 @@ ErrorOr<pid_t> LocalSocket::peer_pid() const
socklen_t creds_size = sizeof(creds); socklen_t creds_size = sizeof(creds);
#endif #endif
#ifdef AK_OS_MACOS #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
TRY(System::getsockopt(m_helper.fd(), SOL_LOCAL, LOCAL_PEERPID, &pid, &pid_size)); TRY(System::getsockopt(m_helper.fd(), SOL_LOCAL, LOCAL_PEERPID, &pid, &pid_size));
return pid; return pid;
#elif defined(AK_OS_FREEBSD) #elif defined(AK_OS_FREEBSD)

View file

@ -47,7 +47,7 @@ static int memfd_create(char const* name, unsigned int flags)
} }
#endif #endif
#if defined(AK_OS_MACOS) #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
# include <mach-o/dyld.h> # include <mach-o/dyld.h>
# include <sys/mman.h> # include <sys/mman.h>
#else #else
@ -140,7 +140,7 @@ static ErrorOr<Optional<struct group>> getgrent_impl(Span<char> buffer)
namespace Core::System { namespace Core::System {
#ifndef HOST_NAME_MAX #ifndef HOST_NAME_MAX
# ifdef AK_OS_MACOS # if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
# define HOST_NAME_MAX 255 # define HOST_NAME_MAX 255
# else # else
# define HOST_NAME_MAX 64 # define HOST_NAME_MAX 64
@ -399,7 +399,7 @@ ErrorOr<Optional<struct spwd>> getspnam(StringView name)
} }
#endif #endif
#if !defined(AK_OS_MACOS) && !defined(AK_OS_HAIKU) #if !defined(AK_OS_MACOS) && !defined(AK_OS_IOS) && !defined(AK_OS_HAIKU)
ErrorOr<int> accept4(int sockfd, sockaddr* address, socklen_t* address_length, int flags) ErrorOr<int> accept4(int sockfd, sockaddr* address, socklen_t* address_length, int flags)
{ {
auto fd = ::accept4(sockfd, address, address_length, flags); auto fd = ::accept4(sockfd, address, address_length, flags);
@ -898,17 +898,19 @@ ErrorOr<Optional<struct group>> getgrnam(StringView name)
return Optional<struct group> {}; return Optional<struct group> {};
} }
#if !defined(AK_OS_IOS)
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts) ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts)
{ {
#ifdef AK_OS_SERENITY # ifdef AK_OS_SERENITY
int rc = syscall(SC_clock_settime, clock_id, ts); int rc = syscall(SC_clock_settime, clock_id, ts);
HANDLE_SYSCALL_RETURN_VALUE("clocksettime", rc, {}); HANDLE_SYSCALL_RETURN_VALUE("clocksettime", rc, {});
#else # else
if (::clock_settime(clock_id, ts) < 0) if (::clock_settime(clock_id, ts) < 0)
return Error::from_syscall("clocksettime"sv, -errno); return Error::from_syscall("clocksettime"sv, -errno);
return {}; return {};
#endif # endif
} }
#endif
static ALWAYS_INLINE ErrorOr<pid_t> posix_spawn_wrapper(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[], StringView function_name, decltype(::posix_spawn) spawn_function) static ALWAYS_INLINE ErrorOr<pid_t> posix_spawn_wrapper(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[], StringView function_name, decltype(::posix_spawn) spawn_function)
{ {
@ -1379,7 +1381,7 @@ ErrorOr<void> exec(StringView filename, ReadonlySpan<StringView> arguments, Sear
envp[environment->size()] = nullptr; envp[environment->size()] = nullptr;
if (search_in_path == SearchInPath::Yes && !filename.contains('/')) { if (search_in_path == SearchInPath::Yes && !filename.contains('/')) {
# if defined(AK_OS_MACOS) || defined(AK_OS_FREEBSD) || defined(AK_OS_SOLARIS) # if defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_FREEBSD) || defined(AK_OS_SOLARIS)
// These BSDs don't support execvpe(), so we'll have to manually search the PATH. // These BSDs don't support execvpe(), so we'll have to manually search the PATH.
ScopedValueRollback errno_rollback(errno); ScopedValueRollback errno_rollback(errno);
@ -1782,7 +1784,7 @@ ErrorOr<ByteString> current_executable_path()
size_t len = sizeof(path); size_t len = sizeof(path);
if (sysctl(mib, 4, path, &len, nullptr, 0) < 0) if (sysctl(mib, 4, path, &len, nullptr, 0) < 0)
return Error::from_syscall("sysctl"sv, -errno); return Error::from_syscall("sysctl"sv, -errno);
#elif defined(AK_OS_MACOS) #elif defined(AK_OS_MACOS) || defined(AK_OS_IOS)
u32 size = sizeof(path); u32 size = sizeof(path);
auto ret = _NSGetExecutablePath(path, &size); auto ret = _NSGetExecutablePath(path, &size);
if (ret != 0) if (ret != 0)

View file

@ -152,7 +152,11 @@ ErrorOr<Optional<struct group>> getgrnam(StringView name);
ErrorOr<Optional<struct passwd>> getpwuid(uid_t); ErrorOr<Optional<struct passwd>> getpwuid(uid_t);
ErrorOr<Optional<struct group>> getgrent(Span<char> buffer); ErrorOr<Optional<struct group>> getgrent(Span<char> buffer);
ErrorOr<Optional<struct group>> getgrgid(gid_t); ErrorOr<Optional<struct group>> getgrgid(gid_t);
#if !defined(AK_OS_IOS)
ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts); ErrorOr<void> clock_settime(clockid_t clock_id, struct timespec* ts);
#endif
ErrorOr<pid_t> posix_spawn(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[]); ErrorOr<pid_t> posix_spawn(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[]);
ErrorOr<pid_t> posix_spawnp(StringView path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]); ErrorOr<pid_t> posix_spawnp(StringView path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]);
ErrorOr<off_t> lseek(int fd, off_t, int whence); ErrorOr<off_t> lseek(int fd, off_t, int whence);

View file

@ -80,7 +80,7 @@ ErrorOr<NonnullOwnPtr<TCPSocket>> TCPServer::accept()
VERIFY(m_listening); VERIFY(m_listening);
sockaddr_in in; sockaddr_in in;
socklen_t in_size = sizeof(in); socklen_t in_size = sizeof(in);
#if !defined(AK_OS_MACOS) && !defined(AK_OS_HAIKU) #if !defined(AK_OS_MACOS) && !defined(AK_OS_IOS) && !defined(AK_OS_HAIKU)
int accepted_fd = TRY(Core::System::accept4(m_fd, (sockaddr*)&in, &in_size, SOCK_NONBLOCK | SOCK_CLOEXEC)); int accepted_fd = TRY(Core::System::accept4(m_fd, (sockaddr*)&in, &in_size, SOCK_NONBLOCK | SOCK_CLOEXEC));
#else #else
int accepted_fd = TRY(Core::System::accept(m_fd, (sockaddr*)&in, &in_size)); int accepted_fd = TRY(Core::System::accept(m_fd, (sockaddr*)&in, &in_size));
@ -88,7 +88,7 @@ ErrorOr<NonnullOwnPtr<TCPSocket>> TCPServer::accept()
auto socket = TRY(TCPSocket::adopt_fd(accepted_fd)); auto socket = TRY(TCPSocket::adopt_fd(accepted_fd));
#if defined(AK_OS_MACOS) || defined(AK_OS_HAIKU) #if defined(AK_OS_MACOS) || defined(AK_OS_IOS) || defined(AK_OS_HAIKU)
// FIXME: Ideally, we should let the caller decide whether it wants the // FIXME: Ideally, we should let the caller decide whether it wants the
// socket to be nonblocking or not, but there are currently places // socket to be nonblocking or not, but there are currently places
// which depend on this. // which depend on this.

View file

@ -14,7 +14,7 @@
#if defined(AK_OS_SERENITY) #if defined(AK_OS_SERENITY)
# include <serenity.h> # include <serenity.h>
#elif defined(AK_OS_BSD_GENERIC) #elif !defined(AK_OS_IOS) && defined(AK_OS_BSD_GENERIC)
# include <sys/disk.h> # include <sys/disk.h>
#elif defined(AK_OS_LINUX) #elif defined(AK_OS_LINUX)
# include <linux/fs.h> # include <linux/fs.h>
@ -230,7 +230,7 @@ ErrorOr<void> copy_file(StringView destination_path, StringView source_path, str
if (has_flag(preserve_mode, PreserveMode::Timestamps)) { if (has_flag(preserve_mode, PreserveMode::Timestamps)) {
struct timespec times[2] = { struct timespec times[2] = {
#ifdef AK_OS_MACOS #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
source_stat.st_atimespec, source_stat.st_atimespec,
source_stat.st_mtimespec, source_stat.st_mtimespec,
#else #else
@ -278,7 +278,7 @@ ErrorOr<void> copy_directory(StringView destination_path, StringView source_path
if (has_flag(preserve_mode, PreserveMode::Timestamps)) { if (has_flag(preserve_mode, PreserveMode::Timestamps)) {
struct timespec times[2] = { struct timespec times[2] = {
#ifdef AK_OS_MACOS #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
source_stat.st_atimespec, source_stat.st_atimespec,
source_stat.st_mtimespec, source_stat.st_mtimespec,
#else #else

View file

@ -38,6 +38,8 @@ namespace Web {
# define OS_STRING "Linux" # define OS_STRING "Linux"
#elif defined(AK_OS_MACOS) #elif defined(AK_OS_MACOS)
# define OS_STRING "macOS" # define OS_STRING "macOS"
#elif defined(AK_OS_IOS)
# define OS_STRING "iOS"
#elif defined(AK_OS_WINDOWS) #elif defined(AK_OS_WINDOWS)
# define OS_STRING "Windows" # define OS_STRING "Windows"
#elif defined(AK_OS_FREEBSD) #elif defined(AK_OS_FREEBSD)