diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2022-09-25 11:19:54 +0000 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-11 19:55:37 -0700 |
commit | cda5a530e63872ee8700c518f51a4ea5dfba8604 (patch) | |
tree | 2a2eb6c7dc060d7c40e066534e012aef700cd419 /Ports/zig/patches/0013-build-Adjust-build-process-for-SerenityOS.patch | |
parent | 27da878bb793d4f4eae2032a9a2a8acb036a22e1 (diff) | |
download | serenity-cda5a530e63872ee8700c518f51a4ea5dfba8604.zip |
Ports: Add zig port :^)
:yakkie:
The build process for the Zig compiler is more involved than most of
the other ports, because the Zig compiler is mostly self-hosting. In
order to build it, the zig-bootstrap build system is used, which does
the following:
1) Build LLVM for the host OS;
2) Build Zig for the host OS with the SerenityOS target enabled;
3) Build zlib, zstd and LLVM for SerenityOS using `zig cc` as the C/C++
compiler;
4) Build Zig for SerenityOS using the host Zig.
A few hacks are required in order to tell `zig cc` and zig about what
Serenity's libc looks like in the build process, but other than that
it's fairly straightforward. All of the patches that are included with
this commit are Zig-upstream ready once the LLVM patches are upstreamed.
Diffstat (limited to 'Ports/zig/patches/0013-build-Adjust-build-process-for-SerenityOS.patch')
-rw-r--r-- | Ports/zig/patches/0013-build-Adjust-build-process-for-SerenityOS.patch | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Ports/zig/patches/0013-build-Adjust-build-process-for-SerenityOS.patch b/Ports/zig/patches/0013-build-Adjust-build-process-for-SerenityOS.patch new file mode 100644 index 0000000000..b6e180268f --- /dev/null +++ b/Ports/zig/patches/0013-build-Adjust-build-process-for-SerenityOS.patch @@ -0,0 +1,98 @@ +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 5db75471ba94da22550136754c5ae71a56b4527c..2e757e44e852e41bd998ff70c2a9992b69d2910f 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 \ |