From 5466b3ff26a3fb918bf143febf2233a19c8d6c76 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Tue, 27 May 2025 16:16:32 +0200 Subject: [PATCH] add patch to add library directories --- ...ve-native-lib-directories-from-rpath.patch | 2 +- 0002-std.Build-add-build-id-option.patch | 2 +- ...-bounds-of-main-zig-executable-to-9G.patch | 2 +- ...ib-dir-as-directory-instead-of-as-st.patch | 2 +- ...t-directory-of-libraries-to-linker-p.patch | 40 +++++++++++++++++++ zig.spec | 15 +++++-- 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 0005-link.Elf-add-root-directory-of-libraries-to-linker-p.patch diff --git a/0001-remove-native-lib-directories-from-rpath.patch b/0001-remove-native-lib-directories-from-rpath.patch index a026bfc..ae39355 100644 --- a/0001-remove-native-lib-directories-from-rpath.patch +++ b/0001-remove-native-lib-directories-from-rpath.patch @@ -1,7 +1,7 @@ From 874ce2357bb7e7398115fc6f37f3f3817a9116ba Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Tue, 11 Jun 2024 13:35:37 +0200 -Subject: [PATCH 1/4] remove native lib directories from rpath +Subject: [PATCH 1/5] remove native lib directories from rpath Signed-off-by: Jan200101 --- diff --git a/0002-std.Build-add-build-id-option.patch b/0002-std.Build-add-build-id-option.patch index 4cef24a..3541011 100644 --- a/0002-std.Build-add-build-id-option.patch +++ b/0002-std.Build-add-build-id-option.patch @@ -1,7 +1,7 @@ From fd127fafb534eade533655688c4977ae4f7cebe0 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 17 Jan 2025 20:53:30 +0100 -Subject: [PATCH 2/4] std.Build: add build-id option +Subject: [PATCH 2/5] std.Build: add build-id option Signed-off-by: Jan200101 --- diff --git a/0003-increase-upper-bounds-of-main-zig-executable-to-9G.patch b/0003-increase-upper-bounds-of-main-zig-executable-to-9G.patch index b23c4f3..207cc73 100644 --- a/0003-increase-upper-bounds-of-main-zig-executable-to-9G.patch +++ b/0003-increase-upper-bounds-of-main-zig-executable-to-9G.patch @@ -1,7 +1,7 @@ From e4b31d2e6cba763f4427bc689c7aa27978d47f49 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Mon, 21 Apr 2025 23:28:27 +0200 -Subject: [PATCH 3/4] increase upper bounds of main zig executable to 9G +Subject: [PATCH 3/5] increase upper bounds of main zig executable to 9G On Fedora 42 aarch64 memory usage peaked at 8736403456 bytes diff --git a/0004-build-pass-zig-lib-dir-as-directory-instead-of-as-st.patch b/0004-build-pass-zig-lib-dir-as-directory-instead-of-as-st.patch index c5f1c72..f91eb91 100644 --- a/0004-build-pass-zig-lib-dir-as-directory-instead-of-as-st.patch +++ b/0004-build-pass-zig-lib-dir-as-directory-instead-of-as-st.patch @@ -1,7 +1,7 @@ From 2f379308820b58049cfe0aaca1eb4f77700d0047 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 24 Apr 2025 17:35:29 +0200 -Subject: [PATCH 4/4] build: pass zig lib dir as directory instead of as string +Subject: [PATCH 4/5] build: pass zig lib dir as directory instead of as string Signed-off-by: Jan200101 --- diff --git a/0005-link.Elf-add-root-directory-of-libraries-to-linker-p.patch b/0005-link.Elf-add-root-directory-of-libraries-to-linker-p.patch new file mode 100644 index 0000000..4bfc87d --- /dev/null +++ b/0005-link.Elf-add-root-directory-of-libraries-to-linker-p.patch @@ -0,0 +1,40 @@ +From 48aa23307d1a47b444854fc09478da6d4ee8e624 Mon Sep 17 00:00:00 2001 +From: Jan200101 +Date: Sun, 11 May 2025 01:09:41 +0200 +Subject: [PATCH 5/5] link.Elf: add root directory of libraries to linker path + +all the given dynamic shared objects will be linked with an absolute path however they may link to other dynamic shared objects which won't have an absolute path, for this we need to add the library path so that lld can resolve it + +Signed-off-by: Jan200101 +--- + src/link/Elf.zig | 12 +++++++++++- + 1 file changed, 11 insertions(+), 1 deletion(-) + +diff --git a/src/link/Elf.zig b/src/link/Elf.zig +index 53f88101b1..fe2b7abd48 100644 +--- a/src/link/Elf.zig ++++ b/src/link/Elf.zig +@@ -1938,9 +1938,19 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s + // Positional arguments to the linker such as object files. + var whole_archive = false; + ++ var lib_directories = std.StringArrayHashMap(void).init(gpa); ++ defer lib_directories.deinit(); ++ + for (self.base.comp.link_inputs) |link_input| switch (link_input) { + .res => unreachable, // Windows-only +- .dso => continue, ++ .dso => |dso| { ++ if (dso.path.root_dir.path) |root_dir| { ++ const lib_dir = try lib_directories.getOrPut(root_dir); ++ if (lib_dir.found_existing) continue; ++ try argv.append("-L"); ++ try argv.append(root_dir); ++ } ++ }, + .object, .archive => |obj| { + if (obj.must_link and !whole_archive) { + try argv.append("-whole-archive"); +-- +2.49.0 + diff --git a/zig.spec b/zig.spec index f56d714..e1afe52 100644 --- a/zig.spec +++ b/zig.spec @@ -44,7 +44,7 @@ Name: zig Version: 0.14.0 -Release: 3%{?dist} +Release: 4%{?dist} Summary: Programming language for maintaining robust, optimal, and reusable software License: MIT AND NCSA AND LGPL-2.1-or-later AND LGPL-2.1-or-later WITH GCC-exception-2.0 AND GPL-2.0-or-later AND GPL-2.0-or-later WITH GCC-exception-2.0 AND BSD-3-Clause AND Inner-Net-2.0 AND ISC AND LicenseRef-Fedora-Public-Domain AND GFDL-1.1-or-later AND ZPL-2.1 @@ -71,11 +71,17 @@ Patch: 0003-increase-upper-bounds-of-main-zig-executable-to-9G.patch # every snippet of code in the documentation is tested to see if it works # while doing this zig incorrectly passes a relative path to the doctest tool # which is ran in a temporary directory making that path invalid +# This patch was superseded by https://github.com/ziglang/zig/pull/23894 which +# implements a proper fix, but for our use case this is good enough. # https://github.com/ziglang/zig/pull/23644 Patch: 0004-build-pass-zig-lib-dir-as-directory-instead-of-as-st.patch +# lld will try to resolve every libary of a shared object thats used for this we need +# add specify the library directories, this patch adds them back. +# This wasn't an issue with the cc binary present because zig will call it to figure +# out more system paths. +# https://github.com/ziglang/zig/pull/23850 +Patch: 0005-link.Elf-add-root-directory-of-libraries-to-linker-p.patch -# Zig invokes the C compiler to figure out system info -Requires: gcc BuildRequires: gcc BuildRequires: gcc-c++ BuildRequires: cmake @@ -244,6 +250,9 @@ install -D -pv -m 0644 %{SOURCE2} %{buildroot}%{_rpmmacrodir}/macros.%{name} %endif %changelog +* Tue May 27 2025 Jan200101 - 0.14.0-4 +- add patch to add library directories + * Fri May 09 2025 Jan200101 - 0.14.0-3 - add gcc to runtime dependencies