From: Efraim Flashner <efraim@flashner.co.il>
To: Hilton Chain <hako@ultrarare.space>
Cc: "Motiejus Jakštys" <motiejus@jakstys.lt>,
"Noé Lopez" <noe@xn--no-cja.eu>, dan <i@dan.games>,
"Ekaitz Zarraga" <ekaitz@elenq.tech>,
74217@debbugs.gnu.org
Subject: bug#74217: Bootstrapping Zig with no Binary Blobs
Date: Wed, 13 Nov 2024 20:10:44 +0200 [thread overview]
Message-ID: <ZzTrpMLuGg9cr70s@3900XT> (raw)
In-Reply-To: <87ldxngjy4.wl-hako@ultrarare.space>
[-- Attachment #1: Type: text/plain, Size: 6399 bytes --]
On Thu, Nov 14, 2024 at 12:46:59AM +0800, Hilton Chain wrote:
> Hello everyone,
>
> With a new forced push (and new rebuilds, sorry), wip-zig-bootstrap is mostly
> ready (for me) now. Please take a look at the first few commits, as I'm
> changing Zig's behavior there, here are some additional notes:
>
> To Efraim: Can adding pkg-config to native-inputs avoid the ncdu snippet?
Unfortunately no. The code reads:
exe.root_module.linkSystemLibrary("ncursesw", .{});
exe.root_module.linkSystemLibrary("libzstd", .{});
and so it searches (something like the following, I lost the log):
/usr/lib/liblibzstd.so
/usr/lib/liblibzstd.a
...
/gnu/store/...-glibc.../lib/liblibzstd.so
/gnu/store/...-glibc.../lib/liblibzstd.a
...
/gnu/store/...-zstd.../lib/liblibzstd.so
/gnu/store/...-zstd.../lib/liblibzstd.a
so it looks like it automatically adds the 'lib' at the front. When I've
built out to ncdu again I'll check it again.
> I'm building this branch on my personal Cuirass instance[1][2], for x86_64-linux
> and aarch64-linux (qemu-binfmt), in previous revisions I have indentified
> reproduciblity issue, and aarch64 builds timed-out. I haven't investigated them
> yet.
I've also been having berlin build zig on the wip-zig-bootstrap branch
for x86_64. Unfortunately there's quite a bit to go on aarch64 for it to
get there, but I can confirm from my machine that it's working.
> Then for what's the RUNPATH issue I have mentioned in commits:
> + For current zig@0.10 on Guix master: glibc is missing from RUNPATH, which
> fails the validate-runpath check.
> + For zig@0.11, some other inputs are missing, making the binary failing to run on Guix[3].
> + dan also mentioned privately to me that they needed to add paths from
> LIBRARY_PATH to RUNPATH for their own projects, so programs built by Zig is also
> affected.
I didn't test it. ncdu@2.3 builds with zig-0.11, so that's an option for
testing it out.
https://dev.yorhel.nl/ncdu/changes2
> I think this is due to Zig's implemention of its own linking logic, which
> bypasses our ld-wrapper.
I wonder if switching from lld to make-lld-wrapper would make a
difference here.
> I'm not going to implement ld-wrapper within Zig. :) So my proposed workaround
> in wip-zig-bootstrap is to patch the handling logic added for Guix:
>
> (In lib/std/zig/system/NativePaths.zig)
> --8<---------------cut here---------------start------------->8---
> // Distros like guix don't use FHS, so they rely on environment
> // variables to search for headers and libraries.
> // We use os.getenv here since this part won't be executed on
> // windows, to get rid of unnecessary error handling.
> - if (std.posix.getenv("C_INCLUDE_PATH")) |c_include_path| {
> + if (std.posix.getenv("CROSS_C_INCLUDE_PATH") orelse std.posix.getenv("C_INCLUDE_PATH")) |c_include_path| {
> var it = mem.tokenizeScalar(u8, c_include_path, ':');
> while (it.next()) |dir| {
> try self.addIncludeDir(dir);
> }
> }
>
> - if (std.posix.getenv("CPLUS_INCLUDE_PATH")) |cplus_include_path| {
> + if (std.posix.getenv("CROSS_CPLUS_INCLUDE_PATH") orelse std.posix.getenv("CPLUS_INCLUDE_PATH")) |cplus_include_path| {
> var it = mem.tokenizeScalar(u8, cplus_include_path, ':');
> while (it.next()) |dir| {
> try self.addIncludeDir(dir);
> }
> }
>
> - if (std.posix.getenv("LIBRARY_PATH")) |library_path| {
> + if (std.posix.getenv("CROSS_LIBRARY_PATH") orelse std.posix.getenv("LIBRARY_PATH")) |library_path| {
> var it = mem.tokenizeScalar(u8, library_path, ':');
> while (it.next()) |dir| {
> try self.addLibDir(dir);
> + try self.addRPath(dir);
> }
> }
> }
> --8<---------------cut here---------------end--------------->8---
>
> Adding directories from CROSS_LIBRARY_PATH or LIBRARY_PATH to RUNPATH, "CROSS_"
> part is for our cross toolchain, I haven't tested it yet.
I like this, and it seems like it should make it work for cross
compiling zig programs. That's part of why I added the updated ncdu
commit, to use it for testing.
> I think this behavior change is reasonable since the search path
> (CROSS_)?LIBRARY_PATH is only automatically set by our compilers.
>
> I added this change to 0.9 as well to make all Zigs behave consistently. I also
> used shrink-runpath phase from meson-build-system in Zig and zig-build-system.
>
> I want to move shrink-runpath to (guix build utils) and export it too, so that
> it can be used easier. But I'm not sure if this change will trigger rebuilds of
> other packages, so I didn't do it.
I found that there was still the full LIBRARY_PATH embedded in the ncdu
binary as a string. So with that I'm not sure about using RPath instead
of LibDir for the LIBRARY_PATH.
> Thanks to Guile, for builds not managed by guix-daemon, something like the
> following script can be used, we can ship a program-file if we agree on this
> workaround.
> --8<---------------cut here---------------start------------->8---
> (use-modules (guix build meson-build-system))
>
> (define shrink-runpath
> (assoc-ref %standard-phases 'shrink-runpath))
>
> (define (main directories)
> (for-each (lambda (dir)
> (false-if-exception
> (shrink-runpath
> #:elf-directories '(".")
> #:outputs `(("out" . ,dir)))))
> directories))
>
> (main (cdr (command-line)))
> --8<---------------cut here---------------end--------------->8---
> Usage: guile <file-with-above-content> DIRECTORY...
>
>
> Thanks
> ---
> [1]: https://ci.boiledscript.com/jobset/guix-zig
> [2]: https://substitute.boiledscript.com, if you want to challenge it.
> [3]: https://github.com/ziglang/zig/issues/18434
I spent a bunch of time trying to get zig-0.10 or 0.10.0-610 to build on
riscv64 and ppc64le but haven't been able to crack it yet.
--
Efraim Flashner <efraim@flashner.co.il> אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-11-13 18:12 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 21:47 bug#74217: Bootstrapping Zig with no Binary Blobs Ekaitz Zarraga
2024-11-07 1:19 ` Hilton Chain via Bug reports for GNU Guix
2024-11-07 22:06 ` Noé Lopez via Bug reports for GNU Guix
2024-11-07 22:09 ` Ekaitz Zarraga
2024-11-11 11:42 ` Efraim Flashner
2024-11-11 11:56 ` Hilton Chain via Bug reports for GNU Guix
2024-11-11 12:02 ` Efraim Flashner
2024-11-08 17:43 ` bug#74217: [PATCH 0/2] Initial step on bootstrapping Zig Hilton Chain via Bug reports for GNU Guix
2024-11-08 17:44 ` bug#74217: [PATCH 1/2] gnu: Add zig-0.10.0-610-bootstrap Hilton Chain via Bug reports for GNU Guix
2024-11-08 17:44 ` bug#74217: [PATCH 2/2] gnu: Add zig-0.10.0-610 Hilton Chain via Bug reports for GNU Guix
2024-11-09 17:26 ` bug#74217: [PATCH 0/2] Initial step on bootstrapping Zig Hilton Chain via Bug reports for GNU Guix
2024-11-13 16:46 ` bug#74217: Bootstrapping Zig with no Binary Blobs Hilton Chain via Bug reports for GNU Guix
2024-11-13 18:10 ` Efraim Flashner [this message]
2024-11-13 23:40 ` Hilton Chain via Bug reports for GNU Guix
2024-11-14 1:05 ` Hilton Chain via Bug reports for GNU Guix
2024-11-14 6:05 ` Hilton Chain via Bug reports for GNU Guix
2024-11-14 9:22 ` Hilton Chain via Bug reports for GNU Guix
2024-11-14 9:41 ` Efraim Flashner
2024-11-15 3:29 ` Hilton Chain via Bug reports for GNU Guix
2024-11-15 14:30 ` Hilton Chain via Bug reports for GNU Guix
2024-11-16 6:54 ` Hilton Chain via Bug reports for GNU Guix
2024-11-16 7:13 ` Motiejus Jakštys
2024-11-16 7:18 ` Hilton Chain via Bug reports for GNU Guix
2024-11-16 17:03 ` Efraim Flashner
2024-11-16 18:59 ` Hilton Chain via Bug reports for GNU Guix
2024-11-17 1:39 ` Hilton Chain via Bug reports for GNU Guix
2024-11-17 7:16 ` Efraim Flashner
2024-11-17 14:51 ` Hilton Chain via Bug reports for GNU Guix
2024-11-18 12:00 ` Hilton Chain via Bug reports for GNU Guix
2024-11-19 13:13 ` Hilton Chain via Bug reports for GNU Guix
2024-11-21 13:06 ` Hilton Chain via Bug reports for GNU Guix
2024-11-28 11:08 ` Hilton Chain via Bug reports for GNU Guix
2024-11-28 12:41 ` Motiejus Jakštys
2024-11-28 15:20 ` Hilton Chain via Bug reports for GNU Guix
2024-11-28 20:12 ` Motiejus Jakštys
2024-11-28 20:14 ` Motiejus Jakštys
2024-11-28 20:53 ` Motiejus Jakštys
2024-11-29 12:25 ` Hilton Chain via Bug reports for GNU Guix
2024-11-29 14:51 ` Hilton Chain via Bug reports for GNU Guix
2024-12-01 19:32 ` Motiejus Jakštys
2024-12-02 7:40 ` Efraim Flashner
2024-12-02 5:11 ` Hilton Chain
2024-12-05 6:27 ` Hilton Chain
2024-12-07 14:07 ` Hilton Chain
2024-12-31 14:49 ` Hilton Chain
2024-11-14 9:47 ` Motiejus Jakštys
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZzTrpMLuGg9cr70s@3900XT \
--to=efraim@flashner.co.il \
--cc=74217@debbugs.gnu.org \
--cc=ekaitz@elenq.tech \
--cc=hako@ultrarare.space \
--cc=i@dan.games \
--cc=motiejus@jakstys.lt \
--cc=noe@xn--no-cja.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).