Subject: Re: Bootstrapping Zig with no Binary Blobs

From: Hilton Chain <[email-masked]>
Date: Sun, 17 Nov 2024 22:51:48 +0800

On Sun, 17 Nov 2024 15:16:13 +0800,
Efraim Flashner wrote:
> 
> [1  <text/plain; utf-8 (quoted-printable)>]
> On Fri, Nov 15, 2024 at 10:30:40PM +0800, Hilton Chain wrote:
> > On Fri, 15 Nov 2024 11:29:10 +0800,
> > Hilton Chain wrote:
> > >
> > > Good news: Thanks to this diff, I know how to add libc to RUNPATH now :)
> > >
> > > Another forced push, I have ensured consistent behavior for
> > > (CROSS_)?LIBRARY_PATH and added libc RUNPATH without restoring the behavior
> > > passing '-lc' to linker.
> > >
> > > Who said not going to implement a ld-wrapper within Zig?  :P
> > > Fortunately it was already there :)
> > >
> > > BTW, adding pkg-config to native-inputs works for ncdu.
> > 
> > I have locally made the "use-system-paths" patch larger so that Zig can really
> > honor "CROSS_" environment variables.
> > 
> > The next issue is cross building with pkg-config.  Zig only invokes
> > "pkg-config", but we don't have a "pkg-config" with search path for target
> > inputs.  I can add a pkg-config-for-zig to workaround this, and then... It's
> > dynamic linker path, I'll look into it soon.
> 
> I found a patch after the 0.13.0 release that switches from hardcoding
> pkg-config to using the PKG_CONFIG environment variable and falling back
> to pkg-config, so I backported it to 0.12 and was able to use that and
> guix's regular pkg-config package.  I've added those patches to the
> wip-zig-bootstrap tree.

Thanks, I have ported all patches and pushed.  GUIX_ZIG_LIBC_DIR is changed to
GUIX_ZIG_GLIBC_LINKER and is set as full path in Guix side because I don't want
mess with strings in Zig side...

> We now have a couple of phases that are before the 'build phase, do you
> think it'd be better to consolidate them into a 'configure phase?
> There's no 'configure' script to run, but it does do a lot of
> preparation before the actual 'build phase...

I have merged these phases into configure, forgot to change commit log though.

The reproducibility issue is related to kernel version from target ("native" by
default) information, to address this we need to specify a target for native
builds too.[1]

---
[1]: https://github.com/ziglang/zig/issues/22002#issuecomment-2480933071