commit:     7cfe7beb5c3f0f0fee6137225b927acb457c2b5d
Author:     sin-ack <sin-ack <AT> protonmail <DOT> com>
AuthorDate: Fri Feb 14 19:23:57 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Feb 16 16:24:53 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7cfe7beb

dev-lang/zig: do not pass `--libc` when running tests

When `--libc` is passed to `zig build test`, tests that cross-compile to
other OSes and architectures fail because the internal include paths
automatically configured by Zig are overridden by the libc installation
file.

Upstream issue: https://www.github.com/ziglang/zig/issues/22383

Signed-off-by: Eric Joldasov <bratishkaerik <AT> landless-city.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 dev-lang/zig/zig-0.13.0-r2.ebuild | 22 +++++++++++++++++++++-
 dev-lang/zig/zig-9999.ebuild      | 22 +++++++++++++++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/dev-lang/zig/zig-0.13.0-r2.ebuild 
b/dev-lang/zig/zig-0.13.0-r2.ebuild
index b970092ce4e4..2b05516cbff1 100644
--- a/dev-lang/zig/zig-0.13.0-r2.ebuild
+++ b/dev-lang/zig/zig-0.13.0-r2.ebuild
@@ -1,4 +1,4 @@
-# Copyright 2019-2024 Gentoo Authors
+# Copyright 2019-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
@@ -210,7 +210,27 @@ src_compile() {
 
 src_test() {
        cd "${BUILD_DIR}" || die
+
+       # XXX: When we pass a libc installation to Zig, it will fail to find
+       #      the bundled libraries for targets like aarch64-macos and
+       #      *-linux-musl. Zig doesn't run binaries for these targets when
+       #      -Dskip-non-native is passed, but they are still compiled, so
+       #      the test will fail. There's no way to disable --libc once passed,
+       #      so we need to strip it from ZBS_ARGS.
+       #      See: https://github.com/ziglang/zig/issues/22383
+       local args_backup=("${ZBS_ARGS[@]}")
+
+       for ((i = 0; i < ${#ZBS_ARGS[@]}; i++)); do
+               if [[ "${ZBS_ARGS[i]}" == "--libc" ]]; then
+                       unset ZBS_ARGS[i]
+                       unset ZBS_ARGS[i+1]
+                       break
+               fi
+       done
+
        ZIG_EXE="./stage3/bin/zig" zig_src_test -Dskip-non-native
+
+       ZBS_ARGS=("${args_backup[@]}")
 }
 
 src_install() {

diff --git a/dev-lang/zig/zig-9999.ebuild b/dev-lang/zig/zig-9999.ebuild
index 4f0358a96629..cb7c8e8bffc1 100644
--- a/dev-lang/zig/zig-9999.ebuild
+++ b/dev-lang/zig/zig-9999.ebuild
@@ -1,4 +1,4 @@
-# Copyright 2019-2024 Gentoo Authors
+# Copyright 2019-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
@@ -203,7 +203,27 @@ src_compile() {
 
 src_test() {
        cd "${BUILD_DIR}" || die
+
+       # XXX: When we pass a libc installation to Zig, it will fail to find
+       #      the bundled libraries for targets like aarch64-macos and
+       #      *-linux-musl. Zig doesn't run binaries for these targets when
+       #      -Dskip-non-native is passed, but they are still compiled, so
+       #      the test will fail. There's no way to disable --libc once passed,
+       #      so we need to strip it from ZBS_ARGS.
+       #      See: https://github.com/ziglang/zig/issues/22383
+       local args_backup=("${ZBS_ARGS[@]}")
+
+       for ((i = 0; i < ${#ZBS_ARGS[@]}; i++)); do
+               if [[ "${ZBS_ARGS[i]}" == "--libc" ]]; then
+                       unset ZBS_ARGS[i]
+                       unset ZBS_ARGS[i+1]
+                       break
+               fi
+       done
+
        ZIG_EXE="./stage3/bin/zig" zig_src_test -Dskip-non-native
+
+       ZBS_ARGS=("${args_backup[@]}")
 }
 
 src_install() {

Reply via email to