ladybird/Ports/zig/patches/0013-build-Adjust-build-process-for-SerenityOS.patch
Andre Herbst 14d8403a7b Ports/zig: Bump zig version to 0.12.0-dev.141+ddf5859c2
Fixes build error
```
error "It looks like you're trying to enable vendor availability
markup, but you haven't defined the corresponding macros yet!"
```
while trying to #include <__availability> header without having
the necessary preprocessor directive
`_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS` set
2023-09-29 00:58:17 +02:00

99 lines
3.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: sin-ack <sin-ack@users.noreply.github.com>
Date: Sun, 11 Dec 2022 17:22:27 +0000
Subject: [PATCH] build: Adjust build process for SerenityOS
---
build | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/build b/build
index b1917f6bb18a587d9b5e98171c9f789d9a29aff6..e7d809893e46e247a579050ac61091a78c6b90a5 100755
--- a/build
+++ b/build
@@ -17,6 +17,7 @@ case $TARGET_OS_CMAKE in
freebsd) TARGET_OS_CMAKE="FreeBSD";;
windows) TARGET_OS_CMAKE="Windows";;
linux) TARGET_OS_CMAKE="Linux";;
+ serenity) TARGET_OS_CMAKE="Serenity";;
native) TARGET_OS_CMAKE="";;
esac
@@ -62,10 +63,58 @@ cmake "$ROOTDIR/zig" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_VERSION="$ZIG_VERSION"
cmake --build . --target install
+
+# Create a libc installation file so Zig knows where to look for headers and
+# libraries while compiling for the Serenity target.
+cat <<EOF > "$ROOTDIR/out/libc_installation.txt"
+include_dir=$SERENITY_INSTALL_ROOT/usr/include
+sys_include_dir=$SERENITY_INSTALL_ROOT/usr/include
+crt_dir=$SERENITY_INSTALL_ROOT/usr/lib
+msvc_lib_dir=
+kernel32_lib_dir=
+gcc_dir=
+EOF
+
+export ZIG_LIBC="$ROOTDIR/out/libc_installation.txt"
+
+# Create a CMakeToolchain.txt file to tell CMake about the SerenityOS platform.
+# Adapted from Toolchain/CMake/GNUToolchain.txt.in, with the tool settings
+# removed as zig-bootstrap overrides them manually with the cmake command.
+cat <<EOF > "$ROOTDIR/out/CMakeToolchain.txt"
+if (\${CMAKE_VERSION} VERSION_LESS "3.25.0")
+ list(APPEND CMAKE_MODULE_PATH "$SERENITY_SOURCE_DIR/Toolchain/CMake")
+endif()
+
+set(CMAKE_SYSTEM_NAME SerenityOS)
+set(CMAKE_SYSTEM_PROCESSOR "$SERENITY_ARCH")
+
+set(CMAKE_C_COMPILER_WORKS TRUE)
+set(CMAKE_CXX_COMPILER_WORKS TRUE)
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
+EOF
+
# Now we have Zig as a cross compiler.
ZIG="$ROOTDIR/out/host/bin/zig"
+# Create a serenity/constants.zig file. This package will overwrite the
+# constants.zig file in the upstream Zig in order to provide values for POSIX
+# constants.
+$ZIG run "$ROOTDIR/out/scripts/generate-serenity-constants.zig" \
+ -D__serenity__ \
+ -I"$SERENITY_INSTALL_ROOT/usr/include" \
+ > "$ROOTDIR/zig/lib/std/c/serenity/constants.zig"
+# HACK: Also copy this file over to the host Zig compiler in the prefix. It has
+# to be done this way because we can't generate the constants until we
+# have a Zig compiler, and by the time the host Zig compiler is built
+# the standard library sources have been copied into the prefix already.
+cp "$ROOTDIR/zig/lib/std/c/serenity/constants.zig" \
+ "$ROOTDIR/out/host/lib/zig/std/c/serenity/constants.zig"
+
# First cross compile zlib for the target, as we need the LLVM linked into
# the final zig binary to have zlib support enabled.
mkdir -p "$ROOTDIR/out/build-zlib-$TARGET-$MCPU"
@@ -81,7 +130,8 @@ cmake "$ROOTDIR/zlib" \
-DCMAKE_ASM_COMPILER="$ZIG;cc;-fno-sanitize=all;-s;-target;$TARGET;-mcpu=$MCPU" \
-DCMAKE_RC_COMPILER="$ROOTDIR/out/host/bin/llvm-rc" \
-DCMAKE_AR="$ROOTDIR/out/host/bin/llvm-ar" \
- -DCMAKE_RANLIB="$ROOTDIR/out/host/bin/llvm-ranlib"
+ -DCMAKE_RANLIB="$ROOTDIR/out/host/bin/llvm-ranlib" \
+ -DCMAKE_TOOLCHAIN_FILE="$ROOTDIR/out/CMakeToolchain.txt"
cmake --build . --target install
# Same deal for zstd.
@@ -144,6 +194,7 @@ cmake "$ROOTDIR/llvm" \
-DCMAKE_RC_COMPILER="$ROOTDIR/out/host/bin/llvm-rc" \
-DCMAKE_AR="$ROOTDIR/out/host/bin/llvm-ar" \
-DCMAKE_RANLIB="$ROOTDIR/out/host/bin/llvm-ranlib" \
+ -DCMAKE_TOOLCHAIN_FILE="$ROOTDIR/out/CMakeToolchain.txt" \
-DLLVM_ENABLE_BACKTRACES=OFF \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_CRASH_OVERRIDES=OFF \