1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:37:34 +00:00
serenity/Ports/zig/patches/0011-Add-SerenityOS-target.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

211 lines
8.4 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 | 7 +++++--
zig/src/zig_llvm.h | 3 ++-
8 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/zig/lib/std/target.zig b/zig/lib/std/target.zig
index c3d12b2759cead4c23d3145fe018327f838399ff..608f0e958144fc53dfb67fa2efa29690a60599ba 100644
--- a/zig/lib/std/target.zig
+++ b/zig/lib/std/target.zig
@@ -57,6 +57,7 @@ pub const Target = struct {
glsl450,
vulkan,
plan9,
+ serenity,
other,
pub inline fn isDarwin(tag: Tag) bool {
@@ -264,6 +265,7 @@ pub const Target = struct {
.glsl450, // TODO: GLSL versions
.vulkan,
.plan9,
+ .serenity,
.other,
=> return .{ .none = {} },
@@ -407,6 +409,7 @@ pub const Target = struct {
.openbsd,
.haiku,
.solaris,
+ .serenity,
=> true,
.linux,
@@ -565,6 +568,7 @@ pub const Target = struct {
.watchos,
.driverkit,
.shadermodel,
+ .serenity,
=> return .none,
}
}
@@ -1689,6 +1693,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 e36f411a01a631c7a52cf8ad8b50986ab26c69bd..7c651e4456ec984730e77a6f29e4c61aa4983310 100644
--- a/zig/src/codegen/llvm.zig
+++ b/zig/src/codegen/llvm.zig
@@ -148,6 +148,7 @@ pub fn targetTriple(allocator: Allocator, target: std.Target) ![]const u8 {
.watchos => "watchos",
.driverkit => "driverkit",
.shadermodel => "shadermodel",
+ .serenity => "serenity",
.opencl,
.glsl450,
.vulkan,
@@ -254,6 +255,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 66826caa42547b19a68c2301ece99d1e7a6d5f86..2f9fae37aad13d16fe4fdf0f0ae205ad1c13855b 100644
--- a/zig/src/codegen/llvm/bindings.zig
+++ b/zig/src/codegen/llvm/bindings.zig
@@ -1191,6 +1191,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 2d42a03a32d7601dbdc8358af5c40e0aef482837..ce550aa8db4e1b3b75ad4a1669edbce3b2ddf8a0 100644
--- a/zig/src/libc_installation.zig
+++ b/zig/src/libc_installation.zig
@@ -7,6 +7,7 @@ const Allocator = std.mem.Allocator;
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);
@@ -213,6 +214,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) {
@@ -316,7 +320,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 9d71885e61dea3e9a5a2d45dd31462b0da963367..ed62c1cf0979e26179d18507abece2f0af2f3a04 100644
--- a/zig/src/link/Elf.zig
+++ b/zig/src/link/Elf.zig
@@ -3368,6 +3368,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 2e7cd46e4376efe9d2c543b3aad937dbc5a6f4b0..0219d7419a54ebfc7dd78a058b8871d417b65d01 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.
@@ -378,7 +378,7 @@ pub fn is_libc_lib_name(target: std.Target, name: []const u8) bool {
return false;
}
- if (target.abi.isGnu() or target.abi.isMusl() or target.os.tag.isDarwin()) {
+ if (target.abi.isGnu() or target.abi.isMusl() or target.os.tag.isDarwin() or target.os.tag == .serenity) {
if (eqlIgnoreCase(ignore_case, name, "m"))
return true;
if (eqlIgnoreCase(ignore_case, name, "rt"))
@@ -485,6 +485,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 6671922090761915ed74913602c8b0d5a21d559f..c8c90adfeac7a5a4ee8348bf119491aadaa4c156 100644
--- a/zig/src/zig_llvm.h
+++ b/zig/src/zig_llvm.h
@@ -426,7 +426,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