1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 02:28:12 +00:00
serenity/Ports/zig/patches/0011-Add-SerenityOS-target.patch
sin-ack 752d9d7c03 Ports: Bump Zig version to 0.11.0-dev.4003+c6aa29b6f
This commit fixes the build for LLVM 16 now that the toolchain has been
updated, and updates us to the latest available Zig commit.

The main patch changes are making more symbols available (and exposing
them through std.c.serenity) and working around new Zig build
requirements.

Co-Authored-By: Andre Herbst <moormaster@gmx.net>
2023-07-17 22:52:08 +01:00

202 lines
8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: sin-ack <sin-ack@users.noreply.github.com>
Date: Sun, 16 Jul 2023 17:34:51 +0300
Subject: [PATCH] Add SerenityOS target
Named "serenity" within the code to match what LLVM says.
---
zig/lib/std/target.zig | 6 ++++++
zig/lib/std/zig/CrossTarget.zig | 2 ++
zig/src/codegen/llvm.zig | 2 ++
zig/src/codegen/llvm/bindings.zig | 1 +
zig/src/libc_installation.zig | 6 +++++-
zig/src/link/Elf.zig | 9 +++++++++
zig/src/target.zig | 5 ++++-
zig/src/zig_llvm.h | 3 ++-
8 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/zig/lib/std/target.zig b/zig/lib/std/target.zig
index 2a96e84001ebf67ce29a9059f62045776530549a..b137e48c02d7d7ecc0f5eae61f6225504bf0ba3d 100644
--- a/zig/lib/std/target.zig
+++ b/zig/lib/std/target.zig
@@ -60,6 +60,7 @@ pub const Target = struct {
glsl450,
vulkan,
plan9,
+ serenity,
other,
pub fn isDarwin(tag: Tag) bool {
@@ -267,6 +268,7 @@ pub const Target = struct {
.glsl450, // TODO: GLSL versions
.vulkan,
.plan9,
+ .serenity,
.other,
=> return .{ .none = {} },
@@ -410,6 +412,7 @@ pub const Target = struct {
.openbsd,
.haiku,
.solaris,
+ .serenity,
=> true,
.linux,
@@ -568,6 +571,7 @@ pub const Target = struct {
.watchos,
.driverkit,
.shadermodel,
+ .serenity,
=> return .none,
}
}
@@ -1690,6 +1694,8 @@ pub const Target = struct {
// TODO revisit when multi-arch for Haiku is available
.haiku => return copy(&result, "/system/runtime_loader"),
+ .serenity => return copy(&result, "/usr/lib/Loader.so"),
+
// TODO go over each item in this list and either move it to the above list, or
// implement the standard dynamic linker path code for it.
.ananas,
diff --git a/zig/lib/std/zig/CrossTarget.zig b/zig/lib/std/zig/CrossTarget.zig
index d42b02d931dc3afa7cc33b1576ec77d123fc5bd5..479c1bffc8df034ee2d876118c1aa2579758ac44 100644
--- a/zig/lib/std/zig/CrossTarget.zig
+++ b/zig/lib/std/zig/CrossTarget.zig
@@ -137,6 +137,7 @@ fn updateOsVersionRange(self: *CrossTarget, os: Target.Os) void {
.glsl450,
.vulkan,
.plan9,
+ .serenity,
.other,
=> {
self.os_version_min = .{ .none = {} };
@@ -734,6 +735,7 @@ fn parseOs(result: *CrossTarget, diags: *ParseOptions.Diagnostics, text: []const
.plan9,
.driverkit,
.shadermodel,
+ .serenity,
.other,
=> return error.InvalidOperatingSystemVersion,
diff --git a/zig/src/codegen/llvm.zig b/zig/src/codegen/llvm.zig
index ec456e53a7b29be235ec329882e593545273c732..32baa8fbb39a699e57450ed36d5897991c32524b 100644
--- a/zig/src/codegen/llvm.zig
+++ b/zig/src/codegen/llvm.zig
@@ -144,6 +144,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 {
.watchos => "watchos",
.driverkit => "driverkit",
.shadermodel => "shadermodel",
+ .serenity => "serenity",
.opencl,
.glsl450,
.vulkan,
@@ -250,6 +251,7 @@ pub fn targetOs(os_tag: std.Target.Os.Tag) llvm.OSType {
.emscripten => .Emscripten,
.driverkit => .DriverKit,
.shadermodel => .ShaderModel,
+ .serenity => .Serenity,
};
}
diff --git a/zig/src/codegen/llvm/bindings.zig b/zig/src/codegen/llvm/bindings.zig
index b093588e80c1dcbcd3d515ffa09b9ffefcd55828..385b17bd16a2f957f6e79bd7c068820415bcae6f 100644
--- a/zig/src/codegen/llvm/bindings.zig
+++ b/zig/src/codegen/llvm/bindings.zig
@@ -1298,6 +1298,7 @@ pub const OSType = enum(c_int) {
WASI,
Emscripten,
ShaderModel,
+ Serenity,
};
pub const ArchType = enum(c_int) {
diff --git a/zig/src/libc_installation.zig b/zig/src/libc_installation.zig
index 355c3bad8dcd53a03e4df133f0a470b91d390a22..c048b865270640877e0bd042c21faa7e8317991f 100644
--- a/zig/src/libc_installation.zig
+++ b/zig/src/libc_installation.zig
@@ -8,6 +8,7 @@ const build_options = @import("build_options");
const is_darwin = builtin.target.isDarwin();
const is_windows = builtin.target.os.tag == .windows;
const is_haiku = builtin.target.os.tag == .haiku;
+const is_serenity = builtin.target.os.tag == .serenity;
const log = std.log.scoped(.libc_installation);
@@ -205,6 +206,9 @@ pub const LibCInstallation = struct {
try self.findNativeIncludeDirPosix(args);
try self.findNativeCrtBeginDirHaiku(args);
self.crt_dir = try args.allocator.dupeZ(u8, "/system/develop/lib");
+ } else if (is_serenity) {
+ try self.findNativeIncludeDirPosix(args);
+ self.crt_dir = try args.allocator.dupeZ(u8, "/usr/lib");
} else if (std.process.can_spawn) {
try self.findNativeIncludeDirPosix(args);
switch (builtin.target.os.tag) {
@@ -308,7 +312,7 @@ pub const LibCInstallation = struct {
const include_dir_example_file = if (is_haiku) "posix/stdlib.h" else "stdlib.h";
const sys_include_dir_example_file = if (is_windows)
"sys\\types.h"
- else if (is_haiku)
+ else if (is_haiku or is_serenity)
"errno.h"
else
"sys/errno.h";
diff --git a/zig/src/link/Elf.zig b/zig/src/link/Elf.zig
index 0258b0a6a70ad07bf6bad54ccf24954d67bb98d9..fc2d11a10eb8aa31a739a0da15b592cd0f0b90ac 100644
--- a/zig/src/link/Elf.zig
+++ b/zig/src/link/Elf.zig
@@ -3382,6 +3382,15 @@ const CsuObjects = struct {
.static_pie => result.set( "rcrt0.o", null, "crtbegin.o", "crtend.o", null ),
// zig fmt: on
},
+ .serenity => switch (mode) {
+ // zig fmt: off
+ .dynamic_lib => result.set( "crt0_shared.o", "crti.o", null, null, "crtn.o" ),
+ .dynamic_exe,
+ .dynamic_pie,
+ .static_exe,
+ .static_pie => result.set( "crt0.o", "crti.o", null, null, "crtn.o" ),
+ // zig fmt: on
+ },
.haiku => switch (mode) {
// zig fmt: off
.dynamic_lib => result.set( null, "crti.o", "crtbeginS.o", "crtendS.o", "crtn.o" ),
diff --git a/zig/src/target.zig b/zig/src/target.zig
index f07dcc43d21e516ef5e5f392d231207a4e6389eb..95efc730d9c2ba61a19200bf11ad1456a37650dc 100644
--- a/zig/src/target.zig
+++ b/zig/src/target.zig
@@ -190,7 +190,7 @@ pub fn libcNeedsLibUnwind(target: std.Target) bool {
}
pub fn requiresPIE(target: std.Target) bool {
- return target.isAndroid() or target.isDarwin() or target.os.tag == .openbsd;
+ return target.isAndroid() or target.isDarwin() or target.os.tag == .openbsd or target.os.tag == .serenity;
}
/// This function returns whether non-pic code is completely invalid on the given target.
@@ -476,6 +476,9 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
"-lpthread",
"-lc",
},
+ .serenity => &[_][]const u8{
+ "-lc",
+ },
else => switch (target.abi) {
.android => &[_][]const u8{
"-lm",
diff --git a/zig/src/zig_llvm.h b/zig/src/zig_llvm.h
index 74dcd105649ab9633f67a8caaf26e2d3ba5b5aef..6dc140d69c16935654a9d58658184def3464be35 100644
--- a/zig/src/zig_llvm.h
+++ b/zig/src/zig_llvm.h
@@ -475,7 +475,8 @@ enum ZigLLVM_OSType {
ZigLLVM_WASI, // Experimental WebAssembly OS
ZigLLVM_Emscripten,
ZigLLVM_ShaderModel, // DirectX ShaderModel
- ZigLLVM_LastOSType = ZigLLVM_ShaderModel
+ ZigLLVM_Serenity, // Well hello friends! :^)
+ ZigLLVM_LastOSType = ZigLLVM_Serenity
};
// Synchronize with target.cpp::abi_list