Article View: linux.gentoo.dev
Article #107[gentoo-dev] [PATCH 1/4] eclass/zig.eclass: Update libc info generation for 0.17
From: Violet Purcell
Date: Thu, 05 Nov 2026 17:20
Date: Thu, 05 Nov 2026 17:20
129 lines
5707 bytes
5707 bytes
From: Eric Joldasov <bratishkaerik@landless-city.net>
Extract libc info generation to separate function.
Add new fields for zig_libc.txt as per latest upstream changes:
* https://codeberg.org/ziglang/zig/pulls/36951
* https://codeberg.org/ziglang/zig/pulls/36942
Co-Authored-By: Violet Purcell <vi@vimproved.dev>
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
Signed-off-by: Violet Purcell <vi@vimproved.dev>
---
eclass/zig.eclass | 87 ++++++++++++++++++++++++++++++++++++-----------
1 file changed, 68 insertions(+), 19 deletions(-)
diff --git a/eclass/zig.eclass b/eclass/zig.eclass
index 1c577c05a996..305d21a57653 100644
--- a/eclass/zig.eclass
+++ b/eclass/zig.eclass
@@ -54,7 +54,7 @@ case ${EAPI} in
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
-inherit multiprocessing zig-utils
+inherit multiprocessing toolchain-funcs zig-utils
# @ECLASS_VARIABLE: ZIG_OPTIONAL
# @PRE_INHERIT
@@ -244,6 +244,72 @@ zig_get_jobs() {
fi
}
+# @FUNCTION: _zig_write_libc_txt
+# @INTERNAL
+# @USAGE: <output_file_path>
+# @DESCRIPTION:
+# Generates the zig_libc.txt configuration file based on the target C compiler
+# information and writes it to the specified target path.
+_zig_write_libc_txt() {
+ [[ -z ${1} ]] && die "${ECLASS}: ${FUNCNAME}: missing required argument"
+ local output_file="${1}"
+
+ # Sync with the output format of `zig libc`.
+ # TODO maybe add to upstream to use ZON format instead...
+ # Will also help "https://github.com/ziglang/zig/issues/20327",
+ # and hopefully will respect our settings too.
+
+ local cc crt1_path libgcc_path
+ cc="$(tc-getCC)"
+ # Omitted CFLAGS here, because for cases where location changes
+ # (say, multilib with "-m32" flag) Zig does not support them.
+ # So there will be danger of desync-ed object formats.
+ libgcc_path="$("${cc}" --print-libgcc-file-name)"
+ crt1_path="$("${cc}" --print-file-name=crt1.o)"
+
+ # Check if file paths are absolute and files exists
+ if [[ "${libgcc_path}" != /* || ! -f "${libgcc_path}" ]]; then
+ die "${ECLASS}: Failed to provide Zig libc info"
+ fi
+ if [[ "${crt1_path}" != /* || ! -f "${crt1_path}" ]]; then
+ die "${ECLASS}: Failed to provide Zig libc info"
+ fi
+
+ local crtbegin_dir="${libgcc_path%/*}"
+ local crt1_dir="${crt1_path%/*}"
+ # Note: paths from "--libc" are not prepended by "--sysroot" value,
+ # so repeat prefix here.
+ local include_dir="${ESYSROOT}/usr/include"
+
+ # No quotes here, paths are interpreted verbatim.
+ if ver_test "${ZIG_SLOT}" -ge "0.17"; then
+ # https://codeberg.org/ziglang/zig/src/commit/da561521dd78dcde03fc51de8fd64551b368f56d/lib/std/zig/LibCInstallation.zig#L136-L165
+ cat <<- _EOF_ > "${output_file}" || die "Failed to provide Zig libc info"
+ include_dir=${include_dir}
+ sys_include_dir=${include_dir}
+ cc_dir=${crtbegin_dir}
+ crt_dir=${crt1_dir}
+ # Windows with MSVC only.
+ msvc_lib_dir=
+ kernel32_lib_dir=
+ # Darwin only.
+ darwin_sdk_dir=
+ _EOF_
+ else
+ # https://codeberg.org/ziglang/zig/src/tag/0.16.0/lib/std/zig/LibCInstallation.zig#L133-L158
+ cat <<- _EOF_ > "${output_file}" || die "Failed to provide Zig libc info"
+ include_dir=${include_dir}
+ sys_include_dir=${include_dir}
+ crt_dir=${crt1_dir}
+ # Windows with MSVC only.
+ msvc_lib_dir=
+ kernel32_lib_dir=
+ # Haiku only.
+ gcc_dir=
+ _EOF_
+ fi
+}
+
# @FUNCTION: zig_init_base_args
# @DESCRIPTION:
# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE.
@@ -272,24 +338,7 @@ zig_get_jobs() {
zig_init_base_args() {
[[ "${ZBS_ARGS_BASE}" ]] && return
- # Sync with the output format of `zig libc`.
- # TODO maybe add to upstream to use ZON format instead...
- # Will also help "https://github.com/ziglang/zig/issues/20327",
- # and hopefully will respect our settings too.
- cat <<- _EOF_ > "${T}/zig_libc.txt" || die "Failed to provide Zig libc info"
- # Note: they are not prepended by "--sysroot" value,
- # so repeat it here.
- # Also, no quotes here, they are interpreted verbatim.
- include_dir=${ESYSROOT}/usr/include/
- sys_include_dir=${ESYSROOT}/usr/include/
- crt_dir=${ESYSROOT}/usr/$(get_libdir)/
- # Windows with MSVC only.
- msvc_lib_dir=
- # Windows with MSVC only.
- kernel32_lib_dir=
- # Haiku only.
- gcc_dir=
- _EOF_
+ _zig_write_libc_txt "${T}/zig_libc.txt"
declare -g -a ZBS_ARGS_BASE=(
-j$(zig_get_jobs)
--
2.56.0
Technical Details
Message-ID:
<NW9i1-a1Ly-1@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Violet Purcell <vi@vimproved.dev> Newsgroups: linux.gentoo.dev Subject: [gentoo-dev] [PATCH 1/4] eclass/zig.eclass: Update libc info generation for 0.17 Date: Thu, 05 Nov 2026 18:20:01 +0100 Message-ID: <NW9i1-a1Ly-1@gated-at.bofh.it> X-Envelope-To: gentoo-dev@lists.gentoo.org X-Envelope-To: gentoo-dev@lists.gentoo.org X-Mizu-Trace-ID: 68aaf83e01c806a7 X-Migadu-Flow: FLOW_OUT X-Mailer: git-send-email 2.56.0 List-ID: Gentoo Linux mail <gentoo-dev.gentoo.org> Reply-To: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Approved: robomod@news.nic.it Lines: 129 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Cc: Eric Joldasov <bratishkaerik@landless-city.net>, Violet Purcell <vi@vimproved.dev> X-Original-Date: Thu, 5 Nov 2026 12:13:11 -0500 X-Original-Message-ID: <20261105171321.147058-1-vi@vimproved.dev>