* [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+
@ 2024-10-24 1:46 Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
` (7 more replies)
0 siblings, 8 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-24 1:46 UTC (permalink / raw
To: gentoo-dev
Hello everyone,
This patch series adds new eclasses for packages that use Zig
toolchain with varying level of integration. Since some projects
or ebuilds use only Zig compiler directly, without touching Zig Build
System, I have decided to split eclasses into 2:
* zig-toolchain.eclass: handles dependency on Zig toolchain and
finds appropriate versions/slots, converts C-style target tuples/triples
to Zig format and sets environment variables to be used in other
eclasses and ebuilds. This eclass is more low-level and intended
to be used by programs and libraries that call "zig" commands directly,
without having build.zig file and using "zig build" command. For example,
authors could use "zig build-exe" and "zig test" directly in Makefile,
or add "zig cc" and compile both C and Zig version of library etc.
In this patchset it is also used by dev-lang/zig to convert targets
during bootstrapping, and other logic is suppressed.
* zig-build.eclass: handles working with "zig build" sub-command and build.zig files.
This eclass is more high-level and for most ebuilds it's the only
one which needs to be inherited. It sets default functions for
ebuild phases, deals with dependencies in package manager, allows
ebuilds and end users to configure used flags, respects multi-threading
and verboseness preferences, has some small support for cross-compilation
and so on.
Github PR and discussion here: https://github.com/gentoo/gentoo/pull/37283 .
I have also wrote small generator for Zig ebuild skeletons here:
https://github.com/BratishkaErik/zig-ebuild . Example output in that PR.
It requires dev-lang/zig:9999 to compile, but at runtime it works
with any version supported by eclass (currently 0.13 and 9999).
P.S.: I have not used "git format-patch" and "git send-email" for
a long time, please forgive me and direct if I did something wrong with mail.
Eric Joldasov (5):
zig-toolchain.eclass: new eclass
zig-build.eclass: new eclass
dev-lang/zig: add 0.13.0-r1
dev-lang/zig: sync 9999 with 0.13.0-r1
sys-fs/ncdu: add 2.6-r1
.../zig-0.13.0-skip-test-stack_iterator.patch | 32 +
dev-lang/zig/zig-0.13.0-r1.ebuild | 242 ++++++++
dev-lang/zig/zig-9999.ebuild | 239 ++++----
eclass/zig-build.eclass | 572 ++++++++++++++++++
eclass/zig-toolchain.eclass | 325 ++++++++++
sys-fs/ncdu/ncdu-2.6-r1.ebuild | 50 ++
6 files changed, 1342 insertions(+), 118 deletions(-)
create mode 100644 dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
create mode 100644 dev-lang/zig/zig-0.13.0-r1.ebuild
create mode 100644 eclass/zig-build.eclass
create mode 100644 eclass/zig-toolchain.eclass
create mode 100644 sys-fs/ncdu/ncdu-2.6-r1.ebuild
--
2.47.0
^ permalink raw reply [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
@ 2024-10-24 1:46 ` Eric Joldasov
2024-10-24 7:32 ` Ulrich Müller
2024-10-24 1:46 ` [gentoo-dev] [PATCH 2/5] zig-build.eclass: " Eric Joldasov
` (6 subsequent siblings)
7 siblings, 1 reply; 29+ messages in thread
From: Eric Joldasov @ 2024-10-24 1:46 UTC (permalink / raw
To: gentoo-dev
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/zig-toolchain.eclass | 325 ++++++++++++++++++++++++++++++++++++
1 file changed, 325 insertions(+)
create mode 100644 eclass/zig-toolchain.eclass
diff --git a/eclass/zig-toolchain.eclass b/eclass/zig-toolchain.eclass
new file mode 100644
index 000000000000..8504dc0553e1
--- /dev/null
+++ b/eclass/zig-toolchain.eclass
@@ -0,0 +1,325 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig-toolchain.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @BLURB: Prepare Zig toolchain and set environment variables.
+# @DESCRIPTION:
+# Prepare Zig toolchain and set environment variables. Supports Zig 0.13+.
+# Does not set any default function, ebuilds must call them manually.
+# Generally, only "zig-toolchain_populate_env_vars" is needed.
+#
+# Intended to be used by ebuilds that call "zig build-exe/lib/obj"
+# or "zig test" directly and by "dev-lang/zig".
+# For ebuilds with ZBS (Zig Build System), it's usually better
+# to inherit zig-build instead, as it has default phases-functions.
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
+_ZIG_TOOLCHAIN_ECLASS=1
+
+inherit edo flag-o-matic
+
+# @ECLASS_VARIABLE: ZIG_SLOT
+# @PRE_INHERIT
+# @REQUIRED
+# @DESCRIPTION:
+# Zig slot that will be used in "ezig" function. Also, if ZIG_OPTIONAL is
+# empty, adds dev-lang/zig and dev-lang/zig-bin dependency to BDEPEND.
+# Must be >= "0.13".
+#
+# Example:
+# @CODE
+# 0.13
+# @CODE
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-toolchain and zig-build
+# eclasses will be considered optional. No dependencies will be added and
+# no phase functions will be exported.
+#
+# For zig-toolchain.eclass users:
+# You have to add Zig dependency in your BDEPEND manually and call
+# at least "zig-toolchain_populate_env_vars" before using "ezig".
+#
+# For zig-build.eclass users: see documentation in zig-build.eclass instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND+=" || (
+ dev-lang/zig:${ZIG_SLOT}
+ dev-lang/zig-bin:${ZIG_SLOT}
+ )"
+fi
+
+# @ECLASS_VARIABLE: ZIG_TARGET
+# @DESCRIPTION:
+# Zig target triple to use. Has the following format:
+# arch-os[.os_version_range]-abi[.abi_version]
+# Can be passed as:
+# * "-target " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dtarget=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
+#
+# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+#
+# Example:
+# @CODE
+# native # autodetected by Zig
+# x86_64-linux-gnu # Machine running Linux x86_64 system, with glibc
+# x86_64-linux.6.1.12...6.6.16-gnu.2.38 # Similar to above, but versions are passed explicitly
+# powerpc64le-linux-musl # Machine running Linux 64-bit little-endian PowerPC system, with musl
+# @CODE
+#
+
+# @ECLASS_VARIABLE: ZIG_CPU
+# @DESCRIPTION:
+# Zig target CPU and features to use. Has the following format:
+# family_name(\+enable_feature|\-disable_feature)*
+# Can be passed as:
+# * "-mcpu " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dcpu=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
+#
+# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+#
+# Example:
+# @CODE
+# native # autodetected by Zig
+# znver2 # AMD Zen 2 processor
+# x86_64+x87-sse2" # x86_64 processor, X87 support enabled, SSE2 support disabled
+# @CODE
+
+# @ECLASS_VARIABLE: ZIG_EXE
+# @DESCRIPTION:
+# Absolute path to the used Zig executable.
+#
+# Please note that when passing one flag several times with different values:
+# * to "zig build" in "-Dbar=false -Dbar" form: errors due to conflict of flags,
+# * to "zig build" in "-Dbar=false -Dbar=true" form: "bar" becomes a list, which is likely not what you (or upstream) want,
+# * to "zig test" or "zig build-exe/lib/obj" in "-fbar -fno-bar" form: latest value overwrites values before.
+# Similar situation with other types of options (enums, "std.SemanticVersion", integers, strings, etc.)
+#
+# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+
+# @ECLASS_VARIABLE: ZIG_VER
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Zig version found during "zig-toolchain_find_installation", as reported by "zig version".
+#
+# Example:
+# @CODE
+# 0.13.0
+# @CODE
+
+# @FUNCTION: zig-toolchain_get_target
+# @USAGE: <C-style target triple>
+# @DESCRIPTION:
+# Translates C-style target triple (like CHOST or CBUILD)
+# to Zig-style target triple. Some information (like ARM features)
+# is handled by "zig-toolchain_get_cpu". Mostly used during cross-compiling
+# if user does not set ZIG_TARGET variable.
+#
+# See ZIG_TARGET description for more information.
+zig-toolchain_get_target() {
+ [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
+ local c_target=${1}
+ local c_target_prefix=${c_target%%-*}
+ local c_target_suffix=${c_target##*-}
+
+ local arch os abi
+
+ case ${c_target_prefix} in
+ i?86) arch=x86;;
+ arm64) arch=aarch64;;
+ arm*) arch=arm;;
+ *) arch=${c_target_prefix};;
+ esac
+
+ case ${c_target} in
+ *linux*) os=linux;;
+ *apple*) os=macos;;
+ esac
+
+ case ${c_target_suffix} in
+ solaris*) os=solaris abi=none;;
+ darwin*) abi=none;;
+ *) abi=${c_target_suffix};;
+ esac
+
+ [[ ${arch} == arm && ${abi} == gnu ]] && die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
+
+ echo ${arch}-${os}-${abi}
+}
+
+
+
+# @FUNCTION: zig-toolchain_get_cpu
+# @USAGE: <C-style target triple>
+# @DESCRIPTION:
+# Translates C-style target triple (like CHOST or CBUILD)
+# to Zig-style target CPU and features. Mostly used to get generic target CPU
+# during cross-compiling if user does not set ZIG_CPU variable.
+#
+# See ZIG_CPU description for more information.
+zig-toolchain_get_cpu() {
+ [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
+ local c_target=${1}
+ local c_target_prefix=${c_target%%-*}
+
+ local base_cpu features=""
+
+ case ${c_target_prefix} in
+ i?86) base_cpu=${c_target_prefix};;
+ loongarch64) base_cpu=generic_la64;;
+ powerpc | powerpcle) base_cpu=ppc;;
+ powerpc64) base_cpu=ppc64;;
+ powerpc64le) base_cpu=ppc64le;;
+ riscv32) base_cpu=generic_rv32;;
+ riscv64) base_cpu=generic_rv64;;
+ *) base_cpu=generic;;
+ esac
+
+ case ${c_target_prefix} in
+ armv5tel) features+="+v5te";;
+ armv*) features+="+${c_target_prefix##armv}";;
+ esac
+
+ case ${c_target_prefix} in
+ arm64) ;;
+ arm*)
+ local is_softfloat=$(CTARGET=${c_target} tc-tuple-is-softfloat)
+ case ${is_softfloat} in
+ only | yes) features+="+soft_float";;
+ softfp | no) features+="-soft_float";;
+ *) die "${FUNCNAME[0]}: tc-tuple-is-softfloat returned unexpected value"
+ esac
+ ;;
+ esac
+
+ echo ${base_cpu}${features}
+}
+
+# @FUNCTION: zig-toolchain_find_installation
+# @DESCRIPTION:
+# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE variables.
+#
+# See ZIG_EXE and ZIG_VER descriptions for more information.
+zig-toolchain_find_installation() {
+ # Adapted from https://github.com/gentoo/gentoo/pull/28986
+ # Many thanks to Florian Schmaus (Flowdalic)!
+
+ [[ -n ${ZIG_SLOT} ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set"
+ if ver_test "${ZIG_SLOT}" -lt "0.13"; then
+ die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}"
+ fi
+
+ einfo "Searching Zig ${ZIG_SLOT}..."
+
+ local selected_path selected_version
+
+ # Prefer "dev-lang/zig" over "dev-lang/zig-bin"
+ local -a candidates candidates1 candidates2
+ readarray -d '' -t candidates1 < <(find -P "${BROOT}"/usr/bin/ -mindepth 1 -maxdepth 1 -type l -name "zig-bin-*" -print0 2> /dev/null || echo -n "")
+ readarray -d '' -t candidates2 < <(find -P "${BROOT}"/usr/bin/ -mindepth 1 -maxdepth 1 -type l -name "zig-*" -a '!' -name "zig-bin-*" -print0 2> /dev/null || echo -n "")
+ candidates=( "${candidates1[@]}" "${candidates2[@]}" )
+
+ local candidate_path
+ for candidate_path in "${candidates[@]}"; do
+ local candidate_version="${candidate_path##*-}"
+
+ # Compare with ZIG_SLOT (like 0.13)
+ local candidate_slot=$(ver_cut 1-2 ${candidate_version})
+ if ver_test "${candidate_slot}" -ne ${ZIG_SLOT}; then
+ # Candidate does not satisfy ZIG_SLOT condition.
+ continue
+ fi
+
+ # Compare with previous version (like 0.13.0 and 0.13.1, we prefer the second one if possible)
+ if [[ -n "${selected_path}" ]]; then
+ local selected_version="${selected_path##*-}"
+ if ver_test ${candidate_version} -lt ${selected_version}; then
+ # Previously chosen version is higher, keep it.
+ continue
+ fi
+ fi
+
+ selected_path="${candidate_path}"
+ done
+
+ if [[ -z "${selected_path}" ]]; then
+ die "Could not find (suitable) Zig installation in \"${BROOT}/usr/bin/\""
+ fi
+
+ export ZIG_EXE="${selected_path}"
+}
+
+# @FUNCTION: zig-toolchain_populate_env_vars
+# @DESCRIPTION:
+# Populates ZIG_TARGET, ZIG_CPU, ZIG_EXE and ZIG_VER environment
+# variables with detected values, or, if user set them already,
+# leaves as-is.
+zig-toolchain_populate_env_vars() {
+ # Should be first because it sets ZIG_VER which might be used in the future
+ # when setting ZIG_TARGET and ZIG_CPU variables for incompatible versions.
+ if [[ -z "${ZIG_EXE}" ]]; then
+ zig-toolchain_find_installation
+ fi
+ if [[ -z ${ZIG_VER} ]]; then
+ local selected_ver=$("${ZIG_EXE}" version || die "Failed to get version from \"${ZIG_EXE}\"")
+ export ZIG_VER=${selected_ver}
+ fi
+
+ if [[ -z ${ZIG_TARGET} ]]; then
+ if tc-is-cross-compiler; then
+ export ZIG_TARGET=$(zig-toolchain_get_target ${CHOST})
+ else
+ export ZIG_TARGET=native
+ fi
+ fi
+
+ if [[ -z ${ZIG_CPU} ]]; then
+ if tc-is-cross-compiler; then
+ export ZIG_CPU=$(zig-toolchain_get_cpu ${CHOST})
+ else
+ export ZIG_CPU=native
+ fi
+ fi
+
+ einfo "ZIG_EXE: \"${ZIG_EXE}\""
+ einfo "ZIG_VER: ${ZIG_VER}"
+ einfo "ZIG_TARGET: ${ZIG_TARGET}"
+ einfo "ZIG_CPU: ${ZIG_CPU}"
+}
+
+# @FUNCTION: ezig
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set.
+#
+# Always disables progress bar (tree in 0.13+).
+# By default enables ANSI escape codes (colours, etc.), set NO_COLOR
+# environment variable to disable them.
+ezig() {
+ # Sync description above and comments below with "std.io.tty.detectConfig".
+ debug-print-function "${FUNCNAME[0]}" "${@}"
+
+ if [[ -z "${ZIG_EXE}" ]] ; then
+ die "${FUNCNAME[0]}: ZIG_EXE is not set. Was 'zig-toolchain_populate_env_vars' called before using ezig?"
+ fi
+
+ # Progress bar (tree in newer versions) are helpful indicators in
+ # TTY, but unfortunately they make Portage logs harder to read in plaintext.
+ # We pass "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE (or YES_COLOR
+ # until 0.13) to preserve colors.
+ # User's NO_COLOR takes precendence over this.
+ TERM=dumb YES_COLOR=1 CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}"
+}
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 2/5] zig-build.eclass: new eclass
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
@ 2024-10-24 1:46 ` Eric Joldasov
2024-10-24 9:16 ` Maciej Barć
2024-10-24 1:46 ` [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
` (5 subsequent siblings)
7 siblings, 1 reply; 29+ messages in thread
From: Eric Joldasov @ 2024-10-24 1:46 UTC (permalink / raw
To: gentoo-dev
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/zig-build.eclass | 572 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 572 insertions(+)
create mode 100644 eclass/zig-build.eclass
diff --git a/eclass/zig-build.eclass b/eclass/zig-build.eclass
new file mode 100644
index 000000000000..b1fc89e38d9d
--- /dev/null
+++ b/eclass/zig-build.eclass
@@ -0,0 +1,572 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig-build.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Alfred Wingate <parona@protonmail.com>
+# Violet Purcell <vimproved@inventati.org>
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: zig-toolchain
+# @BLURB: Functions for working with ZBS (Zig Build System).
+# @DESCRIPTION:
+# Functions for working with Zig build system and package manager.
+# Supports Zig 0.13+. Exports default functions for convenience.
+#
+# Note that zig-build.eclass is mostly tailored for projects that:
+# 1) Install something in build.zig steps: "artifacts" (executable,
+# libraries, objects), source codes, assets, tests, scripts etc. But many authors
+# also use it to write Zig "modules", build logic and/or bindings/wrappers
+# for C/C++ libraries. They install nothing and are only used at build-time,
+# so it's unneccessary and mostly useless to make ebuilds for them.
+# 2) Have required `target`, `cpu` and optional `optimize` options
+# in build.zig that accept standard Zig-style target and optimize mode.
+# They are usually created by `standardTargetOptions` and `standardOptimizeOption`.
+#
+# For end-user executables, usually it's recommended to fix calling these options by patch
+# and upstream it, but in some cases they have good reasons
+# to not have this option, f.e. if it is built only for WASM
+# platform with ReleaseSmall, and is not intended to run in your /usr/bin/.
+# In this case, declare dummy options using `standardTargetOptions` and
+# ignore their values, or else eclass wouldn't work.
+#
+# Another case is when upstream has `target` option but it is customized
+# and does not accept usual targets, but something specific to the project
+# like "linux-baseline-lts" or combine CPU and target in one option.
+# In this case, it's best to rename that option to something like `target-custom`,
+# then declare `target` option and make converter from one value to other.
+#
+# For non-executable binaries like C shared/static libraries, objects etc.
+# our policy is stricter, all 3 options are required and should not
+# be ignored, with no exceptions.
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ ! ${_ZIG_BUILD_ECLASS} ]]; then
+_ZIG_BUILD_ECLASS=1
+
+inherit multiprocessing zig-toolchain
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-toolchain and zig-build
+# eclasses will be considered optional. No dependencies will be added and
+# no phase functions will be exported.
+#
+# For zig-build.eclass users:
+# You need to add Zig and pkgconfig dependency in your BDEPEND, set QA_FLAGS_IGNORED
+# and call all phase functions manually, or, if you want to call "ezig" directly,
+# at least call "zig-build_pkg_setup" before it.
+#
+# For zig-toolchain.eclass users: see documentation in zig-toolchain.eclass instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND+="virtual/pkgconfig"
+
+ # See https://github.com/ziglang/zig/issues/3382
+ # Zig Build System does not support CFLAGS/LDFLAGS/etc.
+ QA_FLAGS_IGNORED=".*"
+fi
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Bash associative array with all tarballs that will be fetched by
+# "ezig fetch" in zig-build_src_unpack phase. Value is URL where
+# tarball is located, key is name under which it would be downloaded
+# and renamed. So generally it has effect of "value -> key".
+#
+# Note: if Zig Build System dependency can't be represented in SRC_URI
+# (like direct Git commit URIs), you should do the following (zig-ebuilder
+# does archiving automatically for you):
+# 1. Archive each folder with dependency content in some tarball,
+# so f.e. if you have 2 Git dependencies, create 2 tarballs.
+# 2. Archive all previous tarballs into one combined tarball (also
+# called tarball-tarball from now on), no subdirs, so that eclass
+# can firstly unpack this tarball with "unpack",
+# and secondly unpack its content with "zig fetch".
+# 3. (zig-ebuilder can't do this) Host this tarball somewhere
+# and put URL of this tarball in SRC_URI, and archives in ZBS_DEPENDENCIES,
+# keys must be names of archives, leave values empty.
+#
+# Example:
+# @CODE
+# declare -r -A ZBS_DEPENDENCIES=(
+# [tarball_a-<long-hash>.tar.gz]='URL_A'
+# [tarball_b-<long-hash>.tar.gz]='URL_B'
+#
+# # If there are Git dependencies:
+# [git_c-<long-hash>.tar.gz]=''
+# # Tarball-tarball should contain inside above tarball flatly.
+# )
+# @CODE
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES_SRC_URI
+# @OUTPUT_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in SRC_URI.
+# Note that elements with empty keys will be skipped.
+# Example:
+# @CODE
+# SRC_URI="
+# <URL to archive of project sources, patches, other non-Zig resources etc.>
+#
+# # If there are Git dependencies:
+# # <URL to tarball-tarball>
+#
+# ${ZBS_DEPENDENCIES_SRC_URI}
+# "
+# @CODE
+
+# @FUNCTION: _zig-build_set_zbs_uris
+# @INTERNAL
+# @DESCRIPTION:
+# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
+_zig-build_set_zbs_uris() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ ZBS_DEPENDENCIES_SRC_URI=
+
+ for dependency in ${!ZBS_DEPENDENCIES[@]}; do
+ local uri="${ZBS_DEPENDENCIES[${dependency}]}"
+ if [[ ${#uri} -gt 0 ]]; then
+ ZBS_DEPENDENCIES_SRC_URI+=" ${uri} -> ${dependency}"
+ else
+ # Unrepresentable dependency
+ continue
+ fi
+ done
+}
+_zig-build_set_zbs_uris
+
+# @ECLASS_VARIABLE: my_zbs_args
+# @DESCRIPTION:
+# Ebuild-specified arguments to pass to the "zig build" after "src_configure".
+# This should be a Bash array. It's appended to the ZBS_ARGS
+# during "src_configure". Note: if you need to override default
+# optimize mode of this eclass (ReleaseSafe) with your default,
+# please use "--release=small" etc. syntax so that user can still
+# override it in ZBS_ARGS_EXTRA.
+#
+# Example:
+# @CODE
+# src_configure() {
+# local my_zbs_args=(
+# -Dpie=true
+# )
+#
+# zig-build_src_configure
+# }
+# @CODE
+: "${my_zbs_args:=}"
+
+# @ECLASS_VARIABLE: ZBS_ARGS_EXTRA
+# @USER_VARIABLE
+# @DESCRIPTION:
+# User-specified arguments to pass to the "zig build" after "src_configure".
+# This is also where amount of jobs for "zig build" is taken from.
+# It's appended to the ZBS_ARGS during "zig-build_src_configure".
+#
+# If this does not have amount of jobs, eclass will try to take amount of jobs
+# from MAKEOPTS, and if it also does not have them, it will default to $(nproc).
+#
+# Example:
+# @CODE
+# -j8 --release=small
+# @CODE
+: "${ZBS_ARGS_EXTRA:=}"
+
+# @ECLASS_VARIABLE: ZBS_VERBOSE
+# @USER_VARIABLE
+# @DESCRIPTION:
+# If enabled, eclass will add "--summary all --verbose" options to
+# "ezig build", so that it prints every command before executing,
+# and summarry tree at the end of step. If not, will do nothing.
+# Enabled by default. Set to OFF to disable these verbose messages.
+#
+# Note: this variable does not control other options starting with "--verbose-",
+# such as "--verbose-link" or "--verbose-llvm-cpu-features". If you need them,
+# add them manually to ZBS_ARGS_EXTRA.
+: "${ZBS_VERBOSE:=ON}"
+
+# @ECLASS_VARIABLE: BUILD_DIR
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Directory where all "ezig build" calls will be proceeded.
+# Defaults to "${WORKDIR}/${P}-build" if not set.
+: "${BUILD_DIR:=${WORKDIR}/${P}-build}"
+
+# @ECLASS_VARIABLE: ZBS_ECLASS_DIR
+# @DESCRIPTION:
+# Directory where various files used by this eclass are stored.
+# They can be supplied by the ebuild or by eclass.
+# Currently, it's used only for Zig packages, which are stored in "p/"
+# subdirectory.
+# Defaults to "${WORKDIR}/zig-eclass" if not set.
+# Should be set before calling "zig-build_src_unpack" or "zig-build_live_fetch".
+: "${ZBS_ECLASS_DIR:=${WORKDIR}/zig-eclass}"
+
+# @FUNCTION: zig-build_get_jobs
+# @DESCRIPTION:
+# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
+# If there is none, defaults to number of available processing units.
+zig-build_get_jobs() {
+ local default_jobs="$(get_nproc)"
+ local jobs=$(makeopts_jobs "${ZBS_ARGS_EXTRA} ${MAKEOPTS}" "${default_jobs}")
+
+ if [[ ${jobs} == "0" ]]; then
+ # Zig build system does not allow jobs count to be less than 1,
+ # and does not have option for unlimited parallelism. Pass
+ # default number of jobs here.
+ echo "${default_jobs}"
+ else
+ echo "${jobs}"
+ fi
+}
+
+# @FUNCTION: zig-build_start_base_args
+# @DESCRIPTION:
+# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE,
+# Package manager option is managed by "zig-build_src_prepare",
+# ebuild and user options are added by "zig-build_src_configure".
+#
+# This function is used by "zig-build_pkg_setup", and it is neccessary
+# that args are available as early as possible, so that ebuilds
+# could use them in steps like "src_unpack" if neccessary, while
+# still having verbosity and amount of jobs from user respected.
+zig-build_start_base_args() {
+ [[ ${ZBS_ARGS_BASE} ]] && return
+
+ local crt_dir="${ESYSROOT}/usr/"
+ if [[ ${ZIG_TARGET} == *musl* ]]; then
+ crt_dir+="lib/"
+ else
+ crt_dir+="$(get_libdir)/"
+ fi
+
+ # 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 create Zig libc installation paths file"
+ # Note: they are not prepended by "--sysroot" value, so repeat it here.
+ include_dir=${ESYSROOT}/usr/include/
+ sys_include_dir=${ESYSROOT}/usr/include/
+ crt_dir=${crt_dir}
+ # Windows with MSVC only.
+ msvc_lib_dir=
+ # Windows with MSVC only.
+ kernel32_lib_dir=
+ # Haiku only.
+ gcc_dir=
+ _EOF_
+
+ declare -g -a ZBS_ARGS_BASE=(
+ -j$(zig-build_get_jobs)
+ --build-file "${S}/build.zig"
+
+ -Dtarget=${ZIG_TARGET}
+ -Dcpu=${ZIG_CPU}
+ --release=safe
+
+ --prefix-exe-dir bin/
+ --prefix-lib-dir $(get_libdir)/
+ --prefix-include-dir include/
+
+ # Should be relative path to make other calls easier,
+ # so remove leading slash here.
+ --prefix "${EPREFIX:+${EPREFIX#/}/}usr/"
+
+ --libc "${T}/zig_libc.txt"
+ )
+ [[ "${ZBS_VERBOSE}" != OFF ]] && ZBS_ARGS_BASE+=( --summary all --verbose )
+
+ if tc-is-cross-compiler; then
+ ZBS_ARGS_BASE+=(
+ # TODO add to upstream some way to add different search prefixes
+ # for binaries, include paths and libraries, like existing --prefix-exe-dir etc.
+ # Right now std.Build.findProgram will try to search here first, before PATH,
+ # but std.Build.run and std.Build.runAllowFail use passed arguments as is and
+ # uses std.process.Child under the hood, which itself can use PATH.
+ #
+ # Passing "--search-prefix" when not cross-compiling gives these errors:
+ # install
+ # └─ install ncdu
+ # └─ zig build-exe ncdu ReleaseSafe native 5 errors
+ # error: ld.lld: /usr/lib64/Scrt1.o is incompatible with elf32-i386
+ # error: ld.lld: /usr/lib64/crti.o is incompatible with elf32-i386
+ # error: ld.lld: /var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/local/o/21d4a7d4d6563c46cfe08d129805520f/ncdu.o is incompatible with elf32-i386
+ # error: ld.lld: /var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/global/o/15ced1ec04eb7a5fc68f8ee7bed8650c/libcompiler_rt.a(/var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/global/o/15ced1ec04eb7a5fc68f8ee7bed8650c/libcompiler_rt.a.o) is incompatible with elf32-i386
+ # error: ld.lld: /usr/lib64/crtn.o is incompatible with elf32-i386
+ # error: the following command failed with 5 compilation errors:
+ # TODO: enable this unconditionnaly
+ # after rewriting https://paste.sr.ht/~bratishkaerik/f68273ccde4e8771413098b302f5ee4961521a09
+ # to include TODO above, and upstreaming that patch. I really don't want to make
+ # different behaviour for 9999 and 0.13 in this place now.
+ --search-prefix "${ESYSROOT}/usr/"
+
+ # Note: combined with our other options, it's mostly not used by Zig itself, only by lld linker.
+ # Without this option, lld thinks we are not cross-compiling
+ # and will complain that dynamic linker like "/lib/ld-linux-aarch64.so.1" does not exist.
+ #
+ # "--sysroot" should be passed together with "--search-prefix" above, else it gives these errors:
+ # install
+ # └─ install ncdu
+ # └─ zig build-exe ncdu ReleaseSafe native failure
+ # error: error: unable to find dynamic system library 'ncursesw' using strategy 'paths_first'. searched paths: none
+ # error: unable to find dynamic system library 'tinfow' using strategy 'paths_first'. searched paths: none
+ # error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
+
+ # error: the following command exited with error code 1:
+ --sysroot "${ESYSROOT}/"
+ )
+ fi
+}
+
+# @FUNCTION: zig-build_pkg_setup
+# @DESCRIPTION:
+# Sets up environmental variables for Zig toolchain
+# and basic args for Zig Build System.
+zig-build_pkg_setup() {
+ [[ ${MERGE_TYPE} != binary ]] || return 0
+
+ zig-toolchain_populate_env_vars
+ zig-build_start_base_args
+
+ # Used only by 9999 for now, change in upstream did not appear
+ # in fixed release yet.
+ export PKG_CONFIG="${PKG_CONFIG:-$(tc-getPKG_CONFIG)}"
+
+ mkdir "${T}/zig-cache/" || die
+ export ZIG_LOCAL_CACHE_DIR="${T}/zig-cache/local/"
+ export ZIG_GLOBAL_CACHE_DIR="${T}/zig-cache/global/"
+}
+
+# @FUNCTION: zig-build_live_fetch
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
+# If you have some lazy dependency which is not triggered in default
+# configuration, pass options like you would pass them for regular
+# "ezig build". Try to cover all of them before "src_configure".
+# **Note**: this function will be deprecated once/if
+# https://github.com/ziglang/zig/pull/19975 lands.
+#
+# Example:
+# @CODE
+# src_unpack() {
+# # If there are no lazy dependency:
+# zig-build_live_fetch
+#
+# # If there are lazy dependencies that can be triggered together:
+# zig-build_live_fetch -Denable-wayland -Denable-xwayland
+#
+# # If there are 2 lazy dependencies that can't be triggered
+# # together in one call because they conflict:
+# zig-build_live_fetch -Dmain-backend=opengl
+# zig-build_live_fetch -Dmain-backend=vulkan
+# }
+# @CODE
+zig-build_live_fetch() {
+ # This function will probably be called before [zig-build_]src_prepare,
+ # like in src_unpack, so this directory might not exist yet.
+ mkdir -p "${BUILD_DIR}" > /dev/null || die
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=(
+ "${ZBS_ARGS_BASE[@]}"
+
+ --global-cache-dir "${ZBS_ECLASS_DIR}/"
+ --fetch
+
+ # Function arguments
+ "${@}"
+ )
+
+ einfo "ZBS: attempting to live-fetch dependencies using the following options: ${args[@]}"
+ ezig build "${args[@]}" || die "ZBS: fetching dependencies failed"
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_unpack
+# @DESCRIPTION:
+# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES, in that order.
+zig-build_src_unpack() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ if [[ "${#ZBS_DEPENDENCIES_SRC_URI}" -eq 0 ]]; then
+ default_src_unpack
+ return
+ fi
+
+ local zig_deps=()
+ for dependency in ${!ZBS_DEPENDENCIES[@]}; do
+ zig_deps+=("${dependency}")
+ done
+ # First unpack non-Zig dependencies, so that
+ # tarball with all Git dependencies tarballs is unpacked early.
+ for dist in ${A}; do
+ for zig_dep in "${zig_deps[@]}"; do
+ if [[ "${dist}" == "${zig_dep}" ]]; then
+ continue 2
+ fi
+ done
+
+ unpack "${dist}"
+ done
+
+ # Now unpack all Zig dependencies, including those that are
+ # now unpacked from tarball-tarball.
+ for zig_dep in "${zig_deps[@]}"; do
+ # Hide now-spammy hash from stdout
+ ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" "${DISTDIR}/${zig_dep}" > /dev/null
+ done
+ einfo "ZBS: ${#zig_deps[@]} dependencies fetched"
+}
+
+# @FUNCTION: zig-build_src_prepare
+# @DESCRIPTION:
+# Calls default "src_prepare" function, creates BUILD_DIR directory
+# and enables or disables system mode (by adding to ZBS_BASE_ARGS),
+# depending on how many packages there are.
+#
+# System mode is toggled here and not in "src_unpack" because
+# they could have been fetched by "live_fetch" in live ebuilds instead.
+zig-build_src_prepare() {
+ default_src_prepare
+
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+
+ local system_dir="${ZBS_ECLASS_DIR}/p/"
+
+ # We are using directories count instead of ZBS_DEPENDENCIES.len
+ # because author might have fetched packages using live_fetch instead.
+ local -a packages=()
+ readarray -d '' -t packages < <(find "${system_dir}" -mindepth 1 -maxdepth 1 -type d -print0 2> /dev/null || echo -n "")
+ local count="${#packages[@]}"
+
+ if [[ "${count}" -gt 0 ]]; then
+ einfo "ZBS: system mode enabled, ${count} packages found"
+ ZBS_ARGS_BASE+=( --system "${system_dir}" )
+ else
+ einfo "ZBS: no packages found, no need to enable system mode"
+ fi
+}
+
+# @FUNCTION: zig-build_src_configure
+# @DESCRIPTION:
+# Creates ZBS_ARGS array which can be used in all future phases,
+# by combining ZBS_ARGS_BASE set previously, my_zbs_args from ebuild,
+# and ZBS_ARGS_EXTRA by user, in this order.
+#
+# Specific flags currently only add support for the cross-compilation.
+# They are likely to be extended in the future.
+zig-build_src_configure() {
+ # Handle quoted whitespace.
+ eval "local -a ZBS_ARGS_EXTRA=( ${ZBS_ARGS_EXTRA} )"
+
+ # Since most arguments in array are also cached by ZBS, we want to
+ # reuse array as much as possible, so prevent modification of it.
+ declare -g -a -r ZBS_ARGS=(
+ # Base arguments from pkg_setup/setup_base_args
+ "${ZBS_ARGS_BASE[@]}"
+
+ # Arguments from ebuild
+ "${my_zbs_args[@]}"
+
+ # Arguments from user
+ "${ZBS_ARGS_EXTRA[@]}"
+ )
+
+ einfo "Configured with:"
+ einfo "${ZBS_ARGS[@]}"
+}
+
+# @FUNCTION: zig-build_src_compile
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build" with previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+zig-build_src_compile() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ ezig build "${ZBS_ARGS[@]}" "${@}" || die "ZBS: compilation failed"
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_test
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# If "test" step exist, calls "ezig build test" with previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Note: currently step detection might give false positives in
+# very rare cases, it will be improved in the future.
+zig-build_src_test() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ # UPSTREAM std.testing.tmpDir and a lot of other functions
+ # do not respect --cache-dir or ZIG_LOCAL_CACHE_DIR:
+ # https://github.com/ziglang/zig/issues/19874
+ mkdir -p "zig-cache/" ".zig-cache/" || die
+
+ local found_test_step=false
+
+ local -a steps
+ readarray steps < <(ezig build --list-steps "${ZBS_ARGS[@]}" || die "ZBS: listing steps failed")
+
+ for step in "${steps[@]}"; do
+ # UPSTREAM Currently, step name can have any characters in it,
+ # including whitespaces, so splitting names and
+ # descriptions by whitespaces is not enough for some cases.
+ # We probably need something like "--list-steps names_only".
+ # In practice, almost nobody sets such names.
+ step_name=$(awk '{print $1}' <<< "${step}")
+ if [[ ${step_name} == test ]]; then
+ found_test_step=true
+ break
+ fi
+ done
+
+ if [[ ${found_test_step} == true ]]; then
+ ezig build test "${ZBS_ARGS[@]}" "${@}" || die "ZBS: tests failed"
+ else
+ einfo "Test step not found, skipping."
+ fi
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_install
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build install" with DESTDIR and previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Also installs documentation via "einstalldocs".
+zig-build_src_install() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+ DESTDIR="${D}" ezig build install "${ZBS_ARGS[@]}" "${@}" || die "ZBS: installing failed"
+ popd > /dev/null || die
+
+ pushd "${S}" > /dev/null || die
+ einstalldocs
+ popd > /dev/null || die
+}
+
+fi
+
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 2/5] zig-build.eclass: " Eric Joldasov
@ 2024-10-24 1:46 ` Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
` (4 subsequent siblings)
7 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-24 1:46 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use llvm-r1 eclass instead of llvm, zig-build and
zig-toolchain functions instead of local get_zig_mcpu etc. functions.
* Port "llvm USE-flag" and "removing memory limit flags" from 9999
ebuild.
* Stage3 compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig-build.eclass with common options.
* Before migrating to the zig-build.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we use
upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in src_test is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-toolchain functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-toolchain.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with "zig std" command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
.../zig-0.13.0-skip-test-stack_iterator.patch | 32 +++
dev-lang/zig/zig-0.13.0-r1.ebuild | 242 ++++++++++++++++++
2 files changed, 274 insertions(+)
create mode 100644 dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
create mode 100644 dev-lang/zig/zig-0.13.0-r1.ebuild
diff --git a/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
new file mode 100644
index 000000000000..e088af2102ed
--- /dev/null
+++ b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
@@ -0,0 +1,32 @@
+From: Eric Joldasov <bratishkaerik@landless-city.net>
+
+Skip standalone test "stack_iterator" that fail on Gentoo Linux x86_64.
+Fails in ReleaseSafe, ReleaseFast and ReleaseSmall, but not in Debug.
+Reported to upstream here https://github.com/ziglang/zig/issues/19944 .
+
+Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
+
+diff --git a/test/standalone/stack_iterator/shared_lib_unwind.zig b/test/standalone/stack_iterator/shared_lib_unwind.zig
+index 57513a49c6..75fddb04c9 100644
+--- a/test/standalone/stack_iterator/shared_lib_unwind.zig
++++ b/test/standalone/stack_iterator/shared_lib_unwind.zig
+@@ -35,6 +35,7 @@ extern fn frame0(
+ ) void;
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
+diff --git a/test/standalone/stack_iterator/unwind.zig b/test/standalone/stack_iterator/unwind.zig
+index 69c463a0c1..40963af63d 100644
+--- a/test/standalone/stack_iterator/unwind.zig
++++ b/test/standalone/stack_iterator/unwind.zig
+@@ -87,6 +87,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {
+ }
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
diff --git a/dev-lang/zig/zig-0.13.0-r1.ebuild b/dev-lang/zig/zig-0.13.0-r1.ebuild
new file mode 100644
index 000000000000..dee2be065321
--- /dev/null
+++ b/dev-lang/zig/zig-0.13.0-r1.ebuild
@@ -0,0 +1,242 @@
+# Copyright 2019-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+LLVM_COMPAT=(18)
+LLVM_OPTIONAL=1
+
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig-build
+
+DESCRIPTION="A robust, optimal, and maintainable programming language"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
+if [[ ${PV} == 9999 ]]; then
+ EGIT_REPO_URI="https://github.com/ziglang/zig.git"
+ inherit git-r3
+else
+ VERIFY_SIG_METHOD=minisig
+ VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
+ inherit verify-sig
+
+ SRC_URI="
+ https://ziglang.org/download/${PV}/${P}.tar.xz
+ verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
+ "
+ KEYWORDS="~amd64 ~arm ~arm64"
+
+ BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
+fi
+
+# project itself: MIT
+# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
+# Files that are unnecessary for cross-compilation are removed by upstream
+# and therefore their licenses (if any special) are not included.
+# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
+# lib/libc/musl: MIT BSD-2
+# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
+# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
+LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
+SLOT="${ZIG_SLOT}"
+IUSE="doc +llvm test"
+RESTRICT="!test? ( test )"
+REQUIRED_USE="
+ !llvm? ( !doc )
+ llvm? ( ${LLVM_REQUIRED_USE} )
+"
+
+# Used by both cmake and zig-build eclass.
+BUILD_DIR="${WORKDIR}/${P}_build"
+
+# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
+# (non-LLVM backends don't require these)
+# They are not required "on their own", so please don't add them here.
+# You can check https://github.com/ziglang/zig-bootstrap in future, to see
+# options that are passed to LLVM CMake building (excluding "static" ofc).
+DEPEND="
+ llvm? (
+ $(llvm_gen_dep '
+ sys-devel/clang:${LLVM_SLOT}
+ sys-devel/lld:${LLVM_SLOT}
+ sys-devel/llvm:${LLVM_SLOT}[zstd]
+ ')
+ )
+"
+BDEPEND+="
+ test? ( !!<sys-apps/sandbox-2.39 )
+ ${DEPEND}
+"
+RDEPEND="${DEPEND}"
+IDEPEND="app-eselect/eselect-zig"
+
+DOCS=("README.md" "doc/build.zig.zon.md")
+
+PATCHES=(
+ "${FILESDIR}/zig-0.13.0-test-std-kernel-version.patch"
+ "${FILESDIR}/zig-0.13.0-skip-test-stack_iterator.patch"
+)
+
+# zig-build does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+
+# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
+# Zig uses self-hosted compiler only
+CHECKREQS_MEMORY="4G"
+
+pkg_setup() {
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig-build_pkg_setup
+
+ export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
+
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
+ check-reqs_pkg_setup
+}
+
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ verify-sig_src_unpack
+ fi
+}
+
+src_prepare() {
+ # Avoid double patching. Copied from net-misc/sunshine-0.23.1::gentoo .
+ default_src_prepare
+ default_src_prepare() { :; }
+
+ use llvm && cmake_src_prepare
+ zig-build_src_prepare
+
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
+
+src_configure() {
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET=$(zig-toolchain_get_target ${CBUILD:-${CHOST}})
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
+ )
+ fi
+
+ zig-build_src_configure
+
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET}
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
+}
+
+src_compile() {
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
+
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET} CC="${native_cc}" edob ./bootstrap
+ fi
+
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig-build_src_compile --prefix "${BUILD_DIR}/stage3/"
+
+ ./stage3/bin/zig env || die "Zig compilation failed"
+
+ if use doc; then
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_compile langref --prefix "${S}/docgen/"
+ fi
+}
+
+src_test() {
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_test -Dskip-non-native
+}
+
+src_install() {
+ use doc && local HTML_DOCS=("docgen/doc/langref.html")
+
+ ZIG_EXE="./zig2" zig-build_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
+
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
+ mv lib/zig/ lib2/ || die
+ rm -rf lib/ || die
+ mv lib2/ lib/ || die
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
+}
+
+pkg_postinst() {
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
+
+ if ! use llvm; then
+ elog "Currently, Zig built without LLVM support lacks some"
+ elog "important features such as most optimizations, @cImport, etc."
+ elog "They are listed under \"Building from Source without LLVM\""
+ elog "section of the README file from \"/usr/share/doc/${PF}\" ."
+ fi
+}
+
+pkg_postrm() {
+ eselect zig update ifunset || die
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (2 preceding siblings ...)
2024-10-24 1:46 ` [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
@ 2024-10-24 1:46 ` Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
` (3 subsequent siblings)
7 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-24 1:46 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use zig-build and zig-toolchain functions instead of
local get_zig_mcpu etc. functions.
* Port "sys-apps/sandbox-2.39" test dependency requirement from
0.13.0 ebuild.
* Stage3 compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig-build.eclass with common options.
* Before migrating to the zig-build.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we use
upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in src_test is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-toolchain functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-toolchain.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with "zig std" command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
dev-lang/zig/zig-9999.ebuild | 239 ++++++++++++++++++-----------------
1 file changed, 121 insertions(+), 118 deletions(-)
diff --git a/dev-lang/zig/zig-9999.ebuild b/dev-lang/zig/zig-9999.ebuild
index 335ac0eab28c..380bb83a3dac 100644
--- a/dev-lang/zig/zig-9999.ebuild
+++ b/dev-lang/zig/zig-9999.ebuild
@@ -1,234 +1,237 @@
# Copyright 2019-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
-LLVM_COMPAT=( 19 )
+LLVM_COMPAT=(19)
LLVM_OPTIONAL=1
-inherit check-reqs cmake edo llvm-r1 toolchain-funcs
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig-build
DESCRIPTION="A robust, optimal, and maintainable programming language"
-HOMEPAGE="https://ziglang.org/"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
if [[ ${PV} == 9999 ]]; then
EGIT_REPO_URI="https://github.com/ziglang/zig.git"
inherit git-r3
else
VERIFY_SIG_METHOD=minisig
VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
inherit verify-sig
SRC_URI="
https://ziglang.org/download/${PV}/${P}.tar.xz
verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
"
KEYWORDS="~amd64 ~arm ~arm64"
BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
fi
# project itself: MIT
# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
# Files that are unnecessary for cross-compilation are removed by upstream
# and therefore their licenses (if any special) are not included.
# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
# lib/libc/musl: MIT BSD-2
# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
-SLOT="$(ver_cut 1-2)"
-IUSE="doc +llvm"
+SLOT="${ZIG_SLOT}"
+IUSE="doc +llvm test"
+RESTRICT="!test? ( test )"
REQUIRED_USE="
!llvm? ( !doc )
llvm? ( ${LLVM_REQUIRED_USE} )
"
-BUILD_DIR="${S}/build"
+# Used by both cmake and zig-build eclass.
+BUILD_DIR="${WORKDIR}/${P}_build"
# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
# (non-LLVM backends don't require these)
# They are not required "on their own", so please don't add them here.
# You can check https://github.com/ziglang/zig-bootstrap in future, to see
# options that are passed to LLVM CMake building (excluding "static" ofc).
DEPEND="
llvm? (
$(llvm_gen_dep '
sys-devel/clang:${LLVM_SLOT}
sys-devel/lld:${LLVM_SLOT}
sys-devel/llvm:${LLVM_SLOT}[zstd]
')
)
"
-
-RDEPEND="
+BDEPEND+="
+ test? ( !!<sys-apps/sandbox-2.39 )
${DEPEND}
"
-
+RDEPEND="${DEPEND}"
IDEPEND="app-eselect/eselect-zig"
-# see https://github.com/ziglang/zig/issues/3382
-# For now, Zig Build System doesn't support enviromental CFLAGS/LDFLAGS/etc.
-QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+DOCS=("README.md" "doc/build.zig.zon.md")
-RESTRICT="!llvm? ( test )"
+# zig-build does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
# Zig uses self-hosted compiler only
CHECKREQS_MEMORY="4G"
-ctarget_to_zigtarget() {
- # Zig's Target Format: arch-os-abi
- local CTARGET="${CTARGET:-${CHOST}}"
-
- local ZIG_ARCH
- case "${CTARGET%%-*}" in
- i?86) ZIG_ARCH=x86;;
- sparcv9) ZIG_ARCH=sparc64;;
- *) ZIG_ARCH="${CTARGET%%-*}";; # Same as in CHOST
- esac
-
- local ZIG_OS
- case "${CTARGET}" in
- *linux*) ZIG_OS=linux;;
- *apple*) ZIG_OS=macos;;
- esac
-
- local ZIG_ABI
- case "${CTARGET##*-}" in
- gnu) ZIG_ABI=gnu;;
- solaris*) ZIG_OS=solaris ZIG_ABI=none;;
- darwin*) ZIG_ABI=none;;
- *) ZIG_ABI="${CTARGET##*-}";; # Same as in CHOST
- esac
-
- echo "${ZIG_ARCH}-${ZIG_OS}-${ZIG_ABI}"
-}
-
-get_zig_mcpu() {
- local ZIG_DEFAULT_MCPU=native
- tc-is-cross-compiler && ZIG_DEFAULT_MCPU=baseline
- echo "${ZIG_MCPU:-${ZIG_DEFAULT_MCPU}}"
-}
-
-get_zig_target() {
- local ZIG_DEFAULT_TARGET=native
- tc-is-cross-compiler && ZIG_DEFAULT_TARGET="$(ctarget_to_zigtarget)"
- echo "${ZIG_TARGET:-${ZIG_DEFAULT_TARGET}}"
-}
-
pkg_setup() {
- # Useful for debugging and a little bit more deterministic.
- export ZIG_LOCAL_CACHE_DIR="${T}/zig-local-cache"
- export ZIG_GLOBAL_CACHE_DIR="${T}/zig-global-cache"
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig-build_pkg_setup
export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
- use llvm && llvm-r1_pkg_setup
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
check-reqs_pkg_setup
}
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ verify-sig_src_unpack
+ fi
+}
+
+src_prepare() {
+ # Avoid double patching. Copied from net-misc/sunshine-0.23.1::gentoo .
+ default_src_prepare
+ default_src_prepare() { :; }
+
+ use llvm && cmake_src_prepare
+ zig-build_src_prepare
+
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
+
src_configure() {
- if ! use llvm; then
- mkdir -p "${BUILD_DIR}/stage3" || die
- # Currently, Zig without LLVM extensions lacks most optimizations.
- export ZIG_BOOTSTRAP_STAGE3_FLAGS=(
- -Dtarget="$(get_zig_target)"
- -Dcpu="$(get_zig_mcpu)"
- -Doptimize=Debug
- -Dstd-docs=false
- -Dno-langref
- -Denable-llvm=false
- -Dforce-link-libc
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET=$(zig-toolchain_get_target ${CBUILD:-${CHOST}})
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
)
- return
fi
- local mycmakeargs=(
- -DZIG_USE_CCACHE=OFF
- -DZIG_SHARED_LLVM=ON
- -DZIG_TARGET_TRIPLE="$(get_zig_target)"
- -DZIG_TARGET_MCPU="$(get_zig_mcpu)"
- -DZIG_USE_LLVM_CONFIG=ON
- -DCMAKE_PREFIX_PATH="$(get_llvm_prefix)"
- -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
- )
+ zig-build_src_configure
- cmake_src_configure
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET}
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
}
src_compile() {
- # Remove "limit memory usage" flags, it's already verified by
- # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
- # according to CI OOM failures, which are higher than during Gentoo build.
- sed -i -e '/\.max_rss = .*,/d' build.zig || die
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
- if ! use llvm; then
- $(tc-getCC) -o bootstrap bootstrap.c || die "Zig's bootstrap.c compilation failed"
- edob ./bootstrap
- edo ./zig2 build install --prefix "${BUILD_DIR}/stage3/" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- return
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET} CC="${native_cc}" edob ./bootstrap
fi
- cmake_src_compile
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig-build_src_compile --prefix "${BUILD_DIR}/stage3/"
- "${BUILD_DIR}/stage3/bin/zig" env || die "Zig compilation failed"
+ ./stage3/bin/zig env || die "Zig compilation failed"
if use doc; then
- cd "${BUILD_DIR}" || die
- edo ./stage3/bin/zig build std-docs --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
- edo ./stage3/bin/zig build langref --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_compile langref --prefix "${S}/docgen/"
fi
}
src_test() {
cd "${BUILD_DIR}" || die
- local ZIG_TEST_ARGS="-Dstatic-llvm=false -Denable-llvm -Dskip-non-native \
- -Doptimize=ReleaseSafe -Dtarget=$(get_zig_target) -Dcpu=$(get_zig_mcpu)"
- local ZIG_TEST_STEPS=(
- test-fmt test-cases test-behavior test-c-import test-compiler-rt test-universal-libc test-compare-output
- test-standalone test-c-abi test-link test-stack-traces test-cli test-asm-link test-translate-c
- test-run-translated-c test-std
- )
-
- local step
- for step in "${ZIG_TEST_STEPS[@]}" ; do
- edob ./stage3/bin/zig build ${step} ${ZIG_TEST_ARGS}
- done
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_test -Dskip-non-native
}
src_install() {
- local DOCS=( "README.md" "doc/build.zig.zon.md" )
- use doc && local HTML_DOCS=( "docgen/doc/langref.html" "docgen/doc/std" )
+ use doc && local HTML_DOCS=("docgen/doc/langref.html")
- if ! use llvm; then
- DESTDIR="${D}" edo ./zig2 build install --prefix "${ZIG_SYS_INSTALL_DEST}" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- einstalldocs
- else
- cmake_src_install
- fi
+ ZIG_EXE="./zig2" zig-build_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
- cd "${ED}/usr/$(get_libdir)/zig/${PV}/" || die
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
mv lib/zig/ lib2/ || die
rm -rf lib/ || die
mv lib2/ lib/ || die
- dosym -r "/usr/$(get_libdir)/zig/${PV}/bin/zig" "/usr/bin/zig-${PV}"
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
}
pkg_postinst() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
if ! use llvm; then
elog "Currently, Zig built without LLVM support lacks some"
elog "important features such as most optimizations, @cImport, etc."
elog "They are listed under \"Building from Source without LLVM\""
elog "section of the README file from \"/usr/share/doc/${PF}\" ."
- elog "It's recommended to use C backend directly with this stage2 build."
fi
}
pkg_postrm() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (3 preceding siblings ...)
2024-10-24 1:46 ` [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
@ 2024-10-24 1:46 ` Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (2 subsequent siblings)
7 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-24 1:46 UTC (permalink / raw
To: gentoo-dev
Now uses "zig-build" eclass.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
sys-fs/ncdu/ncdu-2.6-r1.ebuild | 50 ++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 sys-fs/ncdu/ncdu-2.6-r1.ebuild
diff --git a/sys-fs/ncdu/ncdu-2.6-r1.ebuild b/sys-fs/ncdu/ncdu-2.6-r1.ebuild
new file mode 100644
index 000000000000..6fb3c76328cc
--- /dev/null
+++ b/sys-fs/ncdu/ncdu-2.6-r1.ebuild
@@ -0,0 +1,50 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/yoranheling.asc
+# Upstream states 0.12.x and 0.13.x support,
+# but eclass supports only one slot.
+ZIG_SLOT="0.13"
+inherit verify-sig zig-build
+
+DESCRIPTION="NCurses Disk Usage"
+HOMEPAGE="https://dev.yorhel.nl/ncdu"
+SRC_URI="
+ https://dev.yorhel.nl/download/${P}.tar.gz
+ verify-sig? ( https://dev.yorhel.nl/download/${P}.tar.gz.asc )
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~amd64"
+
+BDEPEND="verify-sig? ( sec-keys/openpgp-keys-yorhel )"
+DEPEND="
+ app-arch/zstd
+ sys-libs/ncurses:=[unicode(+)]
+"
+RDEPEND="${DEPEND}"
+
+DOCS=("README.md" "ChangeLog")
+
+src_unpack() {
+ verify-sig_src_unpack
+}
+
+src_configure() {
+ local my_zbs_args=(
+ -Dpie=true
+ # Upstream recommends this default:
+ --release=fast
+ )
+
+ zig-build_src_configure
+}
+
+src_install() {
+ zig-build_src_install
+
+ doman ncdu.1
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* Re: [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass
2024-10-24 1:46 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
@ 2024-10-24 7:32 ` Ulrich Müller
2024-10-24 7:38 ` Matt Jolly
0 siblings, 1 reply; 29+ messages in thread
From: Ulrich Müller @ 2024-10-24 7:32 UTC (permalink / raw
To: Eric Joldasov; +Cc: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 12328 bytes --]
>>>>> On Thu, 24 Oct 2024, Eric Joldasov wrote:
> --- /dev/null
> +++ b/eclass/zig-toolchain.eclass
I have some general comments about both proposed eclasses.
> @@ -0,0 +1,325 @@
> +# Copyright 2024 Gentoo Authors
> +# Distributed under the terms of the GNU General Public License v2
> +
> +# @ECLASS: zig-toolchain.eclass
> +# @MAINTAINER:
> +# Eric Joldasov <bratishkaerik@landless-city.net>
> +# @AUTHOR:
> +# Eric Joldasov <bratishkaerik@landless-city.net>
> +# @SUPPORTED_EAPIS: 8
> +# @BLURB: Prepare Zig toolchain and set environment variables.
> +# @DESCRIPTION:
> +# Prepare Zig toolchain and set environment variables. Supports Zig 0.13+.
> +# Does not set any default function, ebuilds must call them manually.
> +# Generally, only "zig-toolchain_populate_env_vars" is needed.
> +#
> +# Intended to be used by ebuilds that call "zig build-exe/lib/obj"
> +# or "zig test" directly and by "dev-lang/zig".
> +# For ebuilds with ZBS (Zig Build System), it's usually better
> +# to inherit zig-build instead, as it has default phases-functions.
> +
> +case ${EAPI} in
> + 8) ;;
> + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
> +esac
For new eclasses, the EAPI check should be inside the inherit guard.
> +
> +if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
> +_ZIG_TOOLCHAIN_ECLASS=1
> +
> +inherit edo flag-o-matic
> +
> +# @ECLASS_VARIABLE: ZIG_SLOT
> +# @PRE_INHERIT
> +# @REQUIRED
> +# @DESCRIPTION:
> +# Zig slot that will be used in "ezig" function. Also, if ZIG_OPTIONAL is
> +# empty, adds dev-lang/zig and dev-lang/zig-bin dependency to BDEPEND.
> +# Must be >= "0.13".
> +#
> +# Example:
> +# @CODE
> +# 0.13
> +# @CODE
> +
> +# @ECLASS_VARIABLE: ZIG_OPTIONAL
> +# @PRE_INHERIT
> +# @DEFAULT_UNSET
> +# @DESCRIPTION:
> +# If set to a non-empty value, all logic in zig-toolchain and zig-build
> +# eclasses will be considered optional. No dependencies will be added and
> +# no phase functions will be exported.
> +#
> +# For zig-toolchain.eclass users:
> +# You have to add Zig dependency in your BDEPEND manually and call
> +# at least "zig-toolchain_populate_env_vars" before using "ezig".
> +#
> +# For zig-build.eclass users: see documentation in zig-build.eclass instead.
> +if [[ ! ${ZIG_OPTIONAL} ]]; then
> + BDEPEND+=" || (
> + dev-lang/zig:${ZIG_SLOT}
> + dev-lang/zig-bin:${ZIG_SLOT}
> + )"
I don't see any previous assignment of BDEPEND, so the += and the
initial space aren't necessary here. (Same issue in zig-build.eclass.)
> +fi
> +
> +# @ECLASS_VARIABLE: ZIG_TARGET
> +# @DESCRIPTION:
> +# Zig target triple to use. Has the following format:
> +# arch-os[.os_version_range]-abi[.abi_version]
> +# Can be passed as:
> +# * "-target " option in "zig test" or "zig build-exe/lib/obj",
> +# * "-Dtarget=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
> +#
> +# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
Please keep the length of documentation lines below 80 characters;
best is to break them at 70-ish chars for good human readability.
https://devmanual.gentoo.org/ebuild-writing/file-format/index.html#indenting-and-whitespace
Also, full stops at the end of a sentence should be followed by two
spaces, so that groff will recognise the sentence end in the resulting
man page.
> +#
> +# Example:
> +# @CODE
> +# native # autodetected by Zig
> +# x86_64-linux-gnu # Machine running Linux x86_64 system, with glibc
> +# x86_64-linux.6.1.12...6.6.16-gnu.2.38 # Similar to above, but versions are passed explicitly
> +# powerpc64le-linux-musl # Machine running Linux 64-bit little-endian PowerPC system, with musl
> +# @CODE
> +#
> +
> +# @ECLASS_VARIABLE: ZIG_CPU
> +# @DESCRIPTION:
> +# Zig target CPU and features to use. Has the following format:
> +# family_name(\+enable_feature|\-disable_feature)*
> +# Can be passed as:
> +# * "-mcpu " option in "zig test" or "zig build-exe/lib/obj",
> +# * "-Dcpu=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
> +#
> +# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
> +#
> +# Example:
> +# @CODE
> +# native # autodetected by Zig
> +# znver2 # AMD Zen 2 processor
> +# x86_64+x87-sse2" # x86_64 processor, X87 support enabled, SSE2 support disabled
> +# @CODE
> +
> +# @ECLASS_VARIABLE: ZIG_EXE
> +# @DESCRIPTION:
> +# Absolute path to the used Zig executable.
> +#
> +# Please note that when passing one flag several times with different values:
> +# * to "zig build" in "-Dbar=false -Dbar" form: errors due to conflict of flags,
> +# * to "zig build" in "-Dbar=false -Dbar=true" form: "bar" becomes a list, which is likely not what you (or upstream) want,
> +# * to "zig test" or "zig build-exe/lib/obj" in "-fbar -fno-bar" form: latest value overwrites values before.
> +# Similar situation with other types of options (enums, "std.SemanticVersion", integers, strings, etc.)
> +#
> +# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
> +
> +# @ECLASS_VARIABLE: ZIG_VER
> +# @OUTPUT_VARIABLE
> +# @DESCRIPTION:
> +# Zig version found during "zig-toolchain_find_installation", as reported by "zig version".
> +#
> +# Example:
> +# @CODE
> +# 0.13.0
> +# @CODE
> +
> +# @FUNCTION: zig-toolchain_get_target
> +# @USAGE: <C-style target triple>
> +# @DESCRIPTION:
> +# Translates C-style target triple (like CHOST or CBUILD)
> +# to Zig-style target triple. Some information (like ARM features)
> +# is handled by "zig-toolchain_get_cpu". Mostly used during cross-compiling
> +# if user does not set ZIG_TARGET variable.
> +#
> +# See ZIG_TARGET description for more information.
> +zig-toolchain_get_target() {
> + [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
> + local c_target=${1}
> + local c_target_prefix=${c_target%%-*}
> + local c_target_suffix=${c_target##*-}
> +
> + local arch os abi
> +
> + case ${c_target_prefix} in
> + i?86) arch=x86;;
> + arm64) arch=aarch64;;
> + arm*) arch=arm;;
> + *) arch=${c_target_prefix};;
Any reason why the last line isn't aligned with the others?
> + esac
> +
> + case ${c_target} in
> + *linux*) os=linux;;
> + *apple*) os=macos;;
> + esac
> +
> + case ${c_target_suffix} in
> + solaris*) os=solaris abi=none;;
> + darwin*) abi=none;;
> + *) abi=${c_target_suffix};;
Ditto.
> + esac
> +
> + [[ ${arch} == arm && ${abi} == gnu ]] && die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
> +
> + echo ${arch}-${os}-${abi}
> +}
> +
> +
> +
> +# @FUNCTION: zig-toolchain_get_cpu
> +# @USAGE: <C-style target triple>
> +# @DESCRIPTION:
> +# Translates C-style target triple (like CHOST or CBUILD)
> +# to Zig-style target CPU and features. Mostly used to get generic target CPU
> +# during cross-compiling if user does not set ZIG_CPU variable.
> +#
> +# See ZIG_CPU description for more information.
> +zig-toolchain_get_cpu() {
> + [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
> + local c_target=${1}
> + local c_target_prefix=${c_target%%-*}
> +
> + local base_cpu features=""
> +
> + case ${c_target_prefix} in
> + i?86) base_cpu=${c_target_prefix};;
> + loongarch64) base_cpu=generic_la64;;
> + powerpc | powerpcle) base_cpu=ppc;;
> + powerpc64) base_cpu=ppc64;;
> + powerpc64le) base_cpu=ppc64le;;
> + riscv32) base_cpu=generic_rv32;;
> + riscv64) base_cpu=generic_rv64;;
> + *) base_cpu=generic;;
> + esac
> +
> + case ${c_target_prefix} in
> + armv5tel) features+="+v5te";;
> + armv*) features+="+${c_target_prefix##armv}";;
> + esac
> +
> + case ${c_target_prefix} in
> + arm64) ;;
> + arm*)
> + local is_softfloat=$(CTARGET=${c_target} tc-tuple-is-softfloat)
> + case ${is_softfloat} in
> + only | yes) features+="+soft_float";;
> + softfp | no) features+="-soft_float";;
> + *) die "${FUNCNAME[0]}: tc-tuple-is-softfloat returned unexpected value"
> + esac
> + ;;
> + esac
> +
> + echo ${base_cpu}${features}
> +}
> +
> +# @FUNCTION: zig-toolchain_find_installation
> +# @DESCRIPTION:
> +# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE variables.
> +#
> +# See ZIG_EXE and ZIG_VER descriptions for more information.
> +zig-toolchain_find_installation() {
> + # Adapted from https://github.com/gentoo/gentoo/pull/28986
> + # Many thanks to Florian Schmaus (Flowdalic)!
> +
> + [[ -n ${ZIG_SLOT} ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set"
> + if ver_test "${ZIG_SLOT}" -lt "0.13"; then
> + die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}"
> + fi
> +
> + einfo "Searching Zig ${ZIG_SLOT}..."
> +
> + local selected_path selected_version
> +
> + # Prefer "dev-lang/zig" over "dev-lang/zig-bin"
> + local -a candidates candidates1 candidates2
> + readarray -d '' -t candidates1 < <(find -P "${BROOT}"/usr/bin/ -mindepth 1 -maxdepth 1 -type l -name "zig-bin-*" -print0 2> /dev/null || echo -n "")
> + readarray -d '' -t candidates2 < <(find -P "${BROOT}"/usr/bin/ -mindepth 1 -maxdepth 1 -type l -name "zig-*" -a '!' -name "zig-bin-*" -print0 2> /dev/null || echo -n "")
> + candidates=( "${candidates1[@]}" "${candidates2[@]}" )
> +
> + local candidate_path
> + for candidate_path in "${candidates[@]}"; do
> + local candidate_version="${candidate_path##*-}"
> +
> + # Compare with ZIG_SLOT (like 0.13)
> + local candidate_slot=$(ver_cut 1-2 ${candidate_version})
> + if ver_test "${candidate_slot}" -ne ${ZIG_SLOT}; then
> + # Candidate does not satisfy ZIG_SLOT condition.
> + continue
> + fi
> +
> + # Compare with previous version (like 0.13.0 and 0.13.1, we prefer the second one if possible)
> + if [[ -n "${selected_path}" ]]; then
> + local selected_version="${selected_path##*-}"
> + if ver_test ${candidate_version} -lt ${selected_version}; then
> + # Previously chosen version is higher, keep it.
> + continue
> + fi
> + fi
> +
> + selected_path="${candidate_path}"
> + done
> +
> + if [[ -z "${selected_path}" ]]; then
> + die "Could not find (suitable) Zig installation in \"${BROOT}/usr/bin/\""
> + fi
> +
> + export ZIG_EXE="${selected_path}"
> +}
> +
> +# @FUNCTION: zig-toolchain_populate_env_vars
> +# @DESCRIPTION:
> +# Populates ZIG_TARGET, ZIG_CPU, ZIG_EXE and ZIG_VER environment
> +# variables with detected values, or, if user set them already,
> +# leaves as-is.
> +zig-toolchain_populate_env_vars() {
> + # Should be first because it sets ZIG_VER which might be used in the future
> + # when setting ZIG_TARGET and ZIG_CPU variables for incompatible versions.
> + if [[ -z "${ZIG_EXE}" ]]; then
> + zig-toolchain_find_installation
> + fi
> + if [[ -z ${ZIG_VER} ]]; then
> + local selected_ver=$("${ZIG_EXE}" version || die "Failed to get version from \"${ZIG_EXE}\"")
> + export ZIG_VER=${selected_ver}
> + fi
> +
> + if [[ -z ${ZIG_TARGET} ]]; then
> + if tc-is-cross-compiler; then
> + export ZIG_TARGET=$(zig-toolchain_get_target ${CHOST})
> + else
> + export ZIG_TARGET=native
> + fi
> + fi
> +
> + if [[ -z ${ZIG_CPU} ]]; then
> + if tc-is-cross-compiler; then
> + export ZIG_CPU=$(zig-toolchain_get_cpu ${CHOST})
> + else
> + export ZIG_CPU=native
> + fi
> + fi
> +
> + einfo "ZIG_EXE: \"${ZIG_EXE}\""
> + einfo "ZIG_VER: ${ZIG_VER}"
> + einfo "ZIG_TARGET: ${ZIG_TARGET}"
> + einfo "ZIG_CPU: ${ZIG_CPU}"
> +}
> +
> +# @FUNCTION: ezig
> +# @USAGE: [<args>...]
> +# @DESCRIPTION:
> +# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set.
> +#
> +# Always disables progress bar (tree in 0.13+).
> +# By default enables ANSI escape codes (colours, etc.), set NO_COLOR
> +# environment variable to disable them.
> +ezig() {
> + # Sync description above and comments below with "std.io.tty.detectConfig".
> + debug-print-function "${FUNCNAME[0]}" "${@}"
> +
> + if [[ -z "${ZIG_EXE}" ]] ; then
> + die "${FUNCNAME[0]}: ZIG_EXE is not set. Was 'zig-toolchain_populate_env_vars' called before using ezig?"
> + fi
> +
> + # Progress bar (tree in newer versions) are helpful indicators in
> + # TTY, but unfortunately they make Portage logs harder to read in plaintext.
> + # We pass "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE (or YES_COLOR
> + # until 0.13) to preserve colors.
> + # User's NO_COLOR takes precendence over this.
> + TERM=dumb YES_COLOR=1 CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}"
No die statement?
> +}
> +fi
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass
2024-10-24 7:32 ` Ulrich Müller
@ 2024-10-24 7:38 ` Matt Jolly
2024-10-24 8:50 ` Florian Schmaus
0 siblings, 1 reply; 29+ messages in thread
From: Matt Jolly @ 2024-10-24 7:38 UTC (permalink / raw
To: gentoo-dev
Hi,
On 24/10/24 17:32, Ulrich Müller wrote:
> Please keep the length of documentation lines below 80 characters;
> best is to break them at 70-ish chars for good human readability.
> https://devmanual.gentoo.org/ebuild-writing/file-format/
> index.html#indenting-and-whitespace
A bit off-topic, but:
Is anyone actually using an 80-column display in 2024? Could we look
at relaxing this to something more sane / modern like 120? Are there
any accessibility concerns, etc.?
Cheers,
Matt
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass
2024-10-24 7:38 ` Matt Jolly
@ 2024-10-24 8:50 ` Florian Schmaus
2024-10-24 13:00 ` Michael Orlitzky
0 siblings, 1 reply; 29+ messages in thread
From: Florian Schmaus @ 2024-10-24 8:50 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1.1.1: Type: text/plain, Size: 540 bytes --]
On 24/10/2024 09.38, Matt Jolly wrote:
> Is anyone actually using an 80-column display in 2024? Could we look
> at relaxing this to something more sane / modern like 120? Are there
> any accessibility concerns, etc.?
In present days, its not about the width of the used terminal/display.
As ulm wrote, limiting the text width to something below 80 chars is
supposed to help with readability. I find this to be true, especially
for monospaced text. (For code, I usually prefer a non-strict 100-120
column limit.)
- Flow
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 21567 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 618 bytes --]
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [gentoo-dev] [PATCH 2/5] zig-build.eclass: new eclass
2024-10-24 1:46 ` [gentoo-dev] [PATCH 2/5] zig-build.eclass: " Eric Joldasov
@ 2024-10-24 9:16 ` Maciej Barć
0 siblings, 0 replies; 29+ messages in thread
From: Maciej Barć @ 2024-10-24 9:16 UTC (permalink / raw
To: gentoo-dev, Eric Joldasov
[-- Attachment #1.1.1: Type: text/plain, Size: 893 bytes --]
> + if tc-is-cross-compiler; then
> + ZBS_ARGS_BASE+=(
> + # TODO add to upstream some way to add different search prefixes
> + # for binaries, include paths and libraries, like existing --prefix-exe-dir etc.
> + # Right now std.Build.findProgram will try to search here first, before PATH,
> + # but std.Build.run and std.Build.runAllowFail use passed arguments as is and
> + # uses std.process.Child under the hood, which itself can use PATH.
> + #
> + # Passing "--search-prefix" when not cross-compiling gives these
Could we move this TODO comment above the function
`zig-build_start_base_args`?
1. it will improve readability by giving a TODO block up-front,
2. putting this inside a 3-step indent is a bit too much.
--
Have a great day!
~ Maciej Barć
https://wiki.gentoo.org/wiki/User:Xgqt
9B0A 4C5D 02A3 B43C 9D6F D6B1 14D7 4A1F 43A6 AC3C
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 16315 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 29+ messages in thread
* Re: [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass
2024-10-24 8:50 ` Florian Schmaus
@ 2024-10-24 13:00 ` Michael Orlitzky
0 siblings, 0 replies; 29+ messages in thread
From: Michael Orlitzky @ 2024-10-24 13:00 UTC (permalink / raw
To: gentoo-dev
On 2024-10-24 10:50:55, Florian Schmaus wrote:
> On 24/10/2024 09.38, Matt Jolly wrote:
> > Is anyone actually using an 80-column display in 2024? Could we look
> > at relaxing this to something more sane / modern like 120? Are there
> > any accessibility concerns, etc.?
>
> In present days, its not about the width of the used terminal/display.
>
> As ulm wrote, limiting the text width to something below 80 chars is
> supposed to help with readability. I find this to be true, especially
> for monospaced text. (For code, I usually prefer a non-strict 100-120
> column limit.)
This isn't just a hand-wavy "it's probably true" sort of thing, it's
an established fact in typography and print design. But to answer the
original question, yes, there are still plenty of 4:3 monitors
attached to machines with no framebuffer console and it's nice to have
the letters be big enough to read.
^ permalink raw reply [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (4 preceding siblings ...)
2024-10-24 1:46 ` [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
@ 2024-10-25 21:20 ` Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
` (4 more replies)
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
7 siblings, 5 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:20 UTC (permalink / raw
To: gentoo-dev
Hello everyone,
This patch series adds new eclasses for packages that use Zig
toolchain with varying level of integration. Since some projects
or ebuilds use only Zig compiler directly, without touching Zig Build
System, I have decided to split eclasses into 2:
* zig-toolchain.eclass: handles dependency on Zig toolchain and
finds appropriate versions/slots, converts C-style target tuples/triples
to Zig format and sets environment variables to be used in other
eclasses and ebuilds. This eclass is more low-level and intended
to be used by programs and libraries that call "zig" commands directly,
without having build.zig file and using "zig build" command. For example,
authors could use "zig build-exe" and "zig test" directly in Makefile,
or add "zig cc" and compile both C and Zig version of library etc.
In this patchset it is also used by dev-lang/zig to convert targets
during bootstrapping, and other logic is suppressed.
* zig-build.eclass: handles working with "zig build" sub-command and build.zig files.
This eclass is more high-level and for most ebuilds it's the only
one which needs to be inherited. It sets default functions for
ebuild phases, deals with dependencies in package manager, allows
ebuilds and end users to configure used flags, respects multi-threading
and verboseness preferences, has some small support for cross-compilation
and so on.
Github PR and discussion here: https://github.com/gentoo/gentoo/pull/37283 .
I have also wrote small generator for Zig ebuild skeletons here:
https://github.com/BratishkaErik/zig-ebuild . Example output in that PR.
It requires dev-lang/zig:9999 to compile, but at runtime it works
with any version supported by eclass (currently 0.13 and 9999).
In "v2" revision, including suggestions on mailing list:
* Move EAPI check after inherit guard
* Change BDEPEND from "+=" to "=" and remove initial space here,
* Keep length below 80 characters, and add 2 spaces after full stop,
* Align lines in switch cases (according to Neovim, on nano I had
not noticed it before),
* Add "die -n" to ezig(),
* Move and rewrite TODO comments in zig-build_start_base_args to be
shorter and move less relevant information to patch itself.
...and GitHub. Also remove old leftovers of Zig 0.12 compatibility.
Eric Joldasov (5):
zig-toolchain.eclass: new eclass
zig-build.eclass: new eclass
dev-lang/zig: add 0.13.0-r1
dev-lang/zig: sync 9999 with 0.13.0-r1
sys-fs/ncdu: add 2.6-r1
.../zig-0.13.0-skip-test-stack_iterator.patch | 32 +
dev-lang/zig/zig-0.13.0-r1.ebuild | 245 ++++++++
dev-lang/zig/zig-9999.ebuild | 244 ++++----
eclass/zig-build.eclass | 580 ++++++++++++++++++
eclass/zig-toolchain.eclass | 375 +++++++++++
sys-fs/ncdu/ncdu-2.6-r1.ebuild | 50 ++
6 files changed, 1407 insertions(+), 119 deletions(-)
create mode 100644 dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
create mode 100644 dev-lang/zig/zig-0.13.0-r1.ebuild
create mode 100644 eclass/zig-build.eclass
create mode 100644 eclass/zig-toolchain.eclass
create mode 100644 sys-fs/ncdu/ncdu-2.6-r1.ebuild
Interdiff:
diff --git a/eclass/zig-build.eclass b/eclass/zig-build.eclass
index b1fc89e38d9d..ffa075043cde 100644
--- a/eclass/zig-build.eclass
+++ b/eclass/zig-build.eclass
@@ -1,572 +1,580 @@
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: zig-build.eclass
# @MAINTAINER:
# Eric Joldasov <bratishkaerik@landless-city.net>
# @AUTHOR:
# Alfred Wingate <parona@protonmail.com>
# Violet Purcell <vimproved@inventati.org>
# Eric Joldasov <bratishkaerik@landless-city.net>
# @SUPPORTED_EAPIS: 8
# @PROVIDES: zig-toolchain
-# @BLURB: Functions for working with ZBS (Zig Build System).
+# @BLURB: Functions for working with ZBS (Zig Build System)
# @DESCRIPTION:
-# Functions for working with Zig build system and package manager.
-# Supports Zig 0.13+. Exports default functions for convenience.
+# Functions for working with Zig build system and package manager.
+# Supports Zig 0.13+. Exports default functions for convenience.
#
# Note that zig-build.eclass is mostly tailored for projects that:
# 1) Install something in build.zig steps: "artifacts" (executable,
-# libraries, objects), source codes, assets, tests, scripts etc. But many authors
-# also use it to write Zig "modules", build logic and/or bindings/wrappers
-# for C/C++ libraries. They install nothing and are only used at build-time,
-# so it's unneccessary and mostly useless to make ebuilds for them.
-# 2) Have required `target`, `cpu` and optional `optimize` options
-# in build.zig that accept standard Zig-style target and optimize mode.
-# They are usually created by `standardTargetOptions` and `standardOptimizeOption`.
+# libraries, objects), source codes, assets, tests, scripts etc. But
+# many authors also use it to write Zig "modules", build logic
+# and/or bindings/wrappers for C/C++ libraries. They install nothing
+# and are only used at build-time, so it's unneccessary and mostly
+# useless to make ebuilds for them.
+# 2) Have required `target`, `cpu` and optional `optimize` options in
+# build.zig that accept standard Zig-style target and optimize mode.
+# They are usually created by calling `b.standardTargetOptions` and
+# `b.standardOptimizeOption` functions.
#
-# For end-user executables, usually it's recommended to fix calling these options by patch
-# and upstream it, but in some cases they have good reasons
-# to not have this option, f.e. if it is built only for WASM
-# platform with ReleaseSmall, and is not intended to run in your /usr/bin/.
-# In this case, declare dummy options using `standardTargetOptions` and
-# ignore their values, or else eclass wouldn't work.
+# For end-user executables, usually it's recommended to patch to call
+# these options and upstream it, but in some cases authors have good
+# reasons to not have them, f.e. if it is built only for WASM
+# platform with ReleaseSmall, and is not intended to run in /usr/bin/.
+# In this case, declare dummy options using `b.option` and ignore
+# their values, or else eclass wouldn't work.
#
-# Another case is when upstream has `target` option but it is customized
-# and does not accept usual targets, but something specific to the project
-# like "linux-baseline-lts" or combine CPU and target in one option.
-# In this case, it's best to rename that option to something like `target-custom`,
-# then declare `target` option and make converter from one value to other.
+# Another case is when upstream has `target` option but it has
+# custom format and does not accept usual Zig targets, but rather
+# something specific to the project like "linux-baseline-lts", or
+# combine CPU and target in one option.
+# In this case, it's best to rename that option to something like
+# `target-custom`, then declare `target` option and make converter
+# from one value to other.
#
-# For non-executable binaries like C shared/static libraries, objects etc.
-# our policy is stricter, all 3 options are required and should not
-# be ignored, with no exceptions.
+# For non-executable binaries like C libraries, objects etc. our
+# policy is stricter, all 3 options are required and should not
+# be ignored, with no exceptions.
+
+if [[ ! ${_ZIG_BUILD_ECLASS} ]]; then
+_ZIG_BUILD_ECLASS=1
case ${EAPI} in
8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
-if [[ ! ${_ZIG_BUILD_ECLASS} ]]; then
-_ZIG_BUILD_ECLASS=1
-
inherit multiprocessing zig-toolchain
# @ECLASS_VARIABLE: ZIG_OPTIONAL
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION:
-# If set to a non-empty value, all logic in zig-toolchain and zig-build
-# eclasses will be considered optional. No dependencies will be added and
-# no phase functions will be exported.
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
#
# For zig-build.eclass users:
-# You need to add Zig and pkgconfig dependency in your BDEPEND, set QA_FLAGS_IGNORED
-# and call all phase functions manually, or, if you want to call "ezig" directly,
-# at least call "zig-build_pkg_setup" before it.
+# You need to add Zig and pkgconfig dependencies in your BDEPEND, set
+# QA_FLAGS_IGNORED and call all phase functions manually. If you want
+# to use "ezig build" directly, call "zig-build_pkg_setup" before it.
#
-# For zig-toolchain.eclass users: see documentation in zig-toolchain.eclass instead.
+# For zig-toolchain.eclass users: see documentation in
+# zig-toolchain.eclass instead.
if [[ ! ${ZIG_OPTIONAL} ]]; then
- BDEPEND+="virtual/pkgconfig"
+ BDEPEND="virtual/pkgconfig"
# See https://github.com/ziglang/zig/issues/3382
# Zig Build System does not support CFLAGS/LDFLAGS/etc.
QA_FLAGS_IGNORED=".*"
fi
# @ECLASS_VARIABLE: ZBS_DEPENDENCIES
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION:
# Bash associative array with all tarballs that will be fetched by
-# "ezig fetch" in zig-build_src_unpack phase. Value is URL where
+# "ezig fetch" in zig-build_src_unpack phase. Value is URL where
# tarball is located, key is name under which it would be downloaded
-# and renamed. So generally it has effect of "value -> key".
+# and renamed. So generally it has effect of "value -> key".
#
# Note: if Zig Build System dependency can't be represented in SRC_URI
-# (like direct Git commit URIs), you should do the following (zig-ebuilder
-# does archiving automatically for you):
+# (like direct Git commit URIs), you should do the following
+# (zig-ebuilder does archiving automatically for you):
# 1. Archive each folder with dependency content in some tarball,
-# so f.e. if you have 2 Git dependencies, create 2 tarballs.
+# so f.e. if you have 2 Git dependencies, create 2 tarballs.
# 2. Archive all previous tarballs into one combined tarball (also
# called tarball-tarball from now on), no subdirs, so that eclass
# can firstly unpack this tarball with "unpack",
-# and secondly unpack its content with "zig fetch".
+# and secondly unpack its content with "zig fetch".
# 3. (zig-ebuilder can't do this) Host this tarball somewhere
-# and put URL of this tarball in SRC_URI, and archives in ZBS_DEPENDENCIES,
-# keys must be names of archives, leave values empty.
+# and put URL of this tarball in SRC_URI, and archives in
+# ZBS_DEPENDENCIES, keys must be names of archives, values empty.
#
# Example:
# @CODE
# declare -r -A ZBS_DEPENDENCIES=(
# [tarball_a-<long-hash>.tar.gz]='URL_A'
# [tarball_b-<long-hash>.tar.gz]='URL_B'
#
# # If there are Git dependencies:
# [git_c-<long-hash>.tar.gz]=''
# # Tarball-tarball should contain inside above tarball flatly.
# )
# @CODE
# @ECLASS_VARIABLE: ZBS_DEPENDENCIES_SRC_URI
# @OUTPUT_VARIABLE
# @DEFAULT_UNSET
# @DESCRIPTION:
-# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in SRC_URI.
-# Note that elements with empty keys will be skipped.
+# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in
+# SRC_URI. Note that elements with empty keys will be skipped.
# Example:
# @CODE
# SRC_URI="
-# <URL to archive of project sources, patches, other non-Zig resources etc.>
+# <URL to project sources, patches, non-Zig resources etc.>
#
# # If there are Git dependencies:
# # <URL to tarball-tarball>
#
# ${ZBS_DEPENDENCIES_SRC_URI}
# "
# @CODE
# @FUNCTION: _zig-build_set_zbs_uris
# @INTERNAL
# @DESCRIPTION:
-# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
+# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
_zig-build_set_zbs_uris() {
# Thanks to Alfred Wingate "parona" for inspiration here:
# https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
ZBS_DEPENDENCIES_SRC_URI=
for dependency in ${!ZBS_DEPENDENCIES[@]}; do
local uri="${ZBS_DEPENDENCIES[${dependency}]}"
if [[ ${#uri} -gt 0 ]]; then
ZBS_DEPENDENCIES_SRC_URI+=" ${uri} -> ${dependency}"
else
# Unrepresentable dependency
continue
fi
done
}
_zig-build_set_zbs_uris
# @ECLASS_VARIABLE: my_zbs_args
# @DESCRIPTION:
-# Ebuild-specified arguments to pass to the "zig build" after "src_configure".
-# This should be a Bash array. It's appended to the ZBS_ARGS
-# during "src_configure". Note: if you need to override default
-# optimize mode of this eclass (ReleaseSafe) with your default,
-# please use "--release=small" etc. syntax so that user can still
-# override it in ZBS_ARGS_EXTRA.
+# Bash array with ebuild-specified arguments to pass to the
+# "zig build" after "src_configure".
+# It's appended to the ZBS_ARGS during "src_configure". Note: if you
+# need to override default optimize mode of this eclass (ReleaseSafe)
+# with your default, please use "--release=small" etc. syntax so that
+# user can still override it in ZBS_ARGS_EXTRA.
#
# Example:
# @CODE
# src_configure() {
# local my_zbs_args=(
# -Dpie=true
# )
#
# zig-build_src_configure
# }
# @CODE
: "${my_zbs_args:=}"
# @ECLASS_VARIABLE: ZBS_ARGS_EXTRA
# @USER_VARIABLE
# @DESCRIPTION:
-# User-specified arguments to pass to the "zig build" after "src_configure".
-# This is also where amount of jobs for "zig build" is taken from.
-# It's appended to the ZBS_ARGS during "zig-build_src_configure".
+# Bash string with user-specified arguments to pass to the "zig build"
+# after "src_configure".
+# It's appended to the ZBS_ARGS during "zig-build_src_configure".
#
-# If this does not have amount of jobs, eclass will try to take amount of jobs
-# from MAKEOPTS, and if it also does not have them, it will default to $(nproc).
+# If this does not have amount of jobs, eclass will try to take amount
+# of jobs from MAKEOPTS, and if it also does not have them, it will
+# default to $(nproc).
#
# Example:
# @CODE
# -j8 --release=small
# @CODE
: "${ZBS_ARGS_EXTRA:=}"
# @ECLASS_VARIABLE: ZBS_VERBOSE
# @USER_VARIABLE
# @DESCRIPTION:
# If enabled, eclass will add "--summary all --verbose" options to
# "ezig build", so that it prints every command before executing,
-# and summarry tree at the end of step. If not, will do nothing.
-# Enabled by default. Set to OFF to disable these verbose messages.
+# and summarry tree at the end of step. If not, will do nothing.
+# Enabled by default. Set to OFF to disable these verbose messages.
#
-# Note: this variable does not control other options starting with "--verbose-",
-# such as "--verbose-link" or "--verbose-llvm-cpu-features". If you need them,
-# add them manually to ZBS_ARGS_EXTRA.
+# Note: this variable does not control other options starting with
+# "--verbose-", such as "--verbose-link" or "--verbose-cimport". If
+# you need them, add them manually to ZBS_ARGS_EXTRA.
: "${ZBS_VERBOSE:=ON}"
# @ECLASS_VARIABLE: BUILD_DIR
# @DEFAULT_UNSET
# @DESCRIPTION:
-# Directory where all "ezig build" calls will be proceeded.
-# Defaults to "${WORKDIR}/${P}-build" if not set.
+# Directory where all "ezig build" calls will be proceeded.
+# Defaults to "${WORKDIR}/${P}-build" if not set.
: "${BUILD_DIR:=${WORKDIR}/${P}-build}"
# @ECLASS_VARIABLE: ZBS_ECLASS_DIR
# @DESCRIPTION:
-# Directory where various files used by this eclass are stored.
-# They can be supplied by the ebuild or by eclass.
+# Directory where various files used by this eclass are stored.
+# They can be supplied by the ebuild or by eclass.
# Currently, it's used only for Zig packages, which are stored in "p/"
-# subdirectory.
-# Defaults to "${WORKDIR}/zig-eclass" if not set.
-# Should be set before calling "zig-build_src_unpack" or "zig-build_live_fetch".
+# subdirectory.
+# Defaults to "${WORKDIR}/zig-eclass" if not set.
+# Should be set before calling "zig-build_src_unpack" or
+# "zig-build_live_fetch".
: "${ZBS_ECLASS_DIR:=${WORKDIR}/zig-eclass}"
# @FUNCTION: zig-build_get_jobs
# @DESCRIPTION:
-# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
-# If there is none, defaults to number of available processing units.
+# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
+# If there is none, defaults to number of available processing units.
zig-build_get_jobs() {
+ local all_args="${ZBS_ARGS_EXTRA} ${MAKEOPTS}"
local default_jobs="$(get_nproc)"
- local jobs=$(makeopts_jobs "${ZBS_ARGS_EXTRA} ${MAKEOPTS}" "${default_jobs}")
+ local jobs=$(makeopts_jobs "${all_args}" "${default_jobs}")
if [[ ${jobs} == "0" ]]; then
- # Zig build system does not allow jobs count to be less than 1,
- # and does not have option for unlimited parallelism. Pass
- # default number of jobs here.
+ # Zig build system does not allow "-j0", and does not have
+ # option for unlimited parallelism. Pass our default number
+ # of jobs here.
echo "${default_jobs}"
else
echo "${jobs}"
fi
}
# @FUNCTION: zig-build_start_base_args
# @DESCRIPTION:
-# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE,
+# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE.
# Package manager option is managed by "zig-build_src_prepare",
-# ebuild and user options are added by "zig-build_src_configure".
+# ebuild and user options are added by "zig-build_src_configure".
#
# This function is used by "zig-build_pkg_setup", and it is neccessary
# that args are available as early as possible, so that ebuilds
# could use them in steps like "src_unpack" if neccessary, while
-# still having verbosity and amount of jobs from user respected.
+# still having verbosity and amount of jobs from user respected.
+#
+#
+# TODO: currently this function enables "--search-prefix" (1) and
+# "--sysroot" (2) only when cross-compiling, should be fixed to
+# unconditionally enabling it.
+#
+# For solving (1) this patch should be reworked and upstreamed:
+# https://paste.sr.ht/~bratishkaerik/2ddffe2bf0f8f9d6dfb60403c2e9560334edaa88
+#
+# (2)
+# "--sysroot" should be passed together with "--search-prefix" above,
+# if we pass only "--sysroot" it gives these errors:
+# @CODE
+# error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
+# @CODE
zig-build_start_base_args() {
[[ ${ZBS_ARGS_BASE} ]] && return
local crt_dir="${ESYSROOT}/usr/"
if [[ ${ZIG_TARGET} == *musl* ]]; then
crt_dir+="lib/"
else
crt_dir+="$(get_libdir)/"
fi
# 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 create Zig libc installation paths file"
- # Note: they are not prepended by "--sysroot" value, so repeat it here.
+ cat <<- _EOF_ > "${T}/zig_libc.txt"
+ # Note: they are not prepended by "--sysroot" value,
+ # so repeat it here.
include_dir=${ESYSROOT}/usr/include/
sys_include_dir=${ESYSROOT}/usr/include/
crt_dir=${crt_dir}
# Windows with MSVC only.
msvc_lib_dir=
# Windows with MSVC only.
kernel32_lib_dir=
# Haiku only.
gcc_dir=
_EOF_
+ if [[ ${?} -ne 0 ]]; then
+ die "Failed to create Zig libc installation info file"
+ fi
declare -g -a ZBS_ARGS_BASE=(
-j$(zig-build_get_jobs)
--build-file "${S}/build.zig"
-Dtarget=${ZIG_TARGET}
-Dcpu=${ZIG_CPU}
--release=safe
--prefix-exe-dir bin/
--prefix-lib-dir $(get_libdir)/
--prefix-include-dir include/
# Should be relative path to make other calls easier,
# so remove leading slash here.
--prefix "${EPREFIX:+${EPREFIX#/}/}usr/"
--libc "${T}/zig_libc.txt"
)
- [[ "${ZBS_VERBOSE}" != OFF ]] && ZBS_ARGS_BASE+=( --summary all --verbose )
+ if [[ "${ZBS_VERBOSE}" != OFF ]]; then
+ ZBS_ARGS_BASE+=( --summary all --verbose )
+ fi
if tc-is-cross-compiler; then
ZBS_ARGS_BASE+=(
- # TODO add to upstream some way to add different search prefixes
- # for binaries, include paths and libraries, like existing --prefix-exe-dir etc.
- # Right now std.Build.findProgram will try to search here first, before PATH,
- # but std.Build.run and std.Build.runAllowFail use passed arguments as is and
- # uses std.process.Child under the hood, which itself can use PATH.
- #
- # Passing "--search-prefix" when not cross-compiling gives these errors:
- # install
- # └─ install ncdu
- # └─ zig build-exe ncdu ReleaseSafe native 5 errors
- # error: ld.lld: /usr/lib64/Scrt1.o is incompatible with elf32-i386
- # error: ld.lld: /usr/lib64/crti.o is incompatible with elf32-i386
- # error: ld.lld: /var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/local/o/21d4a7d4d6563c46cfe08d129805520f/ncdu.o is incompatible with elf32-i386
- # error: ld.lld: /var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/global/o/15ced1ec04eb7a5fc68f8ee7bed8650c/libcompiler_rt.a(/var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/global/o/15ced1ec04eb7a5fc68f8ee7bed8650c/libcompiler_rt.a.o) is incompatible with elf32-i386
- # error: ld.lld: /usr/lib64/crtn.o is incompatible with elf32-i386
- # error: the following command failed with 5 compilation errors:
- # TODO: enable this unconditionnaly
- # after rewriting https://paste.sr.ht/~bratishkaerik/f68273ccde4e8771413098b302f5ee4961521a09
- # to include TODO above, and upstreaming that patch. I really don't want to make
- # different behaviour for 9999 and 0.13 in this place now.
--search-prefix "${ESYSROOT}/usr/"
-
- # Note: combined with our other options, it's mostly not used by Zig itself, only by lld linker.
- # Without this option, lld thinks we are not cross-compiling
- # and will complain that dynamic linker like "/lib/ld-linux-aarch64.so.1" does not exist.
- #
- # "--sysroot" should be passed together with "--search-prefix" above, else it gives these errors:
- # install
- # └─ install ncdu
- # └─ zig build-exe ncdu ReleaseSafe native failure
- # error: error: unable to find dynamic system library 'ncursesw' using strategy 'paths_first'. searched paths: none
- # error: unable to find dynamic system library 'tinfow' using strategy 'paths_first'. searched paths: none
- # error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
-
- # error: the following command exited with error code 1:
--sysroot "${ESYSROOT}/"
)
fi
}
# @FUNCTION: zig-build_pkg_setup
# @DESCRIPTION:
# Sets up environmental variables for Zig toolchain
-# and basic args for Zig Build System.
+# and basic args for Zig Build System.
zig-build_pkg_setup() {
[[ ${MERGE_TYPE} != binary ]] || return 0
zig-toolchain_populate_env_vars
zig-build_start_base_args
# Used only by 9999 for now, change in upstream did not appear
# in fixed release yet.
export PKG_CONFIG="${PKG_CONFIG:-$(tc-getPKG_CONFIG)}"
mkdir "${T}/zig-cache/" || die
export ZIG_LOCAL_CACHE_DIR="${T}/zig-cache/local/"
export ZIG_GLOBAL_CACHE_DIR="${T}/zig-cache/global/"
}
# @FUNCTION: zig-build_live_fetch
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
+# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
# If you have some lazy dependency which is not triggered in default
# configuration, pass options like you would pass them for regular
-# "ezig build". Try to cover all of them before "src_configure".
+# "ezig build". Try to cover all of them before "src_configure".
# **Note**: this function will be deprecated once/if
-# https://github.com/ziglang/zig/pull/19975 lands.
+# https://github.com/ziglang/zig/pull/19975 lands.
#
# Example:
# @CODE
# src_unpack() {
# # If there are no lazy dependency:
# zig-build_live_fetch
#
# # If there are lazy dependencies that can be triggered together:
# zig-build_live_fetch -Denable-wayland -Denable-xwayland
#
# # If there are 2 lazy dependencies that can't be triggered
# # together in one call because they conflict:
# zig-build_live_fetch -Dmain-backend=opengl
# zig-build_live_fetch -Dmain-backend=vulkan
# }
# @CODE
zig-build_live_fetch() {
- # This function will probably be called before [zig-build_]src_prepare,
- # like in src_unpack, so this directory might not exist yet.
+ # This function will likely be called in src_unpack,
+ # before [zig-build_]src_prepare, so this directory might not
+ # exist yet.
mkdir -p "${BUILD_DIR}" > /dev/null || die
pushd "${BUILD_DIR}" > /dev/null || die
local args=(
- "${ZBS_ARGS_BASE[@]}"
-
- --global-cache-dir "${ZBS_ECLASS_DIR}/"
--fetch
+ "${ZBS_ARGS_BASE[@]}"
+
# Function arguments
"${@}"
)
- einfo "ZBS: attempting to live-fetch dependencies using the following options: ${args[@]}"
- ezig build "${args[@]}" || die "ZBS: fetching dependencies failed"
+ einfo "ZBS: live-fetching with following args: ${args[@]}"
+ ezig build --global-cache-dir "${ZBS_ECLASS_DIR}/" "${args[@]}"
popd > /dev/null || die
}
# @FUNCTION: zig-build_src_unpack
# @DESCRIPTION:
-# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES, in that order.
+# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES,
+# in that order.
zig-build_src_unpack() {
# Thanks to Alfred Wingate "parona" for inspiration here:
# https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
if [[ "${#ZBS_DEPENDENCIES_SRC_URI}" -eq 0 ]]; then
default_src_unpack
return
fi
local zig_deps=()
for dependency in ${!ZBS_DEPENDENCIES[@]}; do
zig_deps+=("${dependency}")
done
# First unpack non-Zig dependencies, so that
# tarball with all Git dependencies tarballs is unpacked early.
for dist in ${A}; do
for zig_dep in "${zig_deps[@]}"; do
if [[ "${dist}" == "${zig_dep}" ]]; then
continue 2
fi
done
unpack "${dist}"
done
# Now unpack all Zig dependencies, including those that are
# now unpacked from tarball-tarball.
for zig_dep in "${zig_deps[@]}"; do
# Hide now-spammy hash from stdout
- ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" "${DISTDIR}/${zig_dep}" > /dev/null
+ ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" \
+ "${DISTDIR}/${zig_dep}" > /dev/null
done
einfo "ZBS: ${#zig_deps[@]} dependencies fetched"
}
# @FUNCTION: zig-build_src_prepare
# @DESCRIPTION:
# Calls default "src_prepare" function, creates BUILD_DIR directory
# and enables or disables system mode (by adding to ZBS_BASE_ARGS),
-# depending on how many packages there are.
+# depending on how many packages there are.
#
-# System mode is toggled here and not in "src_unpack" because
-# they could have been fetched by "live_fetch" in live ebuilds instead.
+# System mode is toggled here and not in "src_unpack" because they
+# could have been fetched by "live_fetch" in live ebuilds instead.
zig-build_src_prepare() {
default_src_prepare
mkdir -p "${BUILD_DIR}" || die
einfo "BUILD_DIR: \"${BUILD_DIR}\""
local system_dir="${ZBS_ECLASS_DIR}/p/"
- # We are using directories count instead of ZBS_DEPENDENCIES.len
- # because author might have fetched packages using live_fetch instead.
+ # We are using directories.len instead of ZBS_DEPENDENCIES.len
+ # because ebuild might have fetched packages using live_fetch
+ # instead.
local -a packages=()
- readarray -d '' -t packages < <(find "${system_dir}" -mindepth 1 -maxdepth 1 -type d -print0 2> /dev/null || echo -n "")
+ readarray -d '' -t packages < <(find "${system_dir}" -mindepth 1 \
+ -maxdepth 1 -type d -print0 2> /dev/null || echo -n "")
local count="${#packages[@]}"
if [[ "${count}" -gt 0 ]]; then
einfo "ZBS: system mode enabled, ${count} packages found"
ZBS_ARGS_BASE+=( --system "${system_dir}" )
else
einfo "ZBS: no packages found, no need to enable system mode"
fi
}
# @FUNCTION: zig-build_src_configure
# @DESCRIPTION:
# Creates ZBS_ARGS array which can be used in all future phases,
# by combining ZBS_ARGS_BASE set previously, my_zbs_args from ebuild,
-# and ZBS_ARGS_EXTRA by user, in this order.
+# and ZBS_ARGS_EXTRA by user, in this order.
#
-# Specific flags currently only add support for the cross-compilation.
-# They are likely to be extended in the future.
+# Specific flags currently only add support for the cross-compilation.
+# They are likely to be extended in the future.
zig-build_src_configure() {
# Handle quoted whitespace.
eval "local -a ZBS_ARGS_EXTRA=( ${ZBS_ARGS_EXTRA} )"
- # Since most arguments in array are also cached by ZBS, we want to
- # reuse array as much as possible, so prevent modification of it.
+ # Since most arguments in array are also cached by ZBS, we
+ # want to reuse array as much as possible, so prevent
+ # modification of it.
declare -g -a -r ZBS_ARGS=(
# Base arguments from pkg_setup/setup_base_args
"${ZBS_ARGS_BASE[@]}"
# Arguments from ebuild
"${my_zbs_args[@]}"
# Arguments from user
"${ZBS_ARGS_EXTRA[@]}"
)
einfo "Configured with:"
einfo "${ZBS_ARGS[@]}"
}
# @FUNCTION: zig-build_src_compile
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Calls "ezig build" with previously set ZBS_ARGS.
-# Args passed to this function will be passed after ZBS_ARGS.
+# Calls "ezig build" with previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
zig-build_src_compile() {
pushd "${BUILD_DIR}" > /dev/null || die
- ezig build "${ZBS_ARGS[@]}" "${@}" || die "ZBS: compilation failed"
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ nonfatal ezig build "${args[@]}" || die "ZBS: compilation failed"
popd > /dev/null || die
}
# @FUNCTION: zig-build_src_test
# @USAGE: [<args>...]
# @DESCRIPTION:
-# If "test" step exist, calls "ezig build test" with previously set ZBS_ARGS.
-# Args passed to this function will be passed after ZBS_ARGS.
+# If "test" step exist, calls "ezig build test" with previously set
+# ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
# Note: currently step detection might give false positives in
-# very rare cases, it will be improved in the future.
+# very rare cases, it will be improved in the future.
zig-build_src_test() {
pushd "${BUILD_DIR}" > /dev/null || die
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+
# UPSTREAM std.testing.tmpDir and a lot of other functions
# do not respect --cache-dir or ZIG_LOCAL_CACHE_DIR:
# https://github.com/ziglang/zig/issues/19874
mkdir -p "zig-cache/" ".zig-cache/" || die
local found_test_step=false
local -a steps
- readarray steps < <(ezig build --list-steps "${ZBS_ARGS[@]}" || die "ZBS: listing steps failed")
+ readarray steps < <(nonfatal ezig build --list-steps "${args[@]}" \
+ || die "ZBS: listing steps failed")
for step in "${steps[@]}"; do
# UPSTREAM Currently, step name can have any characters in it,
- # including whitespaces, so splitting names and
- # descriptions by whitespaces is not enough for some cases.
- # We probably need something like "--list-steps names_only".
+ # including whitespaces, so splitting names and descriptions
+ # by whitespaces is not enough for some cases.
+ # We probably need something like "--list-steps names_only".
# In practice, almost nobody sets such names.
step_name=$(awk '{print $1}' <<< "${step}")
if [[ ${step_name} == test ]]; then
found_test_step=true
break
fi
done
if [[ ${found_test_step} == true ]]; then
- ezig build test "${ZBS_ARGS[@]}" "${@}" || die "ZBS: tests failed"
+ nonfatal ezig build test "${args[@]}" \
+ || die "ZBS: tests failed"
else
einfo "Test step not found, skipping."
fi
popd > /dev/null || die
}
# @FUNCTION: zig-build_src_install
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Calls "ezig build install" with DESTDIR and previously set ZBS_ARGS.
-# Args passed to this function will be passed after ZBS_ARGS.
-# Also installs documentation via "einstalldocs".
+# Calls "ezig build install" with DESTDIR and previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Also installs documentation via "einstalldocs".
zig-build_src_install() {
pushd "${BUILD_DIR}" > /dev/null || die
- DESTDIR="${D}" ezig build install "${ZBS_ARGS[@]}" "${@}" || die "ZBS: installing failed"
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ DESTDIR="${D}" nonfatal ezig build install "${args[@]}" \
+ || die "ZBS: installing failed"
popd > /dev/null || die
pushd "${S}" > /dev/null || die
einstalldocs
popd > /dev/null || die
}
fi
if [[ ! ${ZIG_OPTIONAL} ]]; then
EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install
fi
diff --git a/eclass/zig-toolchain.eclass b/eclass/zig-toolchain.eclass
index 6297c9fc9cdd..42a3f8ec3706 100644
--- a/eclass/zig-toolchain.eclass
+++ b/eclass/zig-toolchain.eclass
@@ -1,336 +1,375 @@
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: zig-toolchain.eclass
# @MAINTAINER:
# Eric Joldasov <bratishkaerik@landless-city.net>
# @AUTHOR:
# Eric Joldasov <bratishkaerik@landless-city.net>
# @SUPPORTED_EAPIS: 8
-# @BLURB: Prepare Zig toolchain and set environment variables.
+# @BLURB: Prepare Zig toolchain and set environment variables
# @DESCRIPTION:
-# Prepare Zig toolchain and set environment variables. Supports Zig 0.13+.
+# Prepare Zig toolchain and set environment variables.
+# Supports Zig 0.13+.
# Does not set any default function, ebuilds must call them manually.
# Generally, only "zig-toolchain_populate_env_vars" is needed.
#
# Intended to be used by ebuilds that call "zig build-exe/lib/obj"
# or "zig test" directly and by "dev-lang/zig".
# For ebuilds with ZBS (Zig Build System), it's usually better
# to inherit zig-build instead, as it has default phases-functions.
+if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
+_ZIG_TOOLCHAIN_ECLASS=1
+
case ${EAPI} in
8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
-if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
-_ZIG_TOOLCHAIN_ECLASS=1
-
inherit edo flag-o-matic
# @ECLASS_VARIABLE: ZIG_SLOT
# @PRE_INHERIT
# @REQUIRED
# @DESCRIPTION:
-# Zig slot that will be used in "ezig" function. Also, if ZIG_OPTIONAL is
-# empty, adds dev-lang/zig and dev-lang/zig-bin dependency to BDEPEND.
-# Must be >= "0.13".
+# Zig slot that will be used in "ezig" function. Also, if
+# ZIG_OPTIONAL is empty, adds dev-lang/zig and dev-lang/zig-bin
+# dependency to BDEPEND. Must be >= "0.13".
#
# Example:
# @CODE
# 0.13
# @CODE
#
# When a new Zig release occurs, it is advisable for maintainers to
-# check whether their ebuild supports that new version. If yes, they
+# check whether their ebuild supports that new version. If yes, they
# they should bump ZIG_SLOT to the latest version; if not supported,
-# they need to patch any issues with new version and again bump ZIG_SLOT.
-# This helps to reduce dependencies on outdated Zig versions.
+# they need to patch any issues with new version and again bump
+# ZIG_SLOT. This helps to reduce dependencies on outdated Zig
+# versions.
#
# This policy of "1 exclusive Zig slot" will work until it
# stabilizes enough (probably near 1.0), then it will be re-evaluated
# and most likely changed to more common in other eclasses ZIG_MIN/
# ZIG_MAX form.
# @ECLASS_VARIABLE: ZIG_OPTIONAL
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION:
-# If set to a non-empty value, all logic in zig-toolchain and zig-build
-# eclasses will be considered optional. No dependencies will be added and
-# no phase functions will be exported.
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
#
# For zig-toolchain.eclass users:
# You have to add Zig dependency in your BDEPEND manually and call
# at least "zig-toolchain_populate_env_vars" before using "ezig".
#
-# For zig-build.eclass users: see documentation in zig-build.eclass instead.
+# For zig-build.eclass users: see documentation in zig-build.eclass
+# instead.
if [[ ! ${ZIG_OPTIONAL} ]]; then
- BDEPEND+=" || (
+ BDEPEND="|| (
dev-lang/zig:${ZIG_SLOT}
dev-lang/zig-bin:${ZIG_SLOT}
)"
fi
# @ECLASS_VARIABLE: ZIG_TARGET
# @DESCRIPTION:
-# Zig target triple to use. Has the following format:
+# Zig target triple to use. Has the following format:
# arch-os[.os_version_range]-abi[.abi_version]
# Can be passed as:
# * "-target " option in "zig test" or "zig build-exe/lib/obj",
-# * "-Dtarget=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
+# * "-Dtarget=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
#
-# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
#
# Example:
# @CODE
-# native # autodetected by Zig
-# x86_64-linux-gnu # Machine running Linux x86_64 system, with glibc
-# x86_64-linux.6.1.12...6.6.16-gnu.2.38 # Similar to above, but versions are passed explicitly
-# powerpc64le-linux-musl # Machine running Linux 64-bit little-endian PowerPC system, with musl
+# # Autodetected by Zig:
+# native
+# # Machine running Linux x86_64 system, with glibc:
+# x86_64-linux-gnu
+# # Similar to above, but versions are passed explicitly:
+# x86_64-linux.6.1.12...6.6.16-gnu.2.38
+# # Machine running Linux PPC64 little-endian system, with musl
+# powerpc64le-linux-musl
# @CODE
#
# @ECLASS_VARIABLE: ZIG_CPU
# @DESCRIPTION:
-# Zig target CPU and features to use. Has the following format:
+# Zig target CPU and features to use. Has the following format:
# family_name(\+enable_feature|\-disable_feature)*
# Can be passed as:
# * "-mcpu " option in "zig test" or "zig build-exe/lib/obj",
-# * "-Dcpu=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
+# * "-Dcpu=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
#
-# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
#
# Example:
# @CODE
-# native # autodetected by Zig
-# znver2 # AMD Zen 2 processor
-# x86_64+x87-sse2" # x86_64 processor, X87 support enabled, SSE2 support disabled
+# # Autodetected by Zig:
+# native
+# # AMD Zen 2 processor
+# znver2
+# # x86_64 processor, X87 support enabled, SSE2 support disabled
+# x86_64+x87-sse2
# @CODE
# @ECLASS_VARIABLE: ZIG_EXE
# @DESCRIPTION:
# Absolute path to the used Zig executable.
#
-# Please note that when passing one flag several times with different values:
-# * to "zig build" in "-Dbar=false -Dbar" form: errors due to conflict of flags,
-# * to "zig build" in "-Dbar=false -Dbar=true" form: "bar" becomes a list, which is likely not what you (or upstream) want,
-# * to "zig test" or "zig build-exe/lib/obj" in "-fbar -fno-bar" form: latest value overwrites values before.
-# Similar situation with other types of options (enums, "std.SemanticVersion", integers, strings, etc.)
+# Please note that when passing one flag several times with different
+# values:
+# * (only "zig build") in "-Dbar=false -Dbar" form:
+# errors due to conflict of flags,
+# * (only "zig build") in "-Dbar=false -Dbar=true" form:
+# "bar" becomes a list, which is likely not what you want,
+# * in "-fbar -fno-bar" form:
+# latest value overwrites values before.
+# Example above shows only boolean option, but it is same with other
+# types of options (enums, "std.zig.BuildId", "std.SemanticVersion",
+# integers, strings, etc.).
#
-# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
# @ECLASS_VARIABLE: ZIG_VER
# @OUTPUT_VARIABLE
# @DESCRIPTION:
-# Zig version found during "zig-toolchain_find_installation", as reported in dev-lang/zig-${PV} PV part.
+# Zig version found during "zig-toolchain_find_installation",
+# as reported in dev-lang/zig-${PV} PV part.
#
# Example:
# @CODE
# 0.13.0
# @CODE
# @FUNCTION: zig-toolchain_get_target
# @USAGE: <C-style target triple>
# @DESCRIPTION:
# Translates C-style target triple (like CHOST or CBUILD)
-# to Zig-style target triple. Some information (like ARM features)
-# is handled by "zig-toolchain_get_cpu". Mostly used during cross-compiling
-# if user does not set ZIG_TARGET variable.
+# to Zig-style target triple. Some information (like ARM features)
+# is handled by "zig-toolchain_get_cpu". Mostly used during
+# cross-compiling if user does not set ZIG_TARGET variable.
#
# See ZIG_TARGET description for more information.
zig-toolchain_get_target() {
- [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
local c_target=${1}
local c_target_prefix=${c_target%%-*}
local c_target_suffix=${c_target##*-}
local arch os abi
case ${c_target_prefix} in
i?86) arch=x86;;
arm64) arch=aarch64;;
arm*) arch=arm;;
- *) arch=${c_target_prefix};;
+ *) arch=${c_target_prefix};;
esac
case ${c_target} in
*linux*) os=linux;;
*apple*) os=macos;;
esac
case ${c_target_suffix} in
solaris*) os=solaris abi=none;;
darwin*) abi=none;;
- *) abi=${c_target_suffix};;
+ *) abi=${c_target_suffix};;
esac
- [[ ${arch} == arm && ${abi} == gnu ]] && die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
+ if [[ ${arch} == arm && ${abi} == gnu ]]; then
+ die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
+ fi
echo ${arch}-${os}-${abi}
}
# @FUNCTION: zig-toolchain_get_cpu
# @USAGE: <C-style target triple>
# @DESCRIPTION:
# Translates C-style target triple (like CHOST or CBUILD)
-# to Zig-style target CPU and features. Mostly used to get generic target CPU
-# during cross-compiling if user does not set ZIG_CPU variable.
+# to Zig-style target CPU and features. Mostly used to get generic
+# target CPU during cross-compiling if user does not set ZIG_CPU
+# variable.
#
# See ZIG_CPU description for more information.
zig-toolchain_get_cpu() {
- [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
local c_target=${1}
local c_target_prefix=${c_target%%-*}
local base_cpu features=""
case ${c_target_prefix} in
i?86) base_cpu=${c_target_prefix};;
loongarch64) base_cpu=generic_la64;;
powerpc | powerpcle) base_cpu=ppc;;
powerpc64) base_cpu=ppc64;;
powerpc64le) base_cpu=ppc64le;;
riscv32) base_cpu=generic_rv32;;
riscv64) base_cpu=generic_rv64;;
*) base_cpu=generic;;
esac
case ${c_target_prefix} in
armv5tel) features+="+v5te";;
armv*) features+="+${c_target_prefix##armv}";;
esac
case ${c_target_prefix} in
arm64) ;;
arm*)
local is_softfloat=$(CTARGET=${c_target} tc-tuple-is-softfloat)
case ${is_softfloat} in
only | yes) features+="+soft_float";;
softfp | no) features+="-soft_float";;
*) die "${FUNCNAME[0]}: tc-tuple-is-softfloat returned unexpected value"
esac
;;
esac
echo ${base_cpu}${features}
}
# @FUNCTION: zig-toolchain_find_installation
# @DESCRIPTION:
-# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE variables.
+# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE
+# variables.
#
# See ZIG_EXE and ZIG_VER descriptions for more information.
zig-toolchain_find_installation() {
# Adapted from https://github.com/gentoo/gentoo/pull/28986
# Many thanks to Florian Schmaus (Flowdalic)!
[[ -n ${ZIG_SLOT} ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set"
if ver_test "${ZIG_SLOT}" -lt "0.13"; then
die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}"
fi
einfo "Searching Zig ${ZIG_SLOT}..."
local zig_supported_versions=(
"9999"
"0.13.1"
"0.13.0"
)
- local selected_path selected_version
- for selected_version in "${zig_supported_versions[@]}"; do
- # Compare with ZIG_SLOT (like 0.13)
- local candidate_slot=$(ver_cut 1-2 ${selected_version})
+ local base_path="${BROOT}/usr/bin"
+
+ local selected_path selected_ver
+ for selected_ver in "${zig_supported_versions[@]}"; do
+ # Check if candidate satisfies ZIG_SLOT condition.
+ local candidate_slot
+ candidate_slot=$(ver_cut 1-2 ${selected_ver})
if ver_test "${candidate_slot}" -ne ${ZIG_SLOT}; then
- # Candidate does not satisfy ZIG_SLOT condition.
continue
fi
+ local candidate_path
# Prefer "dev-lang/zig" over "dev-lang/zig-bin"
- local candidate_path="${BROOT}/usr/bin/zig-${selected_version}"
+ candidate_path="${base_path}/zig-${selected_ver}"
if [[ -x "${candidate_path}" ]]; then
selected_path="${candidate_path}"
break;
fi
- candidate_path="${BROOT}/usr/bin/zig-bin-${selected_version}"
+ candidate_path="${base_path}/zig-bin-${selected_ver}"
if [[ -x "${candidate_path}" ]]; then
selected_path="${candidate_path}"
break;
fi
done
if [[ -z "${selected_path}" ]]; then
- die "Could not find (suitable) Zig installation in \"${BROOT}/usr/bin/\""
+ die "Could not find (suitable) Zig at \"${base_path}\""
fi
export ZIG_EXE="${selected_path}"
- export ZIG_VER="${selected_version}"
- # Sanity check, from upstream:
- # // Check libc++ linkage to make sure Zig was built correctly, but only
- # // for "env" and "version" to avoid affecting the startup time for
- # // build-critical commands (check takes about ~10 μs)
- "${ZIG_EXE}" version > /dev/null || die "Sanity check failed for \"${ZIG_EXE}\""
+ export ZIG_VER="${selected_ver}"
+ # Sanity check, comment from upstream:
+ # > Check libc++ linkage to make sure Zig was built correctly,
+ # > but only for "env" and "version" to avoid affecting the
+ # > startup time for build-critical commands
+ # > (check takes about ~10 μs)
+ "${ZIG_EXE}" version > /dev/null \
+ || die "Sanity check failed for \"${ZIG_EXE}\""
}
# @FUNCTION: zig-toolchain_populate_env_vars
# @DESCRIPTION:
# Populates ZIG_TARGET, ZIG_CPU, ZIG_EXE and ZIG_VER environment
# variables with detected values, or, if user set them already,
# leaves as-is.
zig-toolchain_populate_env_vars() {
- # Should be first because it sets ZIG_VER which might be used in the future
- # when setting ZIG_TARGET and ZIG_CPU variables for incompatible versions.
+ # Should be first because it sets ZIG_VER which might be used
+ # in the future when setting ZIG_TARGET and ZIG_CPU variables
+ # for incompatible versions.
if [[ -z "${ZIG_EXE}" ]]; then
zig-toolchain_find_installation
fi
if [[ -z ${ZIG_TARGET} ]]; then
if tc-is-cross-compiler; then
export ZIG_TARGET=$(zig-toolchain_get_target ${CHOST})
else
export ZIG_TARGET=native
fi
fi
if [[ -z ${ZIG_CPU} ]]; then
if tc-is-cross-compiler; then
export ZIG_CPU=$(zig-toolchain_get_cpu ${CHOST})
else
export ZIG_CPU=native
fi
fi
einfo "ZIG_EXE: \"${ZIG_EXE}\""
einfo "ZIG_VER: ${ZIG_VER}"
einfo "ZIG_TARGET: ${ZIG_TARGET}"
einfo "ZIG_CPU: ${ZIG_CPU}"
}
# @FUNCTION: ezig
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set.
+# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set or
+# if command exits with error. Respects `nonfatal`.
#
-# Always disables progress bar (tree in 0.13+).
-# By default enables ANSI escape codes (colours, etc.), set NO_COLOR
-# environment variable to disable them.
+# Always disables progress tree. By default enables ANSI escape codes
+# (colours, etc.), user can set NO_COLOR environment variable to
+# disable them.
ezig() {
- # Sync description above and comments below with "std.io.tty.detectConfig".
- debug-print-function "${FUNCNAME[0]}" "${@}"
+ # Sync description above and comments below with upstream's
+ # "std.io.tty.detectConfig".
+ debug-print-function "${FUNCNAME[0]}" "${@}"
if [[ -z "${ZIG_EXE}" ]] ; then
die "${FUNCNAME[0]}: ZIG_EXE is not set. Was 'zig-toolchain_populate_env_vars' called before using ezig?"
fi
- # Progress bar (tree in newer versions) are helpful indicators in
- # TTY, but unfortunately they make Portage logs harder to read in plaintext.
- # We pass "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE (or YES_COLOR
- # until 0.13) to preserve colors.
+ # Progress tree is helpful indicator in TTY, but unfortunately
+ # they make Portage logs harder to read in plaintext. We pass
+ # "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE to
+ # preserve colors.
# User's NO_COLOR takes precendence over this.
- TERM=dumb YES_COLOR=1 CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}"
+ TERM=dumb CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}" \
+ || die -n "Failed to run command: ${ZIG_EXE} ${@}"
}
fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
@ 2024-10-25 21:20 ` Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 2/5] zig-build.eclass: " Eric Joldasov
` (3 subsequent siblings)
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:20 UTC (permalink / raw
To: gentoo-dev
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/zig-toolchain.eclass | 375 ++++++++++++++++++++++++++++++++++++
1 file changed, 375 insertions(+)
create mode 100644 eclass/zig-toolchain.eclass
diff --git a/eclass/zig-toolchain.eclass b/eclass/zig-toolchain.eclass
new file mode 100644
index 000000000000..42a3f8ec3706
--- /dev/null
+++ b/eclass/zig-toolchain.eclass
@@ -0,0 +1,375 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig-toolchain.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @BLURB: Prepare Zig toolchain and set environment variables
+# @DESCRIPTION:
+# Prepare Zig toolchain and set environment variables.
+# Supports Zig 0.13+.
+# Does not set any default function, ebuilds must call them manually.
+# Generally, only "zig-toolchain_populate_env_vars" is needed.
+#
+# Intended to be used by ebuilds that call "zig build-exe/lib/obj"
+# or "zig test" directly and by "dev-lang/zig".
+# For ebuilds with ZBS (Zig Build System), it's usually better
+# to inherit zig-build instead, as it has default phases-functions.
+
+if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
+_ZIG_TOOLCHAIN_ECLASS=1
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit edo flag-o-matic
+
+# @ECLASS_VARIABLE: ZIG_SLOT
+# @PRE_INHERIT
+# @REQUIRED
+# @DESCRIPTION:
+# Zig slot that will be used in "ezig" function. Also, if
+# ZIG_OPTIONAL is empty, adds dev-lang/zig and dev-lang/zig-bin
+# dependency to BDEPEND. Must be >= "0.13".
+#
+# Example:
+# @CODE
+# 0.13
+# @CODE
+#
+# When a new Zig release occurs, it is advisable for maintainers to
+# check whether their ebuild supports that new version. If yes, they
+# they should bump ZIG_SLOT to the latest version; if not supported,
+# they need to patch any issues with new version and again bump
+# ZIG_SLOT. This helps to reduce dependencies on outdated Zig
+# versions.
+#
+# This policy of "1 exclusive Zig slot" will work until it
+# stabilizes enough (probably near 1.0), then it will be re-evaluated
+# and most likely changed to more common in other eclasses ZIG_MIN/
+# ZIG_MAX form.
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
+#
+# For zig-toolchain.eclass users:
+# You have to add Zig dependency in your BDEPEND manually and call
+# at least "zig-toolchain_populate_env_vars" before using "ezig".
+#
+# For zig-build.eclass users: see documentation in zig-build.eclass
+# instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND="|| (
+ dev-lang/zig:${ZIG_SLOT}
+ dev-lang/zig-bin:${ZIG_SLOT}
+ )"
+fi
+
+# @ECLASS_VARIABLE: ZIG_TARGET
+# @DESCRIPTION:
+# Zig target triple to use. Has the following format:
+# arch-os[.os_version_range]-abi[.abi_version]
+# Can be passed as:
+# * "-target " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dtarget=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
+#
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
+#
+# Example:
+# @CODE
+# # Autodetected by Zig:
+# native
+# # Machine running Linux x86_64 system, with glibc:
+# x86_64-linux-gnu
+# # Similar to above, but versions are passed explicitly:
+# x86_64-linux.6.1.12...6.6.16-gnu.2.38
+# # Machine running Linux PPC64 little-endian system, with musl
+# powerpc64le-linux-musl
+# @CODE
+#
+
+# @ECLASS_VARIABLE: ZIG_CPU
+# @DESCRIPTION:
+# Zig target CPU and features to use. Has the following format:
+# family_name(\+enable_feature|\-disable_feature)*
+# Can be passed as:
+# * "-mcpu " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dcpu=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
+#
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
+#
+# Example:
+# @CODE
+# # Autodetected by Zig:
+# native
+# # AMD Zen 2 processor
+# znver2
+# # x86_64 processor, X87 support enabled, SSE2 support disabled
+# x86_64+x87-sse2
+# @CODE
+
+# @ECLASS_VARIABLE: ZIG_EXE
+# @DESCRIPTION:
+# Absolute path to the used Zig executable.
+#
+# Please note that when passing one flag several times with different
+# values:
+# * (only "zig build") in "-Dbar=false -Dbar" form:
+# errors due to conflict of flags,
+# * (only "zig build") in "-Dbar=false -Dbar=true" form:
+# "bar" becomes a list, which is likely not what you want,
+# * in "-fbar -fno-bar" form:
+# latest value overwrites values before.
+# Example above shows only boolean option, but it is same with other
+# types of options (enums, "std.zig.BuildId", "std.SemanticVersion",
+# integers, strings, etc.).
+#
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
+
+# @ECLASS_VARIABLE: ZIG_VER
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Zig version found during "zig-toolchain_find_installation",
+# as reported in dev-lang/zig-${PV} PV part.
+#
+# Example:
+# @CODE
+# 0.13.0
+# @CODE
+
+# @FUNCTION: zig-toolchain_get_target
+# @USAGE: <C-style target triple>
+# @DESCRIPTION:
+# Translates C-style target triple (like CHOST or CBUILD)
+# to Zig-style target triple. Some information (like ARM features)
+# is handled by "zig-toolchain_get_cpu". Mostly used during
+# cross-compiling if user does not set ZIG_TARGET variable.
+#
+# See ZIG_TARGET description for more information.
+zig-toolchain_get_target() {
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
+ local c_target=${1}
+ local c_target_prefix=${c_target%%-*}
+ local c_target_suffix=${c_target##*-}
+
+ local arch os abi
+
+ case ${c_target_prefix} in
+ i?86) arch=x86;;
+ arm64) arch=aarch64;;
+ arm*) arch=arm;;
+ *) arch=${c_target_prefix};;
+ esac
+
+ case ${c_target} in
+ *linux*) os=linux;;
+ *apple*) os=macos;;
+ esac
+
+ case ${c_target_suffix} in
+ solaris*) os=solaris abi=none;;
+ darwin*) abi=none;;
+ *) abi=${c_target_suffix};;
+ esac
+
+ if [[ ${arch} == arm && ${abi} == gnu ]]; then
+ die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
+ fi
+
+ echo ${arch}-${os}-${abi}
+}
+
+
+
+# @FUNCTION: zig-toolchain_get_cpu
+# @USAGE: <C-style target triple>
+# @DESCRIPTION:
+# Translates C-style target triple (like CHOST or CBUILD)
+# to Zig-style target CPU and features. Mostly used to get generic
+# target CPU during cross-compiling if user does not set ZIG_CPU
+# variable.
+#
+# See ZIG_CPU description for more information.
+zig-toolchain_get_cpu() {
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
+ local c_target=${1}
+ local c_target_prefix=${c_target%%-*}
+
+ local base_cpu features=""
+
+ case ${c_target_prefix} in
+ i?86) base_cpu=${c_target_prefix};;
+ loongarch64) base_cpu=generic_la64;;
+ powerpc | powerpcle) base_cpu=ppc;;
+ powerpc64) base_cpu=ppc64;;
+ powerpc64le) base_cpu=ppc64le;;
+ riscv32) base_cpu=generic_rv32;;
+ riscv64) base_cpu=generic_rv64;;
+ *) base_cpu=generic;;
+ esac
+
+ case ${c_target_prefix} in
+ armv5tel) features+="+v5te";;
+ armv*) features+="+${c_target_prefix##armv}";;
+ esac
+
+ case ${c_target_prefix} in
+ arm64) ;;
+ arm*)
+ local is_softfloat=$(CTARGET=${c_target} tc-tuple-is-softfloat)
+ case ${is_softfloat} in
+ only | yes) features+="+soft_float";;
+ softfp | no) features+="-soft_float";;
+ *) die "${FUNCNAME[0]}: tc-tuple-is-softfloat returned unexpected value"
+ esac
+ ;;
+ esac
+
+ echo ${base_cpu}${features}
+}
+
+# @FUNCTION: zig-toolchain_find_installation
+# @DESCRIPTION:
+# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE
+# variables.
+#
+# See ZIG_EXE and ZIG_VER descriptions for more information.
+zig-toolchain_find_installation() {
+ # Adapted from https://github.com/gentoo/gentoo/pull/28986
+ # Many thanks to Florian Schmaus (Flowdalic)!
+
+ [[ -n ${ZIG_SLOT} ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set"
+ if ver_test "${ZIG_SLOT}" -lt "0.13"; then
+ die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}"
+ fi
+
+ einfo "Searching Zig ${ZIG_SLOT}..."
+
+ local zig_supported_versions=(
+ "9999"
+ "0.13.1"
+ "0.13.0"
+ )
+
+ local base_path="${BROOT}/usr/bin"
+
+ local selected_path selected_ver
+ for selected_ver in "${zig_supported_versions[@]}"; do
+ # Check if candidate satisfies ZIG_SLOT condition.
+ local candidate_slot
+ candidate_slot=$(ver_cut 1-2 ${selected_ver})
+ if ver_test "${candidate_slot}" -ne ${ZIG_SLOT}; then
+ continue
+ fi
+
+ local candidate_path
+ # Prefer "dev-lang/zig" over "dev-lang/zig-bin"
+ candidate_path="${base_path}/zig-${selected_ver}"
+ if [[ -x "${candidate_path}" ]]; then
+ selected_path="${candidate_path}"
+ break;
+ fi
+
+ candidate_path="${base_path}/zig-bin-${selected_ver}"
+ if [[ -x "${candidate_path}" ]]; then
+ selected_path="${candidate_path}"
+ break;
+ fi
+ done
+
+ if [[ -z "${selected_path}" ]]; then
+ die "Could not find (suitable) Zig at \"${base_path}\""
+ fi
+
+ export ZIG_EXE="${selected_path}"
+ export ZIG_VER="${selected_ver}"
+ # Sanity check, comment from upstream:
+ # > Check libc++ linkage to make sure Zig was built correctly,
+ # > but only for "env" and "version" to avoid affecting the
+ # > startup time for build-critical commands
+ # > (check takes about ~10 μs)
+ "${ZIG_EXE}" version > /dev/null \
+ || die "Sanity check failed for \"${ZIG_EXE}\""
+}
+
+# @FUNCTION: zig-toolchain_populate_env_vars
+# @DESCRIPTION:
+# Populates ZIG_TARGET, ZIG_CPU, ZIG_EXE and ZIG_VER environment
+# variables with detected values, or, if user set them already,
+# leaves as-is.
+zig-toolchain_populate_env_vars() {
+ # Should be first because it sets ZIG_VER which might be used
+ # in the future when setting ZIG_TARGET and ZIG_CPU variables
+ # for incompatible versions.
+ if [[ -z "${ZIG_EXE}" ]]; then
+ zig-toolchain_find_installation
+ fi
+
+ if [[ -z ${ZIG_TARGET} ]]; then
+ if tc-is-cross-compiler; then
+ export ZIG_TARGET=$(zig-toolchain_get_target ${CHOST})
+ else
+ export ZIG_TARGET=native
+ fi
+ fi
+
+ if [[ -z ${ZIG_CPU} ]]; then
+ if tc-is-cross-compiler; then
+ export ZIG_CPU=$(zig-toolchain_get_cpu ${CHOST})
+ else
+ export ZIG_CPU=native
+ fi
+ fi
+
+ einfo "ZIG_EXE: \"${ZIG_EXE}\""
+ einfo "ZIG_VER: ${ZIG_VER}"
+ einfo "ZIG_TARGET: ${ZIG_TARGET}"
+ einfo "ZIG_CPU: ${ZIG_CPU}"
+}
+
+# @FUNCTION: ezig
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set or
+# if command exits with error. Respects `nonfatal`.
+#
+# Always disables progress tree. By default enables ANSI escape codes
+# (colours, etc.), user can set NO_COLOR environment variable to
+# disable them.
+ezig() {
+ # Sync description above and comments below with upstream's
+ # "std.io.tty.detectConfig".
+ debug-print-function "${FUNCNAME[0]}" "${@}"
+
+ if [[ -z "${ZIG_EXE}" ]] ; then
+ die "${FUNCNAME[0]}: ZIG_EXE is not set. Was 'zig-toolchain_populate_env_vars' called before using ezig?"
+ fi
+
+ # Progress tree is helpful indicator in TTY, but unfortunately
+ # they make Portage logs harder to read in plaintext. We pass
+ # "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE to
+ # preserve colors.
+ # User's NO_COLOR takes precendence over this.
+ TERM=dumb CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}" \
+ || die -n "Failed to run command: ${ZIG_EXE} ${@}"
+}
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 2/5] zig-build.eclass: new eclass
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
@ 2024-10-25 21:20 ` Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
` (2 subsequent siblings)
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:20 UTC (permalink / raw
To: gentoo-dev
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/zig-build.eclass | 580 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 580 insertions(+)
create mode 100644 eclass/zig-build.eclass
diff --git a/eclass/zig-build.eclass b/eclass/zig-build.eclass
new file mode 100644
index 000000000000..ffa075043cde
--- /dev/null
+++ b/eclass/zig-build.eclass
@@ -0,0 +1,580 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig-build.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Alfred Wingate <parona@protonmail.com>
+# Violet Purcell <vimproved@inventati.org>
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: zig-toolchain
+# @BLURB: Functions for working with ZBS (Zig Build System)
+# @DESCRIPTION:
+# Functions for working with Zig build system and package manager.
+# Supports Zig 0.13+. Exports default functions for convenience.
+#
+# Note that zig-build.eclass is mostly tailored for projects that:
+# 1) Install something in build.zig steps: "artifacts" (executable,
+# libraries, objects), source codes, assets, tests, scripts etc. But
+# many authors also use it to write Zig "modules", build logic
+# and/or bindings/wrappers for C/C++ libraries. They install nothing
+# and are only used at build-time, so it's unneccessary and mostly
+# useless to make ebuilds for them.
+# 2) Have required `target`, `cpu` and optional `optimize` options in
+# build.zig that accept standard Zig-style target and optimize mode.
+# They are usually created by calling `b.standardTargetOptions` and
+# `b.standardOptimizeOption` functions.
+#
+# For end-user executables, usually it's recommended to patch to call
+# these options and upstream it, but in some cases authors have good
+# reasons to not have them, f.e. if it is built only for WASM
+# platform with ReleaseSmall, and is not intended to run in /usr/bin/.
+# In this case, declare dummy options using `b.option` and ignore
+# their values, or else eclass wouldn't work.
+#
+# Another case is when upstream has `target` option but it has
+# custom format and does not accept usual Zig targets, but rather
+# something specific to the project like "linux-baseline-lts", or
+# combine CPU and target in one option.
+# In this case, it's best to rename that option to something like
+# `target-custom`, then declare `target` option and make converter
+# from one value to other.
+#
+# For non-executable binaries like C libraries, objects etc. our
+# policy is stricter, all 3 options are required and should not
+# be ignored, with no exceptions.
+
+if [[ ! ${_ZIG_BUILD_ECLASS} ]]; then
+_ZIG_BUILD_ECLASS=1
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit multiprocessing zig-toolchain
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
+#
+# For zig-build.eclass users:
+# You need to add Zig and pkgconfig dependencies in your BDEPEND, set
+# QA_FLAGS_IGNORED and call all phase functions manually. If you want
+# to use "ezig build" directly, call "zig-build_pkg_setup" before it.
+#
+# For zig-toolchain.eclass users: see documentation in
+# zig-toolchain.eclass instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND="virtual/pkgconfig"
+
+ # See https://github.com/ziglang/zig/issues/3382
+ # Zig Build System does not support CFLAGS/LDFLAGS/etc.
+ QA_FLAGS_IGNORED=".*"
+fi
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Bash associative array with all tarballs that will be fetched by
+# "ezig fetch" in zig-build_src_unpack phase. Value is URL where
+# tarball is located, key is name under which it would be downloaded
+# and renamed. So generally it has effect of "value -> key".
+#
+# Note: if Zig Build System dependency can't be represented in SRC_URI
+# (like direct Git commit URIs), you should do the following
+# (zig-ebuilder does archiving automatically for you):
+# 1. Archive each folder with dependency content in some tarball,
+# so f.e. if you have 2 Git dependencies, create 2 tarballs.
+# 2. Archive all previous tarballs into one combined tarball (also
+# called tarball-tarball from now on), no subdirs, so that eclass
+# can firstly unpack this tarball with "unpack",
+# and secondly unpack its content with "zig fetch".
+# 3. (zig-ebuilder can't do this) Host this tarball somewhere
+# and put URL of this tarball in SRC_URI, and archives in
+# ZBS_DEPENDENCIES, keys must be names of archives, values empty.
+#
+# Example:
+# @CODE
+# declare -r -A ZBS_DEPENDENCIES=(
+# [tarball_a-<long-hash>.tar.gz]='URL_A'
+# [tarball_b-<long-hash>.tar.gz]='URL_B'
+#
+# # If there are Git dependencies:
+# [git_c-<long-hash>.tar.gz]=''
+# # Tarball-tarball should contain inside above tarball flatly.
+# )
+# @CODE
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES_SRC_URI
+# @OUTPUT_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in
+# SRC_URI. Note that elements with empty keys will be skipped.
+# Example:
+# @CODE
+# SRC_URI="
+# <URL to project sources, patches, non-Zig resources etc.>
+#
+# # If there are Git dependencies:
+# # <URL to tarball-tarball>
+#
+# ${ZBS_DEPENDENCIES_SRC_URI}
+# "
+# @CODE
+
+# @FUNCTION: _zig-build_set_zbs_uris
+# @INTERNAL
+# @DESCRIPTION:
+# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
+_zig-build_set_zbs_uris() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ ZBS_DEPENDENCIES_SRC_URI=
+
+ for dependency in ${!ZBS_DEPENDENCIES[@]}; do
+ local uri="${ZBS_DEPENDENCIES[${dependency}]}"
+ if [[ ${#uri} -gt 0 ]]; then
+ ZBS_DEPENDENCIES_SRC_URI+=" ${uri} -> ${dependency}"
+ else
+ # Unrepresentable dependency
+ continue
+ fi
+ done
+}
+_zig-build_set_zbs_uris
+
+# @ECLASS_VARIABLE: my_zbs_args
+# @DESCRIPTION:
+# Bash array with ebuild-specified arguments to pass to the
+# "zig build" after "src_configure".
+# It's appended to the ZBS_ARGS during "src_configure". Note: if you
+# need to override default optimize mode of this eclass (ReleaseSafe)
+# with your default, please use "--release=small" etc. syntax so that
+# user can still override it in ZBS_ARGS_EXTRA.
+#
+# Example:
+# @CODE
+# src_configure() {
+# local my_zbs_args=(
+# -Dpie=true
+# )
+#
+# zig-build_src_configure
+# }
+# @CODE
+: "${my_zbs_args:=}"
+
+# @ECLASS_VARIABLE: ZBS_ARGS_EXTRA
+# @USER_VARIABLE
+# @DESCRIPTION:
+# Bash string with user-specified arguments to pass to the "zig build"
+# after "src_configure".
+# It's appended to the ZBS_ARGS during "zig-build_src_configure".
+#
+# If this does not have amount of jobs, eclass will try to take amount
+# of jobs from MAKEOPTS, and if it also does not have them, it will
+# default to $(nproc).
+#
+# Example:
+# @CODE
+# -j8 --release=small
+# @CODE
+: "${ZBS_ARGS_EXTRA:=}"
+
+# @ECLASS_VARIABLE: ZBS_VERBOSE
+# @USER_VARIABLE
+# @DESCRIPTION:
+# If enabled, eclass will add "--summary all --verbose" options to
+# "ezig build", so that it prints every command before executing,
+# and summarry tree at the end of step. If not, will do nothing.
+# Enabled by default. Set to OFF to disable these verbose messages.
+#
+# Note: this variable does not control other options starting with
+# "--verbose-", such as "--verbose-link" or "--verbose-cimport". If
+# you need them, add them manually to ZBS_ARGS_EXTRA.
+: "${ZBS_VERBOSE:=ON}"
+
+# @ECLASS_VARIABLE: BUILD_DIR
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Directory where all "ezig build" calls will be proceeded.
+# Defaults to "${WORKDIR}/${P}-build" if not set.
+: "${BUILD_DIR:=${WORKDIR}/${P}-build}"
+
+# @ECLASS_VARIABLE: ZBS_ECLASS_DIR
+# @DESCRIPTION:
+# Directory where various files used by this eclass are stored.
+# They can be supplied by the ebuild or by eclass.
+# Currently, it's used only for Zig packages, which are stored in "p/"
+# subdirectory.
+# Defaults to "${WORKDIR}/zig-eclass" if not set.
+# Should be set before calling "zig-build_src_unpack" or
+# "zig-build_live_fetch".
+: "${ZBS_ECLASS_DIR:=${WORKDIR}/zig-eclass}"
+
+# @FUNCTION: zig-build_get_jobs
+# @DESCRIPTION:
+# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
+# If there is none, defaults to number of available processing units.
+zig-build_get_jobs() {
+ local all_args="${ZBS_ARGS_EXTRA} ${MAKEOPTS}"
+ local default_jobs="$(get_nproc)"
+ local jobs=$(makeopts_jobs "${all_args}" "${default_jobs}")
+
+ if [[ ${jobs} == "0" ]]; then
+ # Zig build system does not allow "-j0", and does not have
+ # option for unlimited parallelism. Pass our default number
+ # of jobs here.
+ echo "${default_jobs}"
+ else
+ echo "${jobs}"
+ fi
+}
+
+# @FUNCTION: zig-build_start_base_args
+# @DESCRIPTION:
+# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE.
+# Package manager option is managed by "zig-build_src_prepare",
+# ebuild and user options are added by "zig-build_src_configure".
+#
+# This function is used by "zig-build_pkg_setup", and it is neccessary
+# that args are available as early as possible, so that ebuilds
+# could use them in steps like "src_unpack" if neccessary, while
+# still having verbosity and amount of jobs from user respected.
+#
+#
+# TODO: currently this function enables "--search-prefix" (1) and
+# "--sysroot" (2) only when cross-compiling, should be fixed to
+# unconditionally enabling it.
+#
+# For solving (1) this patch should be reworked and upstreamed:
+# https://paste.sr.ht/~bratishkaerik/2ddffe2bf0f8f9d6dfb60403c2e9560334edaa88
+#
+# (2)
+# "--sysroot" should be passed together with "--search-prefix" above,
+# if we pass only "--sysroot" it gives these errors:
+# @CODE
+# error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
+# @CODE
+zig-build_start_base_args() {
+ [[ ${ZBS_ARGS_BASE} ]] && return
+
+ local crt_dir="${ESYSROOT}/usr/"
+ if [[ ${ZIG_TARGET} == *musl* ]]; then
+ crt_dir+="lib/"
+ else
+ crt_dir+="$(get_libdir)/"
+ fi
+
+ # 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"
+ # Note: they are not prepended by "--sysroot" value,
+ # so repeat it here.
+ include_dir=${ESYSROOT}/usr/include/
+ sys_include_dir=${ESYSROOT}/usr/include/
+ crt_dir=${crt_dir}
+ # Windows with MSVC only.
+ msvc_lib_dir=
+ # Windows with MSVC only.
+ kernel32_lib_dir=
+ # Haiku only.
+ gcc_dir=
+ _EOF_
+ if [[ ${?} -ne 0 ]]; then
+ die "Failed to create Zig libc installation info file"
+ fi
+
+ declare -g -a ZBS_ARGS_BASE=(
+ -j$(zig-build_get_jobs)
+ --build-file "${S}/build.zig"
+
+ -Dtarget=${ZIG_TARGET}
+ -Dcpu=${ZIG_CPU}
+ --release=safe
+
+ --prefix-exe-dir bin/
+ --prefix-lib-dir $(get_libdir)/
+ --prefix-include-dir include/
+
+ # Should be relative path to make other calls easier,
+ # so remove leading slash here.
+ --prefix "${EPREFIX:+${EPREFIX#/}/}usr/"
+
+ --libc "${T}/zig_libc.txt"
+ )
+ if [[ "${ZBS_VERBOSE}" != OFF ]]; then
+ ZBS_ARGS_BASE+=( --summary all --verbose )
+ fi
+
+ if tc-is-cross-compiler; then
+ ZBS_ARGS_BASE+=(
+ --search-prefix "${ESYSROOT}/usr/"
+ --sysroot "${ESYSROOT}/"
+ )
+ fi
+}
+
+# @FUNCTION: zig-build_pkg_setup
+# @DESCRIPTION:
+# Sets up environmental variables for Zig toolchain
+# and basic args for Zig Build System.
+zig-build_pkg_setup() {
+ [[ ${MERGE_TYPE} != binary ]] || return 0
+
+ zig-toolchain_populate_env_vars
+ zig-build_start_base_args
+
+ # Used only by 9999 for now, change in upstream did not appear
+ # in fixed release yet.
+ export PKG_CONFIG="${PKG_CONFIG:-$(tc-getPKG_CONFIG)}"
+
+ mkdir "${T}/zig-cache/" || die
+ export ZIG_LOCAL_CACHE_DIR="${T}/zig-cache/local/"
+ export ZIG_GLOBAL_CACHE_DIR="${T}/zig-cache/global/"
+}
+
+# @FUNCTION: zig-build_live_fetch
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
+# If you have some lazy dependency which is not triggered in default
+# configuration, pass options like you would pass them for regular
+# "ezig build". Try to cover all of them before "src_configure".
+# **Note**: this function will be deprecated once/if
+# https://github.com/ziglang/zig/pull/19975 lands.
+#
+# Example:
+# @CODE
+# src_unpack() {
+# # If there are no lazy dependency:
+# zig-build_live_fetch
+#
+# # If there are lazy dependencies that can be triggered together:
+# zig-build_live_fetch -Denable-wayland -Denable-xwayland
+#
+# # If there are 2 lazy dependencies that can't be triggered
+# # together in one call because they conflict:
+# zig-build_live_fetch -Dmain-backend=opengl
+# zig-build_live_fetch -Dmain-backend=vulkan
+# }
+# @CODE
+zig-build_live_fetch() {
+ # This function will likely be called in src_unpack,
+ # before [zig-build_]src_prepare, so this directory might not
+ # exist yet.
+ mkdir -p "${BUILD_DIR}" > /dev/null || die
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=(
+ --fetch
+
+ "${ZBS_ARGS_BASE[@]}"
+
+ # Function arguments
+ "${@}"
+ )
+
+ einfo "ZBS: live-fetching with following args: ${args[@]}"
+ ezig build --global-cache-dir "${ZBS_ECLASS_DIR}/" "${args[@]}"
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_unpack
+# @DESCRIPTION:
+# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES,
+# in that order.
+zig-build_src_unpack() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ if [[ "${#ZBS_DEPENDENCIES_SRC_URI}" -eq 0 ]]; then
+ default_src_unpack
+ return
+ fi
+
+ local zig_deps=()
+ for dependency in ${!ZBS_DEPENDENCIES[@]}; do
+ zig_deps+=("${dependency}")
+ done
+ # First unpack non-Zig dependencies, so that
+ # tarball with all Git dependencies tarballs is unpacked early.
+ for dist in ${A}; do
+ for zig_dep in "${zig_deps[@]}"; do
+ if [[ "${dist}" == "${zig_dep}" ]]; then
+ continue 2
+ fi
+ done
+
+ unpack "${dist}"
+ done
+
+ # Now unpack all Zig dependencies, including those that are
+ # now unpacked from tarball-tarball.
+ for zig_dep in "${zig_deps[@]}"; do
+ # Hide now-spammy hash from stdout
+ ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" \
+ "${DISTDIR}/${zig_dep}" > /dev/null
+ done
+ einfo "ZBS: ${#zig_deps[@]} dependencies fetched"
+}
+
+# @FUNCTION: zig-build_src_prepare
+# @DESCRIPTION:
+# Calls default "src_prepare" function, creates BUILD_DIR directory
+# and enables or disables system mode (by adding to ZBS_BASE_ARGS),
+# depending on how many packages there are.
+#
+# System mode is toggled here and not in "src_unpack" because they
+# could have been fetched by "live_fetch" in live ebuilds instead.
+zig-build_src_prepare() {
+ default_src_prepare
+
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+
+ local system_dir="${ZBS_ECLASS_DIR}/p/"
+
+ # We are using directories.len instead of ZBS_DEPENDENCIES.len
+ # because ebuild might have fetched packages using live_fetch
+ # instead.
+ local -a packages=()
+ readarray -d '' -t packages < <(find "${system_dir}" -mindepth 1 \
+ -maxdepth 1 -type d -print0 2> /dev/null || echo -n "")
+ local count="${#packages[@]}"
+
+ if [[ "${count}" -gt 0 ]]; then
+ einfo "ZBS: system mode enabled, ${count} packages found"
+ ZBS_ARGS_BASE+=( --system "${system_dir}" )
+ else
+ einfo "ZBS: no packages found, no need to enable system mode"
+ fi
+}
+
+# @FUNCTION: zig-build_src_configure
+# @DESCRIPTION:
+# Creates ZBS_ARGS array which can be used in all future phases,
+# by combining ZBS_ARGS_BASE set previously, my_zbs_args from ebuild,
+# and ZBS_ARGS_EXTRA by user, in this order.
+#
+# Specific flags currently only add support for the cross-compilation.
+# They are likely to be extended in the future.
+zig-build_src_configure() {
+ # Handle quoted whitespace.
+ eval "local -a ZBS_ARGS_EXTRA=( ${ZBS_ARGS_EXTRA} )"
+
+ # Since most arguments in array are also cached by ZBS, we
+ # want to reuse array as much as possible, so prevent
+ # modification of it.
+ declare -g -a -r ZBS_ARGS=(
+ # Base arguments from pkg_setup/setup_base_args
+ "${ZBS_ARGS_BASE[@]}"
+
+ # Arguments from ebuild
+ "${my_zbs_args[@]}"
+
+ # Arguments from user
+ "${ZBS_ARGS_EXTRA[@]}"
+ )
+
+ einfo "Configured with:"
+ einfo "${ZBS_ARGS[@]}"
+}
+
+# @FUNCTION: zig-build_src_compile
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build" with previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+zig-build_src_compile() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ nonfatal ezig build "${args[@]}" || die "ZBS: compilation failed"
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_test
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# If "test" step exist, calls "ezig build test" with previously set
+# ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Note: currently step detection might give false positives in
+# very rare cases, it will be improved in the future.
+zig-build_src_test() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+
+ # UPSTREAM std.testing.tmpDir and a lot of other functions
+ # do not respect --cache-dir or ZIG_LOCAL_CACHE_DIR:
+ # https://github.com/ziglang/zig/issues/19874
+ mkdir -p "zig-cache/" ".zig-cache/" || die
+
+ local found_test_step=false
+
+ local -a steps
+ readarray steps < <(nonfatal ezig build --list-steps "${args[@]}" \
+ || die "ZBS: listing steps failed")
+
+ for step in "${steps[@]}"; do
+ # UPSTREAM Currently, step name can have any characters in it,
+ # including whitespaces, so splitting names and descriptions
+ # by whitespaces is not enough for some cases.
+ # We probably need something like "--list-steps names_only".
+ # In practice, almost nobody sets such names.
+ step_name=$(awk '{print $1}' <<< "${step}")
+ if [[ ${step_name} == test ]]; then
+ found_test_step=true
+ break
+ fi
+ done
+
+ if [[ ${found_test_step} == true ]]; then
+ nonfatal ezig build test "${args[@]}" \
+ || die "ZBS: tests failed"
+ else
+ einfo "Test step not found, skipping."
+ fi
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_install
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build install" with DESTDIR and previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Also installs documentation via "einstalldocs".
+zig-build_src_install() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ DESTDIR="${D}" nonfatal ezig build install "${args[@]}" \
+ || die "ZBS: installing failed"
+ popd > /dev/null || die
+
+ pushd "${S}" > /dev/null || die
+ einstalldocs
+ popd > /dev/null || die
+}
+
+fi
+
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 2/5] zig-build.eclass: " Eric Joldasov
@ 2024-10-25 21:20 ` Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:20 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use llvm-r1 eclass instead of llvm, zig-build and
zig-toolchain functions instead of local get_zig_mcpu etc. functions.
* Port "llvm USE-flag" and "removing memory limit flags" from 9999
ebuild.
* Stage3 compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig-build.eclass with common options.
* Before migrating to the zig-build.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we use
upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in src_test is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-toolchain functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-toolchain.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with "zig std" command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
.../zig-0.13.0-skip-test-stack_iterator.patch | 32 +++
dev-lang/zig/zig-0.13.0-r1.ebuild | 245 ++++++++++++++++++
2 files changed, 277 insertions(+)
create mode 100644 dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
create mode 100644 dev-lang/zig/zig-0.13.0-r1.ebuild
diff --git a/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
new file mode 100644
index 000000000000..e088af2102ed
--- /dev/null
+++ b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
@@ -0,0 +1,32 @@
+From: Eric Joldasov <bratishkaerik@landless-city.net>
+
+Skip standalone test "stack_iterator" that fail on Gentoo Linux x86_64.
+Fails in ReleaseSafe, ReleaseFast and ReleaseSmall, but not in Debug.
+Reported to upstream here https://github.com/ziglang/zig/issues/19944 .
+
+Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
+
+diff --git a/test/standalone/stack_iterator/shared_lib_unwind.zig b/test/standalone/stack_iterator/shared_lib_unwind.zig
+index 57513a49c6..75fddb04c9 100644
+--- a/test/standalone/stack_iterator/shared_lib_unwind.zig
++++ b/test/standalone/stack_iterator/shared_lib_unwind.zig
+@@ -35,6 +35,7 @@ extern fn frame0(
+ ) void;
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
+diff --git a/test/standalone/stack_iterator/unwind.zig b/test/standalone/stack_iterator/unwind.zig
+index 69c463a0c1..40963af63d 100644
+--- a/test/standalone/stack_iterator/unwind.zig
++++ b/test/standalone/stack_iterator/unwind.zig
+@@ -87,6 +87,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {
+ }
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
diff --git a/dev-lang/zig/zig-0.13.0-r1.ebuild b/dev-lang/zig/zig-0.13.0-r1.ebuild
new file mode 100644
index 000000000000..5cca5e3efad6
--- /dev/null
+++ b/dev-lang/zig/zig-0.13.0-r1.ebuild
@@ -0,0 +1,245 @@
+# Copyright 2019-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+LLVM_COMPAT=( 18 )
+LLVM_OPTIONAL=1
+
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig-build
+
+DESCRIPTION="A robust, optimal, and maintainable programming language"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
+if [[ ${PV} == 9999 ]]; then
+ EGIT_REPO_URI="https://github.com/ziglang/zig.git"
+ inherit git-r3
+else
+ VERIFY_SIG_METHOD=minisig
+ VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
+ inherit verify-sig
+
+ SRC_URI="
+ https://ziglang.org/download/${PV}/${P}.tar.xz
+ verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
+ "
+ KEYWORDS="~amd64 ~arm ~arm64"
+
+ BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
+fi
+
+# project itself: MIT
+# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
+# Files that are unnecessary for cross-compilation are removed by upstream
+# and therefore their licenses (if any special) are not included.
+# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
+# lib/libc/musl: MIT BSD-2
+# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
+# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
+LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
+SLOT="${ZIG_SLOT}"
+IUSE="doc +llvm test"
+RESTRICT="!test? ( test )"
+REQUIRED_USE="
+ !llvm? ( !doc )
+ llvm? ( ${LLVM_REQUIRED_USE} )
+"
+
+# Used by both cmake and zig-build eclass.
+BUILD_DIR="${WORKDIR}/${P}_build"
+
+# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
+# (non-LLVM backends don't require these)
+# They are not required "on their own", so please don't add them here.
+# You can check https://github.com/ziglang/zig-bootstrap in future, to see
+# options that are passed to LLVM CMake building (excluding "static" ofc).
+DEPEND="
+ llvm? (
+ $(llvm_gen_dep '
+ sys-devel/clang:${LLVM_SLOT}
+ sys-devel/lld:${LLVM_SLOT}
+ sys-devel/llvm:${LLVM_SLOT}[zstd]
+ ')
+ )
+"
+BDEPEND+="
+ test? ( !!<sys-apps/sandbox-2.39 )
+ ${DEPEND}
+"
+RDEPEND="${DEPEND}"
+IDEPEND="app-eselect/eselect-zig"
+
+DOCS=("README.md" "doc/build.zig.zon.md")
+
+PATCHES=(
+ "${FILESDIR}/zig-0.13.0-test-std-kernel-version.patch"
+ "${FILESDIR}/zig-0.13.0-skip-test-stack_iterator.patch"
+)
+
+# zig-build does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+
+# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
+# Zig uses self-hosted compiler only
+CHECKREQS_MEMORY="4G"
+
+pkg_setup() {
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig-build_pkg_setup
+
+ export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
+
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
+ check-reqs_pkg_setup
+}
+
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ verify-sig_src_unpack
+ fi
+}
+
+src_prepare() {
+ if use llvm; then
+ cmake_src_prepare
+ else
+ # Sync with zig-build_src_prepare
+ default_src_prepare
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+ # "--system" mode is not used during bootstrap.
+ fi
+
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
+
+src_configure() {
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET=$(zig-toolchain_get_target ${CBUILD:-${CHOST}})
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
+ )
+ fi
+
+ zig-build_src_configure
+
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET}
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
+}
+
+src_compile() {
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
+
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET} CC="${native_cc}" edob ./bootstrap
+ fi
+
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig-build_src_compile --prefix "${BUILD_DIR}/stage3/"
+
+ ./stage3/bin/zig env || die "Zig compilation failed"
+
+ if use doc; then
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_compile langref --prefix "${S}/docgen/"
+ fi
+}
+
+src_test() {
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_test -Dskip-non-native
+}
+
+src_install() {
+ use doc && local HTML_DOCS=("docgen/doc/langref.html")
+
+ ZIG_EXE="./zig2" zig-build_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
+
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
+ mv lib/zig/ lib2/ || die
+ rm -rf lib/ || die
+ mv lib2/ lib/ || die
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
+}
+
+pkg_postinst() {
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
+
+ if ! use llvm; then
+ elog "Currently, Zig built without LLVM support lacks some"
+ elog "important features such as most optimizations, @cImport, etc."
+ elog "They are listed under \"Building from Source without LLVM\""
+ elog "section of the README file from \"/usr/share/doc/${PF}\" ."
+ fi
+}
+
+pkg_postrm() {
+ eselect zig update ifunset || die
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (2 preceding siblings ...)
2024-10-25 21:20 ` [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
@ 2024-10-25 21:20 ` Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:20 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use zig-build and zig-toolchain functions instead of
local get_zig_mcpu etc. functions.
* Port "sys-apps/sandbox-2.39" test dependency requirement from
0.13.0 ebuild.
* Stage3 compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig-build.eclass with common options.
* Before migrating to the zig-build.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we use
upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in src_test is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-toolchain functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-toolchain.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with "zig std" command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
dev-lang/zig/zig-9999.ebuild | 244 ++++++++++++++++++-----------------
1 file changed, 125 insertions(+), 119 deletions(-)
diff --git a/dev-lang/zig/zig-9999.ebuild b/dev-lang/zig/zig-9999.ebuild
index 335ac0eab28c..65650ac5c781 100644
--- a/dev-lang/zig/zig-9999.ebuild
+++ b/dev-lang/zig/zig-9999.ebuild
@@ -1,234 +1,240 @@
# Copyright 2019-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
LLVM_COMPAT=( 19 )
LLVM_OPTIONAL=1
-inherit check-reqs cmake edo llvm-r1 toolchain-funcs
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig-build
DESCRIPTION="A robust, optimal, and maintainable programming language"
-HOMEPAGE="https://ziglang.org/"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
if [[ ${PV} == 9999 ]]; then
EGIT_REPO_URI="https://github.com/ziglang/zig.git"
inherit git-r3
else
VERIFY_SIG_METHOD=minisig
VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
inherit verify-sig
SRC_URI="
https://ziglang.org/download/${PV}/${P}.tar.xz
verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
"
KEYWORDS="~amd64 ~arm ~arm64"
BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
fi
# project itself: MIT
# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
# Files that are unnecessary for cross-compilation are removed by upstream
# and therefore their licenses (if any special) are not included.
# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
# lib/libc/musl: MIT BSD-2
# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
-SLOT="$(ver_cut 1-2)"
-IUSE="doc +llvm"
+SLOT="${ZIG_SLOT}"
+IUSE="doc +llvm test"
+RESTRICT="!test? ( test )"
REQUIRED_USE="
!llvm? ( !doc )
llvm? ( ${LLVM_REQUIRED_USE} )
"
-BUILD_DIR="${S}/build"
+# Used by both cmake and zig-build eclass.
+BUILD_DIR="${WORKDIR}/${P}_build"
# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
# (non-LLVM backends don't require these)
# They are not required "on their own", so please don't add them here.
# You can check https://github.com/ziglang/zig-bootstrap in future, to see
# options that are passed to LLVM CMake building (excluding "static" ofc).
DEPEND="
llvm? (
$(llvm_gen_dep '
sys-devel/clang:${LLVM_SLOT}
sys-devel/lld:${LLVM_SLOT}
sys-devel/llvm:${LLVM_SLOT}[zstd]
')
)
"
-
-RDEPEND="
+BDEPEND+="
+ test? ( !!<sys-apps/sandbox-2.39 )
${DEPEND}
"
-
+RDEPEND="${DEPEND}"
IDEPEND="app-eselect/eselect-zig"
-# see https://github.com/ziglang/zig/issues/3382
-# For now, Zig Build System doesn't support enviromental CFLAGS/LDFLAGS/etc.
-QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+DOCS=("README.md" "doc/build.zig.zon.md")
-RESTRICT="!llvm? ( test )"
+# zig-build does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
# Zig uses self-hosted compiler only
CHECKREQS_MEMORY="4G"
-ctarget_to_zigtarget() {
- # Zig's Target Format: arch-os-abi
- local CTARGET="${CTARGET:-${CHOST}}"
-
- local ZIG_ARCH
- case "${CTARGET%%-*}" in
- i?86) ZIG_ARCH=x86;;
- sparcv9) ZIG_ARCH=sparc64;;
- *) ZIG_ARCH="${CTARGET%%-*}";; # Same as in CHOST
- esac
-
- local ZIG_OS
- case "${CTARGET}" in
- *linux*) ZIG_OS=linux;;
- *apple*) ZIG_OS=macos;;
- esac
-
- local ZIG_ABI
- case "${CTARGET##*-}" in
- gnu) ZIG_ABI=gnu;;
- solaris*) ZIG_OS=solaris ZIG_ABI=none;;
- darwin*) ZIG_ABI=none;;
- *) ZIG_ABI="${CTARGET##*-}";; # Same as in CHOST
- esac
-
- echo "${ZIG_ARCH}-${ZIG_OS}-${ZIG_ABI}"
-}
-
-get_zig_mcpu() {
- local ZIG_DEFAULT_MCPU=native
- tc-is-cross-compiler && ZIG_DEFAULT_MCPU=baseline
- echo "${ZIG_MCPU:-${ZIG_DEFAULT_MCPU}}"
-}
-
-get_zig_target() {
- local ZIG_DEFAULT_TARGET=native
- tc-is-cross-compiler && ZIG_DEFAULT_TARGET="$(ctarget_to_zigtarget)"
- echo "${ZIG_TARGET:-${ZIG_DEFAULT_TARGET}}"
-}
-
pkg_setup() {
- # Useful for debugging and a little bit more deterministic.
- export ZIG_LOCAL_CACHE_DIR="${T}/zig-local-cache"
- export ZIG_GLOBAL_CACHE_DIR="${T}/zig-global-cache"
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig-build_pkg_setup
export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
- use llvm && llvm-r1_pkg_setup
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
check-reqs_pkg_setup
}
-src_configure() {
- if ! use llvm; then
- mkdir -p "${BUILD_DIR}/stage3" || die
- # Currently, Zig without LLVM extensions lacks most optimizations.
- export ZIG_BOOTSTRAP_STAGE3_FLAGS=(
- -Dtarget="$(get_zig_target)"
- -Dcpu="$(get_zig_mcpu)"
- -Doptimize=Debug
- -Dstd-docs=false
- -Dno-langref
- -Denable-llvm=false
- -Dforce-link-libc
- )
- return
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ verify-sig_src_unpack
+ fi
+}
+
+src_prepare() {
+ if use llvm; then
+ cmake_src_prepare
+ else
+ # Sync with zig-build_src_prepare
+ default_src_prepare
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+ # "--system" mode is not used during bootstrap.
fi
- local mycmakeargs=(
- -DZIG_USE_CCACHE=OFF
- -DZIG_SHARED_LLVM=ON
- -DZIG_TARGET_TRIPLE="$(get_zig_target)"
- -DZIG_TARGET_MCPU="$(get_zig_mcpu)"
- -DZIG_USE_LLVM_CONFIG=ON
- -DCMAKE_PREFIX_PATH="$(get_llvm_prefix)"
- -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
- )
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
- cmake_src_configure
+src_configure() {
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET=$(zig-toolchain_get_target ${CBUILD:-${CHOST}})
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
+ )
+ fi
+
+ zig-build_src_configure
+
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET}
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
}
src_compile() {
- # Remove "limit memory usage" flags, it's already verified by
- # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
- # according to CI OOM failures, which are higher than during Gentoo build.
- sed -i -e '/\.max_rss = .*,/d' build.zig || die
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
- if ! use llvm; then
- $(tc-getCC) -o bootstrap bootstrap.c || die "Zig's bootstrap.c compilation failed"
- edob ./bootstrap
- edo ./zig2 build install --prefix "${BUILD_DIR}/stage3/" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- return
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET} CC="${native_cc}" edob ./bootstrap
fi
- cmake_src_compile
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig-build_src_compile --prefix "${BUILD_DIR}/stage3/"
- "${BUILD_DIR}/stage3/bin/zig" env || die "Zig compilation failed"
+ ./stage3/bin/zig env || die "Zig compilation failed"
if use doc; then
- cd "${BUILD_DIR}" || die
- edo ./stage3/bin/zig build std-docs --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
- edo ./stage3/bin/zig build langref --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_compile langref --prefix "${S}/docgen/"
fi
}
src_test() {
cd "${BUILD_DIR}" || die
- local ZIG_TEST_ARGS="-Dstatic-llvm=false -Denable-llvm -Dskip-non-native \
- -Doptimize=ReleaseSafe -Dtarget=$(get_zig_target) -Dcpu=$(get_zig_mcpu)"
- local ZIG_TEST_STEPS=(
- test-fmt test-cases test-behavior test-c-import test-compiler-rt test-universal-libc test-compare-output
- test-standalone test-c-abi test-link test-stack-traces test-cli test-asm-link test-translate-c
- test-run-translated-c test-std
- )
-
- local step
- for step in "${ZIG_TEST_STEPS[@]}" ; do
- edob ./stage3/bin/zig build ${step} ${ZIG_TEST_ARGS}
- done
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_test -Dskip-non-native
}
src_install() {
- local DOCS=( "README.md" "doc/build.zig.zon.md" )
- use doc && local HTML_DOCS=( "docgen/doc/langref.html" "docgen/doc/std" )
+ use doc && local HTML_DOCS=("docgen/doc/langref.html")
- if ! use llvm; then
- DESTDIR="${D}" edo ./zig2 build install --prefix "${ZIG_SYS_INSTALL_DEST}" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- einstalldocs
- else
- cmake_src_install
- fi
+ ZIG_EXE="./zig2" zig-build_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
- cd "${ED}/usr/$(get_libdir)/zig/${PV}/" || die
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
mv lib/zig/ lib2/ || die
rm -rf lib/ || die
mv lib2/ lib/ || die
- dosym -r "/usr/$(get_libdir)/zig/${PV}/bin/zig" "/usr/bin/zig-${PV}"
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
}
pkg_postinst() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
if ! use llvm; then
elog "Currently, Zig built without LLVM support lacks some"
elog "important features such as most optimizations, @cImport, etc."
elog "They are listed under \"Building from Source without LLVM\""
elog "section of the README file from \"/usr/share/doc/${PF}\" ."
- elog "It's recommended to use C backend directly with this stage2 build."
fi
}
pkg_postrm() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (3 preceding siblings ...)
2024-10-25 21:20 ` [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
@ 2024-10-25 21:20 ` Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:20 UTC (permalink / raw
To: gentoo-dev
Now uses "zig-build" eclass.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
sys-fs/ncdu/ncdu-2.6-r1.ebuild | 50 ++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 sys-fs/ncdu/ncdu-2.6-r1.ebuild
diff --git a/sys-fs/ncdu/ncdu-2.6-r1.ebuild b/sys-fs/ncdu/ncdu-2.6-r1.ebuild
new file mode 100644
index 000000000000..6fb3c76328cc
--- /dev/null
+++ b/sys-fs/ncdu/ncdu-2.6-r1.ebuild
@@ -0,0 +1,50 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/yoranheling.asc
+# Upstream states 0.12.x and 0.13.x support,
+# but eclass supports only one slot.
+ZIG_SLOT="0.13"
+inherit verify-sig zig-build
+
+DESCRIPTION="NCurses Disk Usage"
+HOMEPAGE="https://dev.yorhel.nl/ncdu"
+SRC_URI="
+ https://dev.yorhel.nl/download/${P}.tar.gz
+ verify-sig? ( https://dev.yorhel.nl/download/${P}.tar.gz.asc )
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~amd64"
+
+BDEPEND="verify-sig? ( sec-keys/openpgp-keys-yorhel )"
+DEPEND="
+ app-arch/zstd
+ sys-libs/ncurses:=[unicode(+)]
+"
+RDEPEND="${DEPEND}"
+
+DOCS=("README.md" "ChangeLog")
+
+src_unpack() {
+ verify-sig_src_unpack
+}
+
+src_configure() {
+ local my_zbs_args=(
+ -Dpie=true
+ # Upstream recommends this default:
+ --release=fast
+ )
+
+ zig-build_src_configure
+}
+
+src_install() {
+ zig-build_src_install
+
+ doman ncdu.1
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (5 preceding siblings ...)
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
@ 2024-10-25 21:33 ` Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
` (4 more replies)
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
7 siblings, 5 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:33 UTC (permalink / raw
To: gentoo-dev
Hello everyone,
This patch series adds new eclasses for packages that use Zig
toolchain with varying level of integration. Since some projects
or ebuilds use only Zig compiler directly, without touching Zig Build
System, I have decided to split eclasses into 2:
* zig-toolchain.eclass: handles dependency on Zig toolchain and
finds appropriate versions/slots, converts C-style target tuples/triples
to Zig format and sets environment variables to be used in other
eclasses and ebuilds. This eclass is more low-level and intended
to be used by programs and libraries that call "zig" commands directly,
without having build.zig file and using "zig build" command. For example,
authors could use "zig build-exe" and "zig test" directly in Makefile,
or add "zig cc" and compile both C and Zig version of library etc.
In this patchset it is also used by dev-lang/zig to convert targets
during bootstrapping, and other logic is suppressed.
* zig-build.eclass: handles working with "zig build" sub-command and build.zig files.
This eclass is more high-level and for most ebuilds it's the only
one which needs to be inherited. It sets default functions for
ebuild phases, deals with dependencies in package manager, allows
ebuilds and end users to configure used flags, respects multi-threading
and verboseness preferences, has some small support for cross-compilation
and so on.
Github PR and discussion here: https://github.com/gentoo/gentoo/pull/37283 .
I have also wrote small generator for Zig ebuild skeletons here:
https://github.com/BratishkaErik/zig-ebuild . Example output in that PR.
It requires dev-lang/zig:9999 to compile, but at runtime it works
with any version supported by eclass (currently 0.13 and 9999).
In "v2" revision, including suggestions on mailing list:
* Move EAPI check after inherit guard
* Change BDEPEND from "+=" to "=" and remove initial space here,
* Keep length below 80 characters, and add 2 spaces after full stop,
* Align lines in switch cases (according to Neovim, on nano I had
not noticed it before),
* Add "die -n" to ezig(),
* Move and rewrite TODO comments in zig-build_start_base_args to be
shorter and move less relevant information to patch itself.
...and GitHub. Also remove old leftovers of Zig 0.12 compatibility.
Eric Joldasov (5):
zig-toolchain.eclass: new eclass
zig-build.eclass: new eclass
dev-lang/zig: add 0.13.0-r1
dev-lang/zig: sync 9999 with 0.13.0-r1
sys-fs/ncdu: add 2.6-r1
.../zig-0.13.0-skip-test-stack_iterator.patch | 32 +
dev-lang/zig/zig-0.13.0-r1.ebuild | 245 ++++++++
dev-lang/zig/zig-9999.ebuild | 244 ++++----
eclass/zig-build.eclass | 580 ++++++++++++++++++
eclass/zig-toolchain.eclass | 375 +++++++++++
sys-fs/ncdu/ncdu-2.6-r1.ebuild | 50 ++
6 files changed, 1407 insertions(+), 119 deletions(-)
create mode 100644 dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
create mode 100644 dev-lang/zig/zig-0.13.0-r1.ebuild
create mode 100644 eclass/zig-build.eclass
create mode 100644 eclass/zig-toolchain.eclass
create mode 100644 sys-fs/ncdu/ncdu-2.6-r1.ebuild
Interdiff against v1:
diff --git a/eclass/zig-build.eclass b/eclass/zig-build.eclass
index b1fc89e38d9d..ffa075043cde 100644
--- a/eclass/zig-build.eclass
+++ b/eclass/zig-build.eclass
@@ -1,572 +1,580 @@
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: zig-build.eclass
# @MAINTAINER:
# Eric Joldasov <bratishkaerik@landless-city.net>
# @AUTHOR:
# Alfred Wingate <parona@protonmail.com>
# Violet Purcell <vimproved@inventati.org>
# Eric Joldasov <bratishkaerik@landless-city.net>
# @SUPPORTED_EAPIS: 8
# @PROVIDES: zig-toolchain
-# @BLURB: Functions for working with ZBS (Zig Build System).
+# @BLURB: Functions for working with ZBS (Zig Build System)
# @DESCRIPTION:
-# Functions for working with Zig build system and package manager.
-# Supports Zig 0.13+. Exports default functions for convenience.
+# Functions for working with Zig build system and package manager.
+# Supports Zig 0.13+. Exports default functions for convenience.
#
# Note that zig-build.eclass is mostly tailored for projects that:
# 1) Install something in build.zig steps: "artifacts" (executable,
-# libraries, objects), source codes, assets, tests, scripts etc. But many authors
-# also use it to write Zig "modules", build logic and/or bindings/wrappers
-# for C/C++ libraries. They install nothing and are only used at build-time,
-# so it's unneccessary and mostly useless to make ebuilds for them.
-# 2) Have required `target`, `cpu` and optional `optimize` options
-# in build.zig that accept standard Zig-style target and optimize mode.
-# They are usually created by `standardTargetOptions` and `standardOptimizeOption`.
+# libraries, objects), source codes, assets, tests, scripts etc. But
+# many authors also use it to write Zig "modules", build logic
+# and/or bindings/wrappers for C/C++ libraries. They install nothing
+# and are only used at build-time, so it's unneccessary and mostly
+# useless to make ebuilds for them.
+# 2) Have required `target`, `cpu` and optional `optimize` options in
+# build.zig that accept standard Zig-style target and optimize mode.
+# They are usually created by calling `b.standardTargetOptions` and
+# `b.standardOptimizeOption` functions.
#
-# For end-user executables, usually it's recommended to fix calling these options by patch
-# and upstream it, but in some cases they have good reasons
-# to not have this option, f.e. if it is built only for WASM
-# platform with ReleaseSmall, and is not intended to run in your /usr/bin/.
-# In this case, declare dummy options using `standardTargetOptions` and
-# ignore their values, or else eclass wouldn't work.
+# For end-user executables, usually it's recommended to patch to call
+# these options and upstream it, but in some cases authors have good
+# reasons to not have them, f.e. if it is built only for WASM
+# platform with ReleaseSmall, and is not intended to run in /usr/bin/.
+# In this case, declare dummy options using `b.option` and ignore
+# their values, or else eclass wouldn't work.
#
-# Another case is when upstream has `target` option but it is customized
-# and does not accept usual targets, but something specific to the project
-# like "linux-baseline-lts" or combine CPU and target in one option.
-# In this case, it's best to rename that option to something like `target-custom`,
-# then declare `target` option and make converter from one value to other.
+# Another case is when upstream has `target` option but it has
+# custom format and does not accept usual Zig targets, but rather
+# something specific to the project like "linux-baseline-lts", or
+# combine CPU and target in one option.
+# In this case, it's best to rename that option to something like
+# `target-custom`, then declare `target` option and make converter
+# from one value to other.
#
-# For non-executable binaries like C shared/static libraries, objects etc.
-# our policy is stricter, all 3 options are required and should not
-# be ignored, with no exceptions.
+# For non-executable binaries like C libraries, objects etc. our
+# policy is stricter, all 3 options are required and should not
+# be ignored, with no exceptions.
+
+if [[ ! ${_ZIG_BUILD_ECLASS} ]]; then
+_ZIG_BUILD_ECLASS=1
case ${EAPI} in
8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
-if [[ ! ${_ZIG_BUILD_ECLASS} ]]; then
-_ZIG_BUILD_ECLASS=1
-
inherit multiprocessing zig-toolchain
# @ECLASS_VARIABLE: ZIG_OPTIONAL
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION:
-# If set to a non-empty value, all logic in zig-toolchain and zig-build
-# eclasses will be considered optional. No dependencies will be added and
-# no phase functions will be exported.
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
#
# For zig-build.eclass users:
-# You need to add Zig and pkgconfig dependency in your BDEPEND, set QA_FLAGS_IGNORED
-# and call all phase functions manually, or, if you want to call "ezig" directly,
-# at least call "zig-build_pkg_setup" before it.
+# You need to add Zig and pkgconfig dependencies in your BDEPEND, set
+# QA_FLAGS_IGNORED and call all phase functions manually. If you want
+# to use "ezig build" directly, call "zig-build_pkg_setup" before it.
#
-# For zig-toolchain.eclass users: see documentation in zig-toolchain.eclass instead.
+# For zig-toolchain.eclass users: see documentation in
+# zig-toolchain.eclass instead.
if [[ ! ${ZIG_OPTIONAL} ]]; then
- BDEPEND+="virtual/pkgconfig"
+ BDEPEND="virtual/pkgconfig"
# See https://github.com/ziglang/zig/issues/3382
# Zig Build System does not support CFLAGS/LDFLAGS/etc.
QA_FLAGS_IGNORED=".*"
fi
# @ECLASS_VARIABLE: ZBS_DEPENDENCIES
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION:
# Bash associative array with all tarballs that will be fetched by
-# "ezig fetch" in zig-build_src_unpack phase. Value is URL where
+# "ezig fetch" in zig-build_src_unpack phase. Value is URL where
# tarball is located, key is name under which it would be downloaded
-# and renamed. So generally it has effect of "value -> key".
+# and renamed. So generally it has effect of "value -> key".
#
# Note: if Zig Build System dependency can't be represented in SRC_URI
-# (like direct Git commit URIs), you should do the following (zig-ebuilder
-# does archiving automatically for you):
+# (like direct Git commit URIs), you should do the following
+# (zig-ebuilder does archiving automatically for you):
# 1. Archive each folder with dependency content in some tarball,
-# so f.e. if you have 2 Git dependencies, create 2 tarballs.
+# so f.e. if you have 2 Git dependencies, create 2 tarballs.
# 2. Archive all previous tarballs into one combined tarball (also
# called tarball-tarball from now on), no subdirs, so that eclass
# can firstly unpack this tarball with "unpack",
-# and secondly unpack its content with "zig fetch".
+# and secondly unpack its content with "zig fetch".
# 3. (zig-ebuilder can't do this) Host this tarball somewhere
-# and put URL of this tarball in SRC_URI, and archives in ZBS_DEPENDENCIES,
-# keys must be names of archives, leave values empty.
+# and put URL of this tarball in SRC_URI, and archives in
+# ZBS_DEPENDENCIES, keys must be names of archives, values empty.
#
# Example:
# @CODE
# declare -r -A ZBS_DEPENDENCIES=(
# [tarball_a-<long-hash>.tar.gz]='URL_A'
# [tarball_b-<long-hash>.tar.gz]='URL_B'
#
# # If there are Git dependencies:
# [git_c-<long-hash>.tar.gz]=''
# # Tarball-tarball should contain inside above tarball flatly.
# )
# @CODE
# @ECLASS_VARIABLE: ZBS_DEPENDENCIES_SRC_URI
# @OUTPUT_VARIABLE
# @DEFAULT_UNSET
# @DESCRIPTION:
-# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in SRC_URI.
-# Note that elements with empty keys will be skipped.
+# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in
+# SRC_URI. Note that elements with empty keys will be skipped.
# Example:
# @CODE
# SRC_URI="
-# <URL to archive of project sources, patches, other non-Zig resources etc.>
+# <URL to project sources, patches, non-Zig resources etc.>
#
# # If there are Git dependencies:
# # <URL to tarball-tarball>
#
# ${ZBS_DEPENDENCIES_SRC_URI}
# "
# @CODE
# @FUNCTION: _zig-build_set_zbs_uris
# @INTERNAL
# @DESCRIPTION:
-# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
+# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
_zig-build_set_zbs_uris() {
# Thanks to Alfred Wingate "parona" for inspiration here:
# https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
ZBS_DEPENDENCIES_SRC_URI=
for dependency in ${!ZBS_DEPENDENCIES[@]}; do
local uri="${ZBS_DEPENDENCIES[${dependency}]}"
if [[ ${#uri} -gt 0 ]]; then
ZBS_DEPENDENCIES_SRC_URI+=" ${uri} -> ${dependency}"
else
# Unrepresentable dependency
continue
fi
done
}
_zig-build_set_zbs_uris
# @ECLASS_VARIABLE: my_zbs_args
# @DESCRIPTION:
-# Ebuild-specified arguments to pass to the "zig build" after "src_configure".
-# This should be a Bash array. It's appended to the ZBS_ARGS
-# during "src_configure". Note: if you need to override default
-# optimize mode of this eclass (ReleaseSafe) with your default,
-# please use "--release=small" etc. syntax so that user can still
-# override it in ZBS_ARGS_EXTRA.
+# Bash array with ebuild-specified arguments to pass to the
+# "zig build" after "src_configure".
+# It's appended to the ZBS_ARGS during "src_configure". Note: if you
+# need to override default optimize mode of this eclass (ReleaseSafe)
+# with your default, please use "--release=small" etc. syntax so that
+# user can still override it in ZBS_ARGS_EXTRA.
#
# Example:
# @CODE
# src_configure() {
# local my_zbs_args=(
# -Dpie=true
# )
#
# zig-build_src_configure
# }
# @CODE
: "${my_zbs_args:=}"
# @ECLASS_VARIABLE: ZBS_ARGS_EXTRA
# @USER_VARIABLE
# @DESCRIPTION:
-# User-specified arguments to pass to the "zig build" after "src_configure".
-# This is also where amount of jobs for "zig build" is taken from.
-# It's appended to the ZBS_ARGS during "zig-build_src_configure".
+# Bash string with user-specified arguments to pass to the "zig build"
+# after "src_configure".
+# It's appended to the ZBS_ARGS during "zig-build_src_configure".
#
-# If this does not have amount of jobs, eclass will try to take amount of jobs
-# from MAKEOPTS, and if it also does not have them, it will default to $(nproc).
+# If this does not have amount of jobs, eclass will try to take amount
+# of jobs from MAKEOPTS, and if it also does not have them, it will
+# default to $(nproc).
#
# Example:
# @CODE
# -j8 --release=small
# @CODE
: "${ZBS_ARGS_EXTRA:=}"
# @ECLASS_VARIABLE: ZBS_VERBOSE
# @USER_VARIABLE
# @DESCRIPTION:
# If enabled, eclass will add "--summary all --verbose" options to
# "ezig build", so that it prints every command before executing,
-# and summarry tree at the end of step. If not, will do nothing.
-# Enabled by default. Set to OFF to disable these verbose messages.
+# and summarry tree at the end of step. If not, will do nothing.
+# Enabled by default. Set to OFF to disable these verbose messages.
#
-# Note: this variable does not control other options starting with "--verbose-",
-# such as "--verbose-link" or "--verbose-llvm-cpu-features". If you need them,
-# add them manually to ZBS_ARGS_EXTRA.
+# Note: this variable does not control other options starting with
+# "--verbose-", such as "--verbose-link" or "--verbose-cimport". If
+# you need them, add them manually to ZBS_ARGS_EXTRA.
: "${ZBS_VERBOSE:=ON}"
# @ECLASS_VARIABLE: BUILD_DIR
# @DEFAULT_UNSET
# @DESCRIPTION:
-# Directory where all "ezig build" calls will be proceeded.
-# Defaults to "${WORKDIR}/${P}-build" if not set.
+# Directory where all "ezig build" calls will be proceeded.
+# Defaults to "${WORKDIR}/${P}-build" if not set.
: "${BUILD_DIR:=${WORKDIR}/${P}-build}"
# @ECLASS_VARIABLE: ZBS_ECLASS_DIR
# @DESCRIPTION:
-# Directory where various files used by this eclass are stored.
-# They can be supplied by the ebuild or by eclass.
+# Directory where various files used by this eclass are stored.
+# They can be supplied by the ebuild or by eclass.
# Currently, it's used only for Zig packages, which are stored in "p/"
-# subdirectory.
-# Defaults to "${WORKDIR}/zig-eclass" if not set.
-# Should be set before calling "zig-build_src_unpack" or "zig-build_live_fetch".
+# subdirectory.
+# Defaults to "${WORKDIR}/zig-eclass" if not set.
+# Should be set before calling "zig-build_src_unpack" or
+# "zig-build_live_fetch".
: "${ZBS_ECLASS_DIR:=${WORKDIR}/zig-eclass}"
# @FUNCTION: zig-build_get_jobs
# @DESCRIPTION:
-# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
-# If there is none, defaults to number of available processing units.
+# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
+# If there is none, defaults to number of available processing units.
zig-build_get_jobs() {
+ local all_args="${ZBS_ARGS_EXTRA} ${MAKEOPTS}"
local default_jobs="$(get_nproc)"
- local jobs=$(makeopts_jobs "${ZBS_ARGS_EXTRA} ${MAKEOPTS}" "${default_jobs}")
+ local jobs=$(makeopts_jobs "${all_args}" "${default_jobs}")
if [[ ${jobs} == "0" ]]; then
- # Zig build system does not allow jobs count to be less than 1,
- # and does not have option for unlimited parallelism. Pass
- # default number of jobs here.
+ # Zig build system does not allow "-j0", and does not have
+ # option for unlimited parallelism. Pass our default number
+ # of jobs here.
echo "${default_jobs}"
else
echo "${jobs}"
fi
}
# @FUNCTION: zig-build_start_base_args
# @DESCRIPTION:
-# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE,
+# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE.
# Package manager option is managed by "zig-build_src_prepare",
-# ebuild and user options are added by "zig-build_src_configure".
+# ebuild and user options are added by "zig-build_src_configure".
#
# This function is used by "zig-build_pkg_setup", and it is neccessary
# that args are available as early as possible, so that ebuilds
# could use them in steps like "src_unpack" if neccessary, while
-# still having verbosity and amount of jobs from user respected.
+# still having verbosity and amount of jobs from user respected.
+#
+#
+# TODO: currently this function enables "--search-prefix" (1) and
+# "--sysroot" (2) only when cross-compiling, should be fixed to
+# unconditionally enabling it.
+#
+# For solving (1) this patch should be reworked and upstreamed:
+# https://paste.sr.ht/~bratishkaerik/2ddffe2bf0f8f9d6dfb60403c2e9560334edaa88
+#
+# (2)
+# "--sysroot" should be passed together with "--search-prefix" above,
+# if we pass only "--sysroot" it gives these errors:
+# @CODE
+# error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
+# @CODE
zig-build_start_base_args() {
[[ ${ZBS_ARGS_BASE} ]] && return
local crt_dir="${ESYSROOT}/usr/"
if [[ ${ZIG_TARGET} == *musl* ]]; then
crt_dir+="lib/"
else
crt_dir+="$(get_libdir)/"
fi
# 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 create Zig libc installation paths file"
- # Note: they are not prepended by "--sysroot" value, so repeat it here.
+ cat <<- _EOF_ > "${T}/zig_libc.txt"
+ # Note: they are not prepended by "--sysroot" value,
+ # so repeat it here.
include_dir=${ESYSROOT}/usr/include/
sys_include_dir=${ESYSROOT}/usr/include/
crt_dir=${crt_dir}
# Windows with MSVC only.
msvc_lib_dir=
# Windows with MSVC only.
kernel32_lib_dir=
# Haiku only.
gcc_dir=
_EOF_
+ if [[ ${?} -ne 0 ]]; then
+ die "Failed to create Zig libc installation info file"
+ fi
declare -g -a ZBS_ARGS_BASE=(
-j$(zig-build_get_jobs)
--build-file "${S}/build.zig"
-Dtarget=${ZIG_TARGET}
-Dcpu=${ZIG_CPU}
--release=safe
--prefix-exe-dir bin/
--prefix-lib-dir $(get_libdir)/
--prefix-include-dir include/
# Should be relative path to make other calls easier,
# so remove leading slash here.
--prefix "${EPREFIX:+${EPREFIX#/}/}usr/"
--libc "${T}/zig_libc.txt"
)
- [[ "${ZBS_VERBOSE}" != OFF ]] && ZBS_ARGS_BASE+=( --summary all --verbose )
+ if [[ "${ZBS_VERBOSE}" != OFF ]]; then
+ ZBS_ARGS_BASE+=( --summary all --verbose )
+ fi
if tc-is-cross-compiler; then
ZBS_ARGS_BASE+=(
- # TODO add to upstream some way to add different search prefixes
- # for binaries, include paths and libraries, like existing --prefix-exe-dir etc.
- # Right now std.Build.findProgram will try to search here first, before PATH,
- # but std.Build.run and std.Build.runAllowFail use passed arguments as is and
- # uses std.process.Child under the hood, which itself can use PATH.
- #
- # Passing "--search-prefix" when not cross-compiling gives these errors:
- # install
- # └─ install ncdu
- # └─ zig build-exe ncdu ReleaseSafe native 5 errors
- # error: ld.lld: /usr/lib64/Scrt1.o is incompatible with elf32-i386
- # error: ld.lld: /usr/lib64/crti.o is incompatible with elf32-i386
- # error: ld.lld: /var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/local/o/21d4a7d4d6563c46cfe08d129805520f/ncdu.o is incompatible with elf32-i386
- # error: ld.lld: /var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/global/o/15ced1ec04eb7a5fc68f8ee7bed8650c/libcompiler_rt.a(/var/tmp/portage/sys-fs/ncdu-2.6-r1/temp/zig-cache/global/o/15ced1ec04eb7a5fc68f8ee7bed8650c/libcompiler_rt.a.o) is incompatible with elf32-i386
- # error: ld.lld: /usr/lib64/crtn.o is incompatible with elf32-i386
- # error: the following command failed with 5 compilation errors:
- # TODO: enable this unconditionnaly
- # after rewriting https://paste.sr.ht/~bratishkaerik/f68273ccde4e8771413098b302f5ee4961521a09
- # to include TODO above, and upstreaming that patch. I really don't want to make
- # different behaviour for 9999 and 0.13 in this place now.
--search-prefix "${ESYSROOT}/usr/"
-
- # Note: combined with our other options, it's mostly not used by Zig itself, only by lld linker.
- # Without this option, lld thinks we are not cross-compiling
- # and will complain that dynamic linker like "/lib/ld-linux-aarch64.so.1" does not exist.
- #
- # "--sysroot" should be passed together with "--search-prefix" above, else it gives these errors:
- # install
- # └─ install ncdu
- # └─ zig build-exe ncdu ReleaseSafe native failure
- # error: error: unable to find dynamic system library 'ncursesw' using strategy 'paths_first'. searched paths: none
- # error: unable to find dynamic system library 'tinfow' using strategy 'paths_first'. searched paths: none
- # error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
-
- # error: the following command exited with error code 1:
--sysroot "${ESYSROOT}/"
)
fi
}
# @FUNCTION: zig-build_pkg_setup
# @DESCRIPTION:
# Sets up environmental variables for Zig toolchain
-# and basic args for Zig Build System.
+# and basic args for Zig Build System.
zig-build_pkg_setup() {
[[ ${MERGE_TYPE} != binary ]] || return 0
zig-toolchain_populate_env_vars
zig-build_start_base_args
# Used only by 9999 for now, change in upstream did not appear
# in fixed release yet.
export PKG_CONFIG="${PKG_CONFIG:-$(tc-getPKG_CONFIG)}"
mkdir "${T}/zig-cache/" || die
export ZIG_LOCAL_CACHE_DIR="${T}/zig-cache/local/"
export ZIG_GLOBAL_CACHE_DIR="${T}/zig-cache/global/"
}
# @FUNCTION: zig-build_live_fetch
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
+# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
# If you have some lazy dependency which is not triggered in default
# configuration, pass options like you would pass them for regular
-# "ezig build". Try to cover all of them before "src_configure".
+# "ezig build". Try to cover all of them before "src_configure".
# **Note**: this function will be deprecated once/if
-# https://github.com/ziglang/zig/pull/19975 lands.
+# https://github.com/ziglang/zig/pull/19975 lands.
#
# Example:
# @CODE
# src_unpack() {
# # If there are no lazy dependency:
# zig-build_live_fetch
#
# # If there are lazy dependencies that can be triggered together:
# zig-build_live_fetch -Denable-wayland -Denable-xwayland
#
# # If there are 2 lazy dependencies that can't be triggered
# # together in one call because they conflict:
# zig-build_live_fetch -Dmain-backend=opengl
# zig-build_live_fetch -Dmain-backend=vulkan
# }
# @CODE
zig-build_live_fetch() {
- # This function will probably be called before [zig-build_]src_prepare,
- # like in src_unpack, so this directory might not exist yet.
+ # This function will likely be called in src_unpack,
+ # before [zig-build_]src_prepare, so this directory might not
+ # exist yet.
mkdir -p "${BUILD_DIR}" > /dev/null || die
pushd "${BUILD_DIR}" > /dev/null || die
local args=(
- "${ZBS_ARGS_BASE[@]}"
-
- --global-cache-dir "${ZBS_ECLASS_DIR}/"
--fetch
+ "${ZBS_ARGS_BASE[@]}"
+
# Function arguments
"${@}"
)
- einfo "ZBS: attempting to live-fetch dependencies using the following options: ${args[@]}"
- ezig build "${args[@]}" || die "ZBS: fetching dependencies failed"
+ einfo "ZBS: live-fetching with following args: ${args[@]}"
+ ezig build --global-cache-dir "${ZBS_ECLASS_DIR}/" "${args[@]}"
popd > /dev/null || die
}
# @FUNCTION: zig-build_src_unpack
# @DESCRIPTION:
-# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES, in that order.
+# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES,
+# in that order.
zig-build_src_unpack() {
# Thanks to Alfred Wingate "parona" for inspiration here:
# https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
if [[ "${#ZBS_DEPENDENCIES_SRC_URI}" -eq 0 ]]; then
default_src_unpack
return
fi
local zig_deps=()
for dependency in ${!ZBS_DEPENDENCIES[@]}; do
zig_deps+=("${dependency}")
done
# First unpack non-Zig dependencies, so that
# tarball with all Git dependencies tarballs is unpacked early.
for dist in ${A}; do
for zig_dep in "${zig_deps[@]}"; do
if [[ "${dist}" == "${zig_dep}" ]]; then
continue 2
fi
done
unpack "${dist}"
done
# Now unpack all Zig dependencies, including those that are
# now unpacked from tarball-tarball.
for zig_dep in "${zig_deps[@]}"; do
# Hide now-spammy hash from stdout
- ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" "${DISTDIR}/${zig_dep}" > /dev/null
+ ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" \
+ "${DISTDIR}/${zig_dep}" > /dev/null
done
einfo "ZBS: ${#zig_deps[@]} dependencies fetched"
}
# @FUNCTION: zig-build_src_prepare
# @DESCRIPTION:
# Calls default "src_prepare" function, creates BUILD_DIR directory
# and enables or disables system mode (by adding to ZBS_BASE_ARGS),
-# depending on how many packages there are.
+# depending on how many packages there are.
#
-# System mode is toggled here and not in "src_unpack" because
-# they could have been fetched by "live_fetch" in live ebuilds instead.
+# System mode is toggled here and not in "src_unpack" because they
+# could have been fetched by "live_fetch" in live ebuilds instead.
zig-build_src_prepare() {
default_src_prepare
mkdir -p "${BUILD_DIR}" || die
einfo "BUILD_DIR: \"${BUILD_DIR}\""
local system_dir="${ZBS_ECLASS_DIR}/p/"
- # We are using directories count instead of ZBS_DEPENDENCIES.len
- # because author might have fetched packages using live_fetch instead.
+ # We are using directories.len instead of ZBS_DEPENDENCIES.len
+ # because ebuild might have fetched packages using live_fetch
+ # instead.
local -a packages=()
- readarray -d '' -t packages < <(find "${system_dir}" -mindepth 1 -maxdepth 1 -type d -print0 2> /dev/null || echo -n "")
+ readarray -d '' -t packages < <(find "${system_dir}" -mindepth 1 \
+ -maxdepth 1 -type d -print0 2> /dev/null || echo -n "")
local count="${#packages[@]}"
if [[ "${count}" -gt 0 ]]; then
einfo "ZBS: system mode enabled, ${count} packages found"
ZBS_ARGS_BASE+=( --system "${system_dir}" )
else
einfo "ZBS: no packages found, no need to enable system mode"
fi
}
# @FUNCTION: zig-build_src_configure
# @DESCRIPTION:
# Creates ZBS_ARGS array which can be used in all future phases,
# by combining ZBS_ARGS_BASE set previously, my_zbs_args from ebuild,
-# and ZBS_ARGS_EXTRA by user, in this order.
+# and ZBS_ARGS_EXTRA by user, in this order.
#
-# Specific flags currently only add support for the cross-compilation.
-# They are likely to be extended in the future.
+# Specific flags currently only add support for the cross-compilation.
+# They are likely to be extended in the future.
zig-build_src_configure() {
# Handle quoted whitespace.
eval "local -a ZBS_ARGS_EXTRA=( ${ZBS_ARGS_EXTRA} )"
- # Since most arguments in array are also cached by ZBS, we want to
- # reuse array as much as possible, so prevent modification of it.
+ # Since most arguments in array are also cached by ZBS, we
+ # want to reuse array as much as possible, so prevent
+ # modification of it.
declare -g -a -r ZBS_ARGS=(
# Base arguments from pkg_setup/setup_base_args
"${ZBS_ARGS_BASE[@]}"
# Arguments from ebuild
"${my_zbs_args[@]}"
# Arguments from user
"${ZBS_ARGS_EXTRA[@]}"
)
einfo "Configured with:"
einfo "${ZBS_ARGS[@]}"
}
# @FUNCTION: zig-build_src_compile
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Calls "ezig build" with previously set ZBS_ARGS.
-# Args passed to this function will be passed after ZBS_ARGS.
+# Calls "ezig build" with previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
zig-build_src_compile() {
pushd "${BUILD_DIR}" > /dev/null || die
- ezig build "${ZBS_ARGS[@]}" "${@}" || die "ZBS: compilation failed"
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ nonfatal ezig build "${args[@]}" || die "ZBS: compilation failed"
popd > /dev/null || die
}
# @FUNCTION: zig-build_src_test
# @USAGE: [<args>...]
# @DESCRIPTION:
-# If "test" step exist, calls "ezig build test" with previously set ZBS_ARGS.
-# Args passed to this function will be passed after ZBS_ARGS.
+# If "test" step exist, calls "ezig build test" with previously set
+# ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
# Note: currently step detection might give false positives in
-# very rare cases, it will be improved in the future.
+# very rare cases, it will be improved in the future.
zig-build_src_test() {
pushd "${BUILD_DIR}" > /dev/null || die
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+
# UPSTREAM std.testing.tmpDir and a lot of other functions
# do not respect --cache-dir or ZIG_LOCAL_CACHE_DIR:
# https://github.com/ziglang/zig/issues/19874
mkdir -p "zig-cache/" ".zig-cache/" || die
local found_test_step=false
local -a steps
- readarray steps < <(ezig build --list-steps "${ZBS_ARGS[@]}" || die "ZBS: listing steps failed")
+ readarray steps < <(nonfatal ezig build --list-steps "${args[@]}" \
+ || die "ZBS: listing steps failed")
for step in "${steps[@]}"; do
# UPSTREAM Currently, step name can have any characters in it,
- # including whitespaces, so splitting names and
- # descriptions by whitespaces is not enough for some cases.
- # We probably need something like "--list-steps names_only".
+ # including whitespaces, so splitting names and descriptions
+ # by whitespaces is not enough for some cases.
+ # We probably need something like "--list-steps names_only".
# In practice, almost nobody sets such names.
step_name=$(awk '{print $1}' <<< "${step}")
if [[ ${step_name} == test ]]; then
found_test_step=true
break
fi
done
if [[ ${found_test_step} == true ]]; then
- ezig build test "${ZBS_ARGS[@]}" "${@}" || die "ZBS: tests failed"
+ nonfatal ezig build test "${args[@]}" \
+ || die "ZBS: tests failed"
else
einfo "Test step not found, skipping."
fi
popd > /dev/null || die
}
# @FUNCTION: zig-build_src_install
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Calls "ezig build install" with DESTDIR and previously set ZBS_ARGS.
-# Args passed to this function will be passed after ZBS_ARGS.
-# Also installs documentation via "einstalldocs".
+# Calls "ezig build install" with DESTDIR and previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Also installs documentation via "einstalldocs".
zig-build_src_install() {
pushd "${BUILD_DIR}" > /dev/null || die
- DESTDIR="${D}" ezig build install "${ZBS_ARGS[@]}" "${@}" || die "ZBS: installing failed"
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ DESTDIR="${D}" nonfatal ezig build install "${args[@]}" \
+ || die "ZBS: installing failed"
popd > /dev/null || die
pushd "${S}" > /dev/null || die
einstalldocs
popd > /dev/null || die
}
fi
if [[ ! ${ZIG_OPTIONAL} ]]; then
EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install
fi
diff --git a/eclass/zig-toolchain.eclass b/eclass/zig-toolchain.eclass
index 6297c9fc9cdd..42a3f8ec3706 100644
--- a/eclass/zig-toolchain.eclass
+++ b/eclass/zig-toolchain.eclass
@@ -1,336 +1,375 @@
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: zig-toolchain.eclass
# @MAINTAINER:
# Eric Joldasov <bratishkaerik@landless-city.net>
# @AUTHOR:
# Eric Joldasov <bratishkaerik@landless-city.net>
# @SUPPORTED_EAPIS: 8
-# @BLURB: Prepare Zig toolchain and set environment variables.
+# @BLURB: Prepare Zig toolchain and set environment variables
# @DESCRIPTION:
-# Prepare Zig toolchain and set environment variables. Supports Zig 0.13+.
+# Prepare Zig toolchain and set environment variables.
+# Supports Zig 0.13+.
# Does not set any default function, ebuilds must call them manually.
# Generally, only "zig-toolchain_populate_env_vars" is needed.
#
# Intended to be used by ebuilds that call "zig build-exe/lib/obj"
# or "zig test" directly and by "dev-lang/zig".
# For ebuilds with ZBS (Zig Build System), it's usually better
# to inherit zig-build instead, as it has default phases-functions.
+if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
+_ZIG_TOOLCHAIN_ECLASS=1
+
case ${EAPI} in
8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
-if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
-_ZIG_TOOLCHAIN_ECLASS=1
-
inherit edo flag-o-matic
# @ECLASS_VARIABLE: ZIG_SLOT
# @PRE_INHERIT
# @REQUIRED
# @DESCRIPTION:
-# Zig slot that will be used in "ezig" function. Also, if ZIG_OPTIONAL is
-# empty, adds dev-lang/zig and dev-lang/zig-bin dependency to BDEPEND.
-# Must be >= "0.13".
+# Zig slot that will be used in "ezig" function. Also, if
+# ZIG_OPTIONAL is empty, adds dev-lang/zig and dev-lang/zig-bin
+# dependency to BDEPEND. Must be >= "0.13".
#
# Example:
# @CODE
# 0.13
# @CODE
#
# When a new Zig release occurs, it is advisable for maintainers to
-# check whether their ebuild supports that new version. If yes, they
+# check whether their ebuild supports that new version. If yes, they
# they should bump ZIG_SLOT to the latest version; if not supported,
-# they need to patch any issues with new version and again bump ZIG_SLOT.
-# This helps to reduce dependencies on outdated Zig versions.
+# they need to patch any issues with new version and again bump
+# ZIG_SLOT. This helps to reduce dependencies on outdated Zig
+# versions.
#
# This policy of "1 exclusive Zig slot" will work until it
# stabilizes enough (probably near 1.0), then it will be re-evaluated
# and most likely changed to more common in other eclasses ZIG_MIN/
# ZIG_MAX form.
# @ECLASS_VARIABLE: ZIG_OPTIONAL
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION:
-# If set to a non-empty value, all logic in zig-toolchain and zig-build
-# eclasses will be considered optional. No dependencies will be added and
-# no phase functions will be exported.
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
#
# For zig-toolchain.eclass users:
# You have to add Zig dependency in your BDEPEND manually and call
# at least "zig-toolchain_populate_env_vars" before using "ezig".
#
-# For zig-build.eclass users: see documentation in zig-build.eclass instead.
+# For zig-build.eclass users: see documentation in zig-build.eclass
+# instead.
if [[ ! ${ZIG_OPTIONAL} ]]; then
- BDEPEND+=" || (
+ BDEPEND="|| (
dev-lang/zig:${ZIG_SLOT}
dev-lang/zig-bin:${ZIG_SLOT}
)"
fi
# @ECLASS_VARIABLE: ZIG_TARGET
# @DESCRIPTION:
-# Zig target triple to use. Has the following format:
+# Zig target triple to use. Has the following format:
# arch-os[.os_version_range]-abi[.abi_version]
# Can be passed as:
# * "-target " option in "zig test" or "zig build-exe/lib/obj",
-# * "-Dtarget=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
+# * "-Dtarget=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
#
-# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
#
# Example:
# @CODE
-# native # autodetected by Zig
-# x86_64-linux-gnu # Machine running Linux x86_64 system, with glibc
-# x86_64-linux.6.1.12...6.6.16-gnu.2.38 # Similar to above, but versions are passed explicitly
-# powerpc64le-linux-musl # Machine running Linux 64-bit little-endian PowerPC system, with musl
+# # Autodetected by Zig:
+# native
+# # Machine running Linux x86_64 system, with glibc:
+# x86_64-linux-gnu
+# # Similar to above, but versions are passed explicitly:
+# x86_64-linux.6.1.12...6.6.16-gnu.2.38
+# # Machine running Linux PPC64 little-endian system, with musl
+# powerpc64le-linux-musl
# @CODE
#
# @ECLASS_VARIABLE: ZIG_CPU
# @DESCRIPTION:
-# Zig target CPU and features to use. Has the following format:
+# Zig target CPU and features to use. Has the following format:
# family_name(\+enable_feature|\-disable_feature)*
# Can be passed as:
# * "-mcpu " option in "zig test" or "zig build-exe/lib/obj",
-# * "-Dcpu=" option in "zig build" (if project uses "std.Build.standardTargetOptions").
+# * "-Dcpu=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
#
-# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
#
# Example:
# @CODE
-# native # autodetected by Zig
-# znver2 # AMD Zen 2 processor
-# x86_64+x87-sse2" # x86_64 processor, X87 support enabled, SSE2 support disabled
+# # Autodetected by Zig:
+# native
+# # AMD Zen 2 processor
+# znver2
+# # x86_64 processor, X87 support enabled, SSE2 support disabled
+# x86_64+x87-sse2
# @CODE
# @ECLASS_VARIABLE: ZIG_EXE
# @DESCRIPTION:
# Absolute path to the used Zig executable.
#
-# Please note that when passing one flag several times with different values:
-# * to "zig build" in "-Dbar=false -Dbar" form: errors due to conflict of flags,
-# * to "zig build" in "-Dbar=false -Dbar=true" form: "bar" becomes a list, which is likely not what you (or upstream) want,
-# * to "zig test" or "zig build-exe/lib/obj" in "-fbar -fno-bar" form: latest value overwrites values before.
-# Similar situation with other types of options (enums, "std.SemanticVersion", integers, strings, etc.)
+# Please note that when passing one flag several times with different
+# values:
+# * (only "zig build") in "-Dbar=false -Dbar" form:
+# errors due to conflict of flags,
+# * (only "zig build") in "-Dbar=false -Dbar=true" form:
+# "bar" becomes a list, which is likely not what you want,
+# * in "-fbar -fno-bar" form:
+# latest value overwrites values before.
+# Example above shows only boolean option, but it is same with other
+# types of options (enums, "std.zig.BuildId", "std.SemanticVersion",
+# integers, strings, etc.).
#
-# Can be overriden by user. If not overriden, then set by "zig-toolchain_populate_env_vars".
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
# @ECLASS_VARIABLE: ZIG_VER
# @OUTPUT_VARIABLE
# @DESCRIPTION:
-# Zig version found during "zig-toolchain_find_installation", as reported in dev-lang/zig-${PV} PV part.
+# Zig version found during "zig-toolchain_find_installation",
+# as reported in dev-lang/zig-${PV} PV part.
#
# Example:
# @CODE
# 0.13.0
# @CODE
# @FUNCTION: zig-toolchain_get_target
# @USAGE: <C-style target triple>
# @DESCRIPTION:
# Translates C-style target triple (like CHOST or CBUILD)
-# to Zig-style target triple. Some information (like ARM features)
-# is handled by "zig-toolchain_get_cpu". Mostly used during cross-compiling
-# if user does not set ZIG_TARGET variable.
+# to Zig-style target triple. Some information (like ARM features)
+# is handled by "zig-toolchain_get_cpu". Mostly used during
+# cross-compiling if user does not set ZIG_TARGET variable.
#
# See ZIG_TARGET description for more information.
zig-toolchain_get_target() {
- [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
local c_target=${1}
local c_target_prefix=${c_target%%-*}
local c_target_suffix=${c_target##*-}
local arch os abi
case ${c_target_prefix} in
i?86) arch=x86;;
arm64) arch=aarch64;;
arm*) arch=arm;;
- *) arch=${c_target_prefix};;
+ *) arch=${c_target_prefix};;
esac
case ${c_target} in
*linux*) os=linux;;
*apple*) os=macos;;
esac
case ${c_target_suffix} in
solaris*) os=solaris abi=none;;
darwin*) abi=none;;
- *) abi=${c_target_suffix};;
+ *) abi=${c_target_suffix};;
esac
- [[ ${arch} == arm && ${abi} == gnu ]] && die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
+ if [[ ${arch} == arm && ${abi} == gnu ]]; then
+ die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
+ fi
echo ${arch}-${os}-${abi}
}
# @FUNCTION: zig-toolchain_get_cpu
# @USAGE: <C-style target triple>
# @DESCRIPTION:
# Translates C-style target triple (like CHOST or CBUILD)
-# to Zig-style target CPU and features. Mostly used to get generic target CPU
-# during cross-compiling if user does not set ZIG_CPU variable.
+# to Zig-style target CPU and features. Mostly used to get generic
+# target CPU during cross-compiling if user does not set ZIG_CPU
+# variable.
#
# See ZIG_CPU description for more information.
zig-toolchain_get_cpu() {
- [[ ${#} -eq 1 ]] || die "${FUNCNAME[0]}: exactly one argument must be passed"
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
local c_target=${1}
local c_target_prefix=${c_target%%-*}
local base_cpu features=""
case ${c_target_prefix} in
i?86) base_cpu=${c_target_prefix};;
loongarch64) base_cpu=generic_la64;;
powerpc | powerpcle) base_cpu=ppc;;
powerpc64) base_cpu=ppc64;;
powerpc64le) base_cpu=ppc64le;;
riscv32) base_cpu=generic_rv32;;
riscv64) base_cpu=generic_rv64;;
*) base_cpu=generic;;
esac
case ${c_target_prefix} in
armv5tel) features+="+v5te";;
armv*) features+="+${c_target_prefix##armv}";;
esac
case ${c_target_prefix} in
arm64) ;;
arm*)
local is_softfloat=$(CTARGET=${c_target} tc-tuple-is-softfloat)
case ${is_softfloat} in
only | yes) features+="+soft_float";;
softfp | no) features+="-soft_float";;
*) die "${FUNCNAME[0]}: tc-tuple-is-softfloat returned unexpected value"
esac
;;
esac
echo ${base_cpu}${features}
}
# @FUNCTION: zig-toolchain_find_installation
# @DESCRIPTION:
-# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE variables.
+# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE
+# variables.
#
# See ZIG_EXE and ZIG_VER descriptions for more information.
zig-toolchain_find_installation() {
# Adapted from https://github.com/gentoo/gentoo/pull/28986
# Many thanks to Florian Schmaus (Flowdalic)!
[[ -n ${ZIG_SLOT} ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set"
if ver_test "${ZIG_SLOT}" -lt "0.13"; then
die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}"
fi
einfo "Searching Zig ${ZIG_SLOT}..."
local zig_supported_versions=(
"9999"
"0.13.1"
"0.13.0"
)
- local selected_path selected_version
- for selected_version in "${zig_supported_versions[@]}"; do
- # Compare with ZIG_SLOT (like 0.13)
- local candidate_slot=$(ver_cut 1-2 ${selected_version})
+ local base_path="${BROOT}/usr/bin"
+
+ local selected_path selected_ver
+ for selected_ver in "${zig_supported_versions[@]}"; do
+ # Check if candidate satisfies ZIG_SLOT condition.
+ local candidate_slot
+ candidate_slot=$(ver_cut 1-2 ${selected_ver})
if ver_test "${candidate_slot}" -ne ${ZIG_SLOT}; then
- # Candidate does not satisfy ZIG_SLOT condition.
continue
fi
+ local candidate_path
# Prefer "dev-lang/zig" over "dev-lang/zig-bin"
- local candidate_path="${BROOT}/usr/bin/zig-${selected_version}"
+ candidate_path="${base_path}/zig-${selected_ver}"
if [[ -x "${candidate_path}" ]]; then
selected_path="${candidate_path}"
break;
fi
- candidate_path="${BROOT}/usr/bin/zig-bin-${selected_version}"
+ candidate_path="${base_path}/zig-bin-${selected_ver}"
if [[ -x "${candidate_path}" ]]; then
selected_path="${candidate_path}"
break;
fi
done
if [[ -z "${selected_path}" ]]; then
- die "Could not find (suitable) Zig installation in \"${BROOT}/usr/bin/\""
+ die "Could not find (suitable) Zig at \"${base_path}\""
fi
export ZIG_EXE="${selected_path}"
- export ZIG_VER="${selected_version}"
- # Sanity check, from upstream:
- # // Check libc++ linkage to make sure Zig was built correctly, but only
- # // for "env" and "version" to avoid affecting the startup time for
- # // build-critical commands (check takes about ~10 μs)
- "${ZIG_EXE}" version > /dev/null || die "Sanity check failed for \"${ZIG_EXE}\""
+ export ZIG_VER="${selected_ver}"
+ # Sanity check, comment from upstream:
+ # > Check libc++ linkage to make sure Zig was built correctly,
+ # > but only for "env" and "version" to avoid affecting the
+ # > startup time for build-critical commands
+ # > (check takes about ~10 μs)
+ "${ZIG_EXE}" version > /dev/null \
+ || die "Sanity check failed for \"${ZIG_EXE}\""
}
# @FUNCTION: zig-toolchain_populate_env_vars
# @DESCRIPTION:
# Populates ZIG_TARGET, ZIG_CPU, ZIG_EXE and ZIG_VER environment
# variables with detected values, or, if user set them already,
# leaves as-is.
zig-toolchain_populate_env_vars() {
- # Should be first because it sets ZIG_VER which might be used in the future
- # when setting ZIG_TARGET and ZIG_CPU variables for incompatible versions.
+ # Should be first because it sets ZIG_VER which might be used
+ # in the future when setting ZIG_TARGET and ZIG_CPU variables
+ # for incompatible versions.
if [[ -z "${ZIG_EXE}" ]]; then
zig-toolchain_find_installation
fi
if [[ -z ${ZIG_TARGET} ]]; then
if tc-is-cross-compiler; then
export ZIG_TARGET=$(zig-toolchain_get_target ${CHOST})
else
export ZIG_TARGET=native
fi
fi
if [[ -z ${ZIG_CPU} ]]; then
if tc-is-cross-compiler; then
export ZIG_CPU=$(zig-toolchain_get_cpu ${CHOST})
else
export ZIG_CPU=native
fi
fi
einfo "ZIG_EXE: \"${ZIG_EXE}\""
einfo "ZIG_VER: ${ZIG_VER}"
einfo "ZIG_TARGET: ${ZIG_TARGET}"
einfo "ZIG_CPU: ${ZIG_CPU}"
}
# @FUNCTION: ezig
# @USAGE: [<args>...]
# @DESCRIPTION:
-# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set.
+# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set or
+# if command exits with error. Respects `nonfatal`.
#
-# Always disables progress bar (tree in 0.13+).
-# By default enables ANSI escape codes (colours, etc.), set NO_COLOR
-# environment variable to disable them.
+# Always disables progress tree. By default enables ANSI escape codes
+# (colours, etc.), user can set NO_COLOR environment variable to
+# disable them.
ezig() {
- # Sync description above and comments below with "std.io.tty.detectConfig".
- debug-print-function "${FUNCNAME[0]}" "${@}"
+ # Sync description above and comments below with upstream's
+ # "std.io.tty.detectConfig".
+ debug-print-function "${FUNCNAME[0]}" "${@}"
if [[ -z "${ZIG_EXE}" ]] ; then
die "${FUNCNAME[0]}: ZIG_EXE is not set. Was 'zig-toolchain_populate_env_vars' called before using ezig?"
fi
- # Progress bar (tree in newer versions) are helpful indicators in
- # TTY, but unfortunately they make Portage logs harder to read in plaintext.
- # We pass "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE (or YES_COLOR
- # until 0.13) to preserve colors.
+ # Progress tree is helpful indicator in TTY, but unfortunately
+ # they make Portage logs harder to read in plaintext. We pass
+ # "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE to
+ # preserve colors.
# User's NO_COLOR takes precendence over this.
- TERM=dumb YES_COLOR=1 CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}"
+ TERM=dumb CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}" \
+ || die -n "Failed to run command: ${ZIG_EXE} ${@}"
}
fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v2 1/5] zig-toolchain.eclass: new eclass
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
@ 2024-10-25 21:33 ` Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 2/5] zig-build.eclass: " Eric Joldasov
` (3 subsequent siblings)
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:33 UTC (permalink / raw
To: gentoo-dev
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/zig-toolchain.eclass | 375 ++++++++++++++++++++++++++++++++++++
1 file changed, 375 insertions(+)
create mode 100644 eclass/zig-toolchain.eclass
diff --git a/eclass/zig-toolchain.eclass b/eclass/zig-toolchain.eclass
new file mode 100644
index 000000000000..42a3f8ec3706
--- /dev/null
+++ b/eclass/zig-toolchain.eclass
@@ -0,0 +1,375 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig-toolchain.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @BLURB: Prepare Zig toolchain and set environment variables
+# @DESCRIPTION:
+# Prepare Zig toolchain and set environment variables.
+# Supports Zig 0.13+.
+# Does not set any default function, ebuilds must call them manually.
+# Generally, only "zig-toolchain_populate_env_vars" is needed.
+#
+# Intended to be used by ebuilds that call "zig build-exe/lib/obj"
+# or "zig test" directly and by "dev-lang/zig".
+# For ebuilds with ZBS (Zig Build System), it's usually better
+# to inherit zig-build instead, as it has default phases-functions.
+
+if [[ ! ${_ZIG_TOOLCHAIN_ECLASS} ]]; then
+_ZIG_TOOLCHAIN_ECLASS=1
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit edo flag-o-matic
+
+# @ECLASS_VARIABLE: ZIG_SLOT
+# @PRE_INHERIT
+# @REQUIRED
+# @DESCRIPTION:
+# Zig slot that will be used in "ezig" function. Also, if
+# ZIG_OPTIONAL is empty, adds dev-lang/zig and dev-lang/zig-bin
+# dependency to BDEPEND. Must be >= "0.13".
+#
+# Example:
+# @CODE
+# 0.13
+# @CODE
+#
+# When a new Zig release occurs, it is advisable for maintainers to
+# check whether their ebuild supports that new version. If yes, they
+# they should bump ZIG_SLOT to the latest version; if not supported,
+# they need to patch any issues with new version and again bump
+# ZIG_SLOT. This helps to reduce dependencies on outdated Zig
+# versions.
+#
+# This policy of "1 exclusive Zig slot" will work until it
+# stabilizes enough (probably near 1.0), then it will be re-evaluated
+# and most likely changed to more common in other eclasses ZIG_MIN/
+# ZIG_MAX form.
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
+#
+# For zig-toolchain.eclass users:
+# You have to add Zig dependency in your BDEPEND manually and call
+# at least "zig-toolchain_populate_env_vars" before using "ezig".
+#
+# For zig-build.eclass users: see documentation in zig-build.eclass
+# instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND="|| (
+ dev-lang/zig:${ZIG_SLOT}
+ dev-lang/zig-bin:${ZIG_SLOT}
+ )"
+fi
+
+# @ECLASS_VARIABLE: ZIG_TARGET
+# @DESCRIPTION:
+# Zig target triple to use. Has the following format:
+# arch-os[.os_version_range]-abi[.abi_version]
+# Can be passed as:
+# * "-target " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dtarget=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
+#
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
+#
+# Example:
+# @CODE
+# # Autodetected by Zig:
+# native
+# # Machine running Linux x86_64 system, with glibc:
+# x86_64-linux-gnu
+# # Similar to above, but versions are passed explicitly:
+# x86_64-linux.6.1.12...6.6.16-gnu.2.38
+# # Machine running Linux PPC64 little-endian system, with musl
+# powerpc64le-linux-musl
+# @CODE
+#
+
+# @ECLASS_VARIABLE: ZIG_CPU
+# @DESCRIPTION:
+# Zig target CPU and features to use. Has the following format:
+# family_name(\+enable_feature|\-disable_feature)*
+# Can be passed as:
+# * "-mcpu " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dcpu=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
+#
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
+#
+# Example:
+# @CODE
+# # Autodetected by Zig:
+# native
+# # AMD Zen 2 processor
+# znver2
+# # x86_64 processor, X87 support enabled, SSE2 support disabled
+# x86_64+x87-sse2
+# @CODE
+
+# @ECLASS_VARIABLE: ZIG_EXE
+# @DESCRIPTION:
+# Absolute path to the used Zig executable.
+#
+# Please note that when passing one flag several times with different
+# values:
+# * (only "zig build") in "-Dbar=false -Dbar" form:
+# errors due to conflict of flags,
+# * (only "zig build") in "-Dbar=false -Dbar=true" form:
+# "bar" becomes a list, which is likely not what you want,
+# * in "-fbar -fno-bar" form:
+# latest value overwrites values before.
+# Example above shows only boolean option, but it is same with other
+# types of options (enums, "std.zig.BuildId", "std.SemanticVersion",
+# integers, strings, etc.).
+#
+# Can be overriden by user. If not overriden, then set by
+# "zig-toolchain_populate_env_vars".
+
+# @ECLASS_VARIABLE: ZIG_VER
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Zig version found during "zig-toolchain_find_installation",
+# as reported in dev-lang/zig-${PV} PV part.
+#
+# Example:
+# @CODE
+# 0.13.0
+# @CODE
+
+# @FUNCTION: zig-toolchain_get_target
+# @USAGE: <C-style target triple>
+# @DESCRIPTION:
+# Translates C-style target triple (like CHOST or CBUILD)
+# to Zig-style target triple. Some information (like ARM features)
+# is handled by "zig-toolchain_get_cpu". Mostly used during
+# cross-compiling if user does not set ZIG_TARGET variable.
+#
+# See ZIG_TARGET description for more information.
+zig-toolchain_get_target() {
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
+ local c_target=${1}
+ local c_target_prefix=${c_target%%-*}
+ local c_target_suffix=${c_target##*-}
+
+ local arch os abi
+
+ case ${c_target_prefix} in
+ i?86) arch=x86;;
+ arm64) arch=aarch64;;
+ arm*) arch=arm;;
+ *) arch=${c_target_prefix};;
+ esac
+
+ case ${c_target} in
+ *linux*) os=linux;;
+ *apple*) os=macos;;
+ esac
+
+ case ${c_target_suffix} in
+ solaris*) os=solaris abi=none;;
+ darwin*) abi=none;;
+ *) abi=${c_target_suffix};;
+ esac
+
+ if [[ ${arch} == arm && ${abi} == gnu ]]; then
+ die "${FUNCNAME[0]}: Zig does not support old ARM ABI"
+ fi
+
+ echo ${arch}-${os}-${abi}
+}
+
+
+
+# @FUNCTION: zig-toolchain_get_cpu
+# @USAGE: <C-style target triple>
+# @DESCRIPTION:
+# Translates C-style target triple (like CHOST or CBUILD)
+# to Zig-style target CPU and features. Mostly used to get generic
+# target CPU during cross-compiling if user does not set ZIG_CPU
+# variable.
+#
+# See ZIG_CPU description for more information.
+zig-toolchain_get_cpu() {
+ if [[ ${#} -ne 1 ]]; then
+ die "${FUNCNAME[0]}: expected 1 arguments, got ${#}"
+ fi
+ local c_target=${1}
+ local c_target_prefix=${c_target%%-*}
+
+ local base_cpu features=""
+
+ case ${c_target_prefix} in
+ i?86) base_cpu=${c_target_prefix};;
+ loongarch64) base_cpu=generic_la64;;
+ powerpc | powerpcle) base_cpu=ppc;;
+ powerpc64) base_cpu=ppc64;;
+ powerpc64le) base_cpu=ppc64le;;
+ riscv32) base_cpu=generic_rv32;;
+ riscv64) base_cpu=generic_rv64;;
+ *) base_cpu=generic;;
+ esac
+
+ case ${c_target_prefix} in
+ armv5tel) features+="+v5te";;
+ armv*) features+="+${c_target_prefix##armv}";;
+ esac
+
+ case ${c_target_prefix} in
+ arm64) ;;
+ arm*)
+ local is_softfloat=$(CTARGET=${c_target} tc-tuple-is-softfloat)
+ case ${is_softfloat} in
+ only | yes) features+="+soft_float";;
+ softfp | no) features+="-soft_float";;
+ *) die "${FUNCNAME[0]}: tc-tuple-is-softfloat returned unexpected value"
+ esac
+ ;;
+ esac
+
+ echo ${base_cpu}${features}
+}
+
+# @FUNCTION: zig-toolchain_find_installation
+# @DESCRIPTION:
+# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE
+# variables.
+#
+# See ZIG_EXE and ZIG_VER descriptions for more information.
+zig-toolchain_find_installation() {
+ # Adapted from https://github.com/gentoo/gentoo/pull/28986
+ # Many thanks to Florian Schmaus (Flowdalic)!
+
+ [[ -n ${ZIG_SLOT} ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set"
+ if ver_test "${ZIG_SLOT}" -lt "0.13"; then
+ die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}"
+ fi
+
+ einfo "Searching Zig ${ZIG_SLOT}..."
+
+ local zig_supported_versions=(
+ "9999"
+ "0.13.1"
+ "0.13.0"
+ )
+
+ local base_path="${BROOT}/usr/bin"
+
+ local selected_path selected_ver
+ for selected_ver in "${zig_supported_versions[@]}"; do
+ # Check if candidate satisfies ZIG_SLOT condition.
+ local candidate_slot
+ candidate_slot=$(ver_cut 1-2 ${selected_ver})
+ if ver_test "${candidate_slot}" -ne ${ZIG_SLOT}; then
+ continue
+ fi
+
+ local candidate_path
+ # Prefer "dev-lang/zig" over "dev-lang/zig-bin"
+ candidate_path="${base_path}/zig-${selected_ver}"
+ if [[ -x "${candidate_path}" ]]; then
+ selected_path="${candidate_path}"
+ break;
+ fi
+
+ candidate_path="${base_path}/zig-bin-${selected_ver}"
+ if [[ -x "${candidate_path}" ]]; then
+ selected_path="${candidate_path}"
+ break;
+ fi
+ done
+
+ if [[ -z "${selected_path}" ]]; then
+ die "Could not find (suitable) Zig at \"${base_path}\""
+ fi
+
+ export ZIG_EXE="${selected_path}"
+ export ZIG_VER="${selected_ver}"
+ # Sanity check, comment from upstream:
+ # > Check libc++ linkage to make sure Zig was built correctly,
+ # > but only for "env" and "version" to avoid affecting the
+ # > startup time for build-critical commands
+ # > (check takes about ~10 μs)
+ "${ZIG_EXE}" version > /dev/null \
+ || die "Sanity check failed for \"${ZIG_EXE}\""
+}
+
+# @FUNCTION: zig-toolchain_populate_env_vars
+# @DESCRIPTION:
+# Populates ZIG_TARGET, ZIG_CPU, ZIG_EXE and ZIG_VER environment
+# variables with detected values, or, if user set them already,
+# leaves as-is.
+zig-toolchain_populate_env_vars() {
+ # Should be first because it sets ZIG_VER which might be used
+ # in the future when setting ZIG_TARGET and ZIG_CPU variables
+ # for incompatible versions.
+ if [[ -z "${ZIG_EXE}" ]]; then
+ zig-toolchain_find_installation
+ fi
+
+ if [[ -z ${ZIG_TARGET} ]]; then
+ if tc-is-cross-compiler; then
+ export ZIG_TARGET=$(zig-toolchain_get_target ${CHOST})
+ else
+ export ZIG_TARGET=native
+ fi
+ fi
+
+ if [[ -z ${ZIG_CPU} ]]; then
+ if tc-is-cross-compiler; then
+ export ZIG_CPU=$(zig-toolchain_get_cpu ${CHOST})
+ else
+ export ZIG_CPU=native
+ fi
+ fi
+
+ einfo "ZIG_EXE: \"${ZIG_EXE}\""
+ einfo "ZIG_VER: ${ZIG_VER}"
+ einfo "ZIG_TARGET: ${ZIG_TARGET}"
+ einfo "ZIG_CPU: ${ZIG_CPU}"
+}
+
+# @FUNCTION: ezig
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set or
+# if command exits with error. Respects `nonfatal`.
+#
+# Always disables progress tree. By default enables ANSI escape codes
+# (colours, etc.), user can set NO_COLOR environment variable to
+# disable them.
+ezig() {
+ # Sync description above and comments below with upstream's
+ # "std.io.tty.detectConfig".
+ debug-print-function "${FUNCNAME[0]}" "${@}"
+
+ if [[ -z "${ZIG_EXE}" ]] ; then
+ die "${FUNCNAME[0]}: ZIG_EXE is not set. Was 'zig-toolchain_populate_env_vars' called before using ezig?"
+ fi
+
+ # Progress tree is helpful indicator in TTY, but unfortunately
+ # they make Portage logs harder to read in plaintext. We pass
+ # "TERM=dumb" here to have clean logs, and CLICOLOR_FORCE to
+ # preserve colors.
+ # User's NO_COLOR takes precendence over this.
+ TERM=dumb CLICOLOR_FORCE=1 "${ZIG_EXE}" "${@}" \
+ || die -n "Failed to run command: ${ZIG_EXE} ${@}"
+}
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v2 2/5] zig-build.eclass: new eclass
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
@ 2024-10-25 21:33 ` Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
` (2 subsequent siblings)
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:33 UTC (permalink / raw
To: gentoo-dev
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/zig-build.eclass | 580 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 580 insertions(+)
create mode 100644 eclass/zig-build.eclass
diff --git a/eclass/zig-build.eclass b/eclass/zig-build.eclass
new file mode 100644
index 000000000000..ffa075043cde
--- /dev/null
+++ b/eclass/zig-build.eclass
@@ -0,0 +1,580 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig-build.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Alfred Wingate <parona@protonmail.com>
+# Violet Purcell <vimproved@inventati.org>
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: zig-toolchain
+# @BLURB: Functions for working with ZBS (Zig Build System)
+# @DESCRIPTION:
+# Functions for working with Zig build system and package manager.
+# Supports Zig 0.13+. Exports default functions for convenience.
+#
+# Note that zig-build.eclass is mostly tailored for projects that:
+# 1) Install something in build.zig steps: "artifacts" (executable,
+# libraries, objects), source codes, assets, tests, scripts etc. But
+# many authors also use it to write Zig "modules", build logic
+# and/or bindings/wrappers for C/C++ libraries. They install nothing
+# and are only used at build-time, so it's unneccessary and mostly
+# useless to make ebuilds for them.
+# 2) Have required `target`, `cpu` and optional `optimize` options in
+# build.zig that accept standard Zig-style target and optimize mode.
+# They are usually created by calling `b.standardTargetOptions` and
+# `b.standardOptimizeOption` functions.
+#
+# For end-user executables, usually it's recommended to patch to call
+# these options and upstream it, but in some cases authors have good
+# reasons to not have them, f.e. if it is built only for WASM
+# platform with ReleaseSmall, and is not intended to run in /usr/bin/.
+# In this case, declare dummy options using `b.option` and ignore
+# their values, or else eclass wouldn't work.
+#
+# Another case is when upstream has `target` option but it has
+# custom format and does not accept usual Zig targets, but rather
+# something specific to the project like "linux-baseline-lts", or
+# combine CPU and target in one option.
+# In this case, it's best to rename that option to something like
+# `target-custom`, then declare `target` option and make converter
+# from one value to other.
+#
+# For non-executable binaries like C libraries, objects etc. our
+# policy is stricter, all 3 options are required and should not
+# be ignored, with no exceptions.
+
+if [[ ! ${_ZIG_BUILD_ECLASS} ]]; then
+_ZIG_BUILD_ECLASS=1
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit multiprocessing zig-toolchain
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-toolchain and
+# zig-build eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
+#
+# For zig-build.eclass users:
+# You need to add Zig and pkgconfig dependencies in your BDEPEND, set
+# QA_FLAGS_IGNORED and call all phase functions manually. If you want
+# to use "ezig build" directly, call "zig-build_pkg_setup" before it.
+#
+# For zig-toolchain.eclass users: see documentation in
+# zig-toolchain.eclass instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND="virtual/pkgconfig"
+
+ # See https://github.com/ziglang/zig/issues/3382
+ # Zig Build System does not support CFLAGS/LDFLAGS/etc.
+ QA_FLAGS_IGNORED=".*"
+fi
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Bash associative array with all tarballs that will be fetched by
+# "ezig fetch" in zig-build_src_unpack phase. Value is URL where
+# tarball is located, key is name under which it would be downloaded
+# and renamed. So generally it has effect of "value -> key".
+#
+# Note: if Zig Build System dependency can't be represented in SRC_URI
+# (like direct Git commit URIs), you should do the following
+# (zig-ebuilder does archiving automatically for you):
+# 1. Archive each folder with dependency content in some tarball,
+# so f.e. if you have 2 Git dependencies, create 2 tarballs.
+# 2. Archive all previous tarballs into one combined tarball (also
+# called tarball-tarball from now on), no subdirs, so that eclass
+# can firstly unpack this tarball with "unpack",
+# and secondly unpack its content with "zig fetch".
+# 3. (zig-ebuilder can't do this) Host this tarball somewhere
+# and put URL of this tarball in SRC_URI, and archives in
+# ZBS_DEPENDENCIES, keys must be names of archives, values empty.
+#
+# Example:
+# @CODE
+# declare -r -A ZBS_DEPENDENCIES=(
+# [tarball_a-<long-hash>.tar.gz]='URL_A'
+# [tarball_b-<long-hash>.tar.gz]='URL_B'
+#
+# # If there are Git dependencies:
+# [git_c-<long-hash>.tar.gz]=''
+# # Tarball-tarball should contain inside above tarball flatly.
+# )
+# @CODE
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES_SRC_URI
+# @OUTPUT_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in
+# SRC_URI. Note that elements with empty keys will be skipped.
+# Example:
+# @CODE
+# SRC_URI="
+# <URL to project sources, patches, non-Zig resources etc.>
+#
+# # If there are Git dependencies:
+# # <URL to tarball-tarball>
+#
+# ${ZBS_DEPENDENCIES_SRC_URI}
+# "
+# @CODE
+
+# @FUNCTION: _zig-build_set_zbs_uris
+# @INTERNAL
+# @DESCRIPTION:
+# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
+_zig-build_set_zbs_uris() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ ZBS_DEPENDENCIES_SRC_URI=
+
+ for dependency in ${!ZBS_DEPENDENCIES[@]}; do
+ local uri="${ZBS_DEPENDENCIES[${dependency}]}"
+ if [[ ${#uri} -gt 0 ]]; then
+ ZBS_DEPENDENCIES_SRC_URI+=" ${uri} -> ${dependency}"
+ else
+ # Unrepresentable dependency
+ continue
+ fi
+ done
+}
+_zig-build_set_zbs_uris
+
+# @ECLASS_VARIABLE: my_zbs_args
+# @DESCRIPTION:
+# Bash array with ebuild-specified arguments to pass to the
+# "zig build" after "src_configure".
+# It's appended to the ZBS_ARGS during "src_configure". Note: if you
+# need to override default optimize mode of this eclass (ReleaseSafe)
+# with your default, please use "--release=small" etc. syntax so that
+# user can still override it in ZBS_ARGS_EXTRA.
+#
+# Example:
+# @CODE
+# src_configure() {
+# local my_zbs_args=(
+# -Dpie=true
+# )
+#
+# zig-build_src_configure
+# }
+# @CODE
+: "${my_zbs_args:=}"
+
+# @ECLASS_VARIABLE: ZBS_ARGS_EXTRA
+# @USER_VARIABLE
+# @DESCRIPTION:
+# Bash string with user-specified arguments to pass to the "zig build"
+# after "src_configure".
+# It's appended to the ZBS_ARGS during "zig-build_src_configure".
+#
+# If this does not have amount of jobs, eclass will try to take amount
+# of jobs from MAKEOPTS, and if it also does not have them, it will
+# default to $(nproc).
+#
+# Example:
+# @CODE
+# -j8 --release=small
+# @CODE
+: "${ZBS_ARGS_EXTRA:=}"
+
+# @ECLASS_VARIABLE: ZBS_VERBOSE
+# @USER_VARIABLE
+# @DESCRIPTION:
+# If enabled, eclass will add "--summary all --verbose" options to
+# "ezig build", so that it prints every command before executing,
+# and summarry tree at the end of step. If not, will do nothing.
+# Enabled by default. Set to OFF to disable these verbose messages.
+#
+# Note: this variable does not control other options starting with
+# "--verbose-", such as "--verbose-link" or "--verbose-cimport". If
+# you need them, add them manually to ZBS_ARGS_EXTRA.
+: "${ZBS_VERBOSE:=ON}"
+
+# @ECLASS_VARIABLE: BUILD_DIR
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Directory where all "ezig build" calls will be proceeded.
+# Defaults to "${WORKDIR}/${P}-build" if not set.
+: "${BUILD_DIR:=${WORKDIR}/${P}-build}"
+
+# @ECLASS_VARIABLE: ZBS_ECLASS_DIR
+# @DESCRIPTION:
+# Directory where various files used by this eclass are stored.
+# They can be supplied by the ebuild or by eclass.
+# Currently, it's used only for Zig packages, which are stored in "p/"
+# subdirectory.
+# Defaults to "${WORKDIR}/zig-eclass" if not set.
+# Should be set before calling "zig-build_src_unpack" or
+# "zig-build_live_fetch".
+: "${ZBS_ECLASS_DIR:=${WORKDIR}/zig-eclass}"
+
+# @FUNCTION: zig-build_get_jobs
+# @DESCRIPTION:
+# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
+# If there is none, defaults to number of available processing units.
+zig-build_get_jobs() {
+ local all_args="${ZBS_ARGS_EXTRA} ${MAKEOPTS}"
+ local default_jobs="$(get_nproc)"
+ local jobs=$(makeopts_jobs "${all_args}" "${default_jobs}")
+
+ if [[ ${jobs} == "0" ]]; then
+ # Zig build system does not allow "-j0", and does not have
+ # option for unlimited parallelism. Pass our default number
+ # of jobs here.
+ echo "${default_jobs}"
+ else
+ echo "${jobs}"
+ fi
+}
+
+# @FUNCTION: zig-build_start_base_args
+# @DESCRIPTION:
+# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE.
+# Package manager option is managed by "zig-build_src_prepare",
+# ebuild and user options are added by "zig-build_src_configure".
+#
+# This function is used by "zig-build_pkg_setup", and it is neccessary
+# that args are available as early as possible, so that ebuilds
+# could use them in steps like "src_unpack" if neccessary, while
+# still having verbosity and amount of jobs from user respected.
+#
+#
+# TODO: currently this function enables "--search-prefix" (1) and
+# "--sysroot" (2) only when cross-compiling, should be fixed to
+# unconditionally enabling it.
+#
+# For solving (1) this patch should be reworked and upstreamed:
+# https://paste.sr.ht/~bratishkaerik/2ddffe2bf0f8f9d6dfb60403c2e9560334edaa88
+#
+# (2)
+# "--sysroot" should be passed together with "--search-prefix" above,
+# if we pass only "--sysroot" it gives these errors:
+# @CODE
+# error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
+# @CODE
+zig-build_start_base_args() {
+ [[ ${ZBS_ARGS_BASE} ]] && return
+
+ local crt_dir="${ESYSROOT}/usr/"
+ if [[ ${ZIG_TARGET} == *musl* ]]; then
+ crt_dir+="lib/"
+ else
+ crt_dir+="$(get_libdir)/"
+ fi
+
+ # 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"
+ # Note: they are not prepended by "--sysroot" value,
+ # so repeat it here.
+ include_dir=${ESYSROOT}/usr/include/
+ sys_include_dir=${ESYSROOT}/usr/include/
+ crt_dir=${crt_dir}
+ # Windows with MSVC only.
+ msvc_lib_dir=
+ # Windows with MSVC only.
+ kernel32_lib_dir=
+ # Haiku only.
+ gcc_dir=
+ _EOF_
+ if [[ ${?} -ne 0 ]]; then
+ die "Failed to create Zig libc installation info file"
+ fi
+
+ declare -g -a ZBS_ARGS_BASE=(
+ -j$(zig-build_get_jobs)
+ --build-file "${S}/build.zig"
+
+ -Dtarget=${ZIG_TARGET}
+ -Dcpu=${ZIG_CPU}
+ --release=safe
+
+ --prefix-exe-dir bin/
+ --prefix-lib-dir $(get_libdir)/
+ --prefix-include-dir include/
+
+ # Should be relative path to make other calls easier,
+ # so remove leading slash here.
+ --prefix "${EPREFIX:+${EPREFIX#/}/}usr/"
+
+ --libc "${T}/zig_libc.txt"
+ )
+ if [[ "${ZBS_VERBOSE}" != OFF ]]; then
+ ZBS_ARGS_BASE+=( --summary all --verbose )
+ fi
+
+ if tc-is-cross-compiler; then
+ ZBS_ARGS_BASE+=(
+ --search-prefix "${ESYSROOT}/usr/"
+ --sysroot "${ESYSROOT}/"
+ )
+ fi
+}
+
+# @FUNCTION: zig-build_pkg_setup
+# @DESCRIPTION:
+# Sets up environmental variables for Zig toolchain
+# and basic args for Zig Build System.
+zig-build_pkg_setup() {
+ [[ ${MERGE_TYPE} != binary ]] || return 0
+
+ zig-toolchain_populate_env_vars
+ zig-build_start_base_args
+
+ # Used only by 9999 for now, change in upstream did not appear
+ # in fixed release yet.
+ export PKG_CONFIG="${PKG_CONFIG:-$(tc-getPKG_CONFIG)}"
+
+ mkdir "${T}/zig-cache/" || die
+ export ZIG_LOCAL_CACHE_DIR="${T}/zig-cache/local/"
+ export ZIG_GLOBAL_CACHE_DIR="${T}/zig-cache/global/"
+}
+
+# @FUNCTION: zig-build_live_fetch
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
+# If you have some lazy dependency which is not triggered in default
+# configuration, pass options like you would pass them for regular
+# "ezig build". Try to cover all of them before "src_configure".
+# **Note**: this function will be deprecated once/if
+# https://github.com/ziglang/zig/pull/19975 lands.
+#
+# Example:
+# @CODE
+# src_unpack() {
+# # If there are no lazy dependency:
+# zig-build_live_fetch
+#
+# # If there are lazy dependencies that can be triggered together:
+# zig-build_live_fetch -Denable-wayland -Denable-xwayland
+#
+# # If there are 2 lazy dependencies that can't be triggered
+# # together in one call because they conflict:
+# zig-build_live_fetch -Dmain-backend=opengl
+# zig-build_live_fetch -Dmain-backend=vulkan
+# }
+# @CODE
+zig-build_live_fetch() {
+ # This function will likely be called in src_unpack,
+ # before [zig-build_]src_prepare, so this directory might not
+ # exist yet.
+ mkdir -p "${BUILD_DIR}" > /dev/null || die
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=(
+ --fetch
+
+ "${ZBS_ARGS_BASE[@]}"
+
+ # Function arguments
+ "${@}"
+ )
+
+ einfo "ZBS: live-fetching with following args: ${args[@]}"
+ ezig build --global-cache-dir "${ZBS_ECLASS_DIR}/" "${args[@]}"
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_unpack
+# @DESCRIPTION:
+# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES,
+# in that order.
+zig-build_src_unpack() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ if [[ "${#ZBS_DEPENDENCIES_SRC_URI}" -eq 0 ]]; then
+ default_src_unpack
+ return
+ fi
+
+ local zig_deps=()
+ for dependency in ${!ZBS_DEPENDENCIES[@]}; do
+ zig_deps+=("${dependency}")
+ done
+ # First unpack non-Zig dependencies, so that
+ # tarball with all Git dependencies tarballs is unpacked early.
+ for dist in ${A}; do
+ for zig_dep in "${zig_deps[@]}"; do
+ if [[ "${dist}" == "${zig_dep}" ]]; then
+ continue 2
+ fi
+ done
+
+ unpack "${dist}"
+ done
+
+ # Now unpack all Zig dependencies, including those that are
+ # now unpacked from tarball-tarball.
+ for zig_dep in "${zig_deps[@]}"; do
+ # Hide now-spammy hash from stdout
+ ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" \
+ "${DISTDIR}/${zig_dep}" > /dev/null
+ done
+ einfo "ZBS: ${#zig_deps[@]} dependencies fetched"
+}
+
+# @FUNCTION: zig-build_src_prepare
+# @DESCRIPTION:
+# Calls default "src_prepare" function, creates BUILD_DIR directory
+# and enables or disables system mode (by adding to ZBS_BASE_ARGS),
+# depending on how many packages there are.
+#
+# System mode is toggled here and not in "src_unpack" because they
+# could have been fetched by "live_fetch" in live ebuilds instead.
+zig-build_src_prepare() {
+ default_src_prepare
+
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+
+ local system_dir="${ZBS_ECLASS_DIR}/p/"
+
+ # We are using directories.len instead of ZBS_DEPENDENCIES.len
+ # because ebuild might have fetched packages using live_fetch
+ # instead.
+ local -a packages=()
+ readarray -d '' -t packages < <(find "${system_dir}" -mindepth 1 \
+ -maxdepth 1 -type d -print0 2> /dev/null || echo -n "")
+ local count="${#packages[@]}"
+
+ if [[ "${count}" -gt 0 ]]; then
+ einfo "ZBS: system mode enabled, ${count} packages found"
+ ZBS_ARGS_BASE+=( --system "${system_dir}" )
+ else
+ einfo "ZBS: no packages found, no need to enable system mode"
+ fi
+}
+
+# @FUNCTION: zig-build_src_configure
+# @DESCRIPTION:
+# Creates ZBS_ARGS array which can be used in all future phases,
+# by combining ZBS_ARGS_BASE set previously, my_zbs_args from ebuild,
+# and ZBS_ARGS_EXTRA by user, in this order.
+#
+# Specific flags currently only add support for the cross-compilation.
+# They are likely to be extended in the future.
+zig-build_src_configure() {
+ # Handle quoted whitespace.
+ eval "local -a ZBS_ARGS_EXTRA=( ${ZBS_ARGS_EXTRA} )"
+
+ # Since most arguments in array are also cached by ZBS, we
+ # want to reuse array as much as possible, so prevent
+ # modification of it.
+ declare -g -a -r ZBS_ARGS=(
+ # Base arguments from pkg_setup/setup_base_args
+ "${ZBS_ARGS_BASE[@]}"
+
+ # Arguments from ebuild
+ "${my_zbs_args[@]}"
+
+ # Arguments from user
+ "${ZBS_ARGS_EXTRA[@]}"
+ )
+
+ einfo "Configured with:"
+ einfo "${ZBS_ARGS[@]}"
+}
+
+# @FUNCTION: zig-build_src_compile
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build" with previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+zig-build_src_compile() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ nonfatal ezig build "${args[@]}" || die "ZBS: compilation failed"
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_test
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# If "test" step exist, calls "ezig build test" with previously set
+# ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Note: currently step detection might give false positives in
+# very rare cases, it will be improved in the future.
+zig-build_src_test() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+
+ # UPSTREAM std.testing.tmpDir and a lot of other functions
+ # do not respect --cache-dir or ZIG_LOCAL_CACHE_DIR:
+ # https://github.com/ziglang/zig/issues/19874
+ mkdir -p "zig-cache/" ".zig-cache/" || die
+
+ local found_test_step=false
+
+ local -a steps
+ readarray steps < <(nonfatal ezig build --list-steps "${args[@]}" \
+ || die "ZBS: listing steps failed")
+
+ for step in "${steps[@]}"; do
+ # UPSTREAM Currently, step name can have any characters in it,
+ # including whitespaces, so splitting names and descriptions
+ # by whitespaces is not enough for some cases.
+ # We probably need something like "--list-steps names_only".
+ # In practice, almost nobody sets such names.
+ step_name=$(awk '{print $1}' <<< "${step}")
+ if [[ ${step_name} == test ]]; then
+ found_test_step=true
+ break
+ fi
+ done
+
+ if [[ ${found_test_step} == true ]]; then
+ nonfatal ezig build test "${args[@]}" \
+ || die "ZBS: tests failed"
+ else
+ einfo "Test step not found, skipping."
+ fi
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig-build_src_install
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build install" with DESTDIR and previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Also installs documentation via "einstalldocs".
+zig-build_src_install() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ DESTDIR="${D}" nonfatal ezig build install "${args[@]}" \
+ || die "ZBS: installing failed"
+ popd > /dev/null || die
+
+ pushd "${S}" > /dev/null || die
+ einstalldocs
+ popd > /dev/null || die
+}
+
+fi
+
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v2 3/5] dev-lang/zig: add 0.13.0-r1
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 2/5] zig-build.eclass: " Eric Joldasov
@ 2024-10-25 21:33 ` Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:33 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use llvm-r1 eclass instead of llvm, zig-build and
zig-toolchain functions instead of local get_zig_mcpu etc. functions.
* Port "llvm USE-flag" and "removing memory limit flags" from 9999
ebuild.
* Stage3 compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig-build.eclass with common options.
* Before migrating to the zig-build.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we use
upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in src_test is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-toolchain functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-toolchain.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with "zig std" command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
.../zig-0.13.0-skip-test-stack_iterator.patch | 32 +++
dev-lang/zig/zig-0.13.0-r1.ebuild | 245 ++++++++++++++++++
2 files changed, 277 insertions(+)
create mode 100644 dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
create mode 100644 dev-lang/zig/zig-0.13.0-r1.ebuild
diff --git a/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
new file mode 100644
index 000000000000..e088af2102ed
--- /dev/null
+++ b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
@@ -0,0 +1,32 @@
+From: Eric Joldasov <bratishkaerik@landless-city.net>
+
+Skip standalone test "stack_iterator" that fail on Gentoo Linux x86_64.
+Fails in ReleaseSafe, ReleaseFast and ReleaseSmall, but not in Debug.
+Reported to upstream here https://github.com/ziglang/zig/issues/19944 .
+
+Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
+
+diff --git a/test/standalone/stack_iterator/shared_lib_unwind.zig b/test/standalone/stack_iterator/shared_lib_unwind.zig
+index 57513a49c6..75fddb04c9 100644
+--- a/test/standalone/stack_iterator/shared_lib_unwind.zig
++++ b/test/standalone/stack_iterator/shared_lib_unwind.zig
+@@ -35,6 +35,7 @@ extern fn frame0(
+ ) void;
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
+diff --git a/test/standalone/stack_iterator/unwind.zig b/test/standalone/stack_iterator/unwind.zig
+index 69c463a0c1..40963af63d 100644
+--- a/test/standalone/stack_iterator/unwind.zig
++++ b/test/standalone/stack_iterator/unwind.zig
+@@ -87,6 +87,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {
+ }
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
diff --git a/dev-lang/zig/zig-0.13.0-r1.ebuild b/dev-lang/zig/zig-0.13.0-r1.ebuild
new file mode 100644
index 000000000000..5cca5e3efad6
--- /dev/null
+++ b/dev-lang/zig/zig-0.13.0-r1.ebuild
@@ -0,0 +1,245 @@
+# Copyright 2019-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+LLVM_COMPAT=( 18 )
+LLVM_OPTIONAL=1
+
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig-build
+
+DESCRIPTION="A robust, optimal, and maintainable programming language"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
+if [[ ${PV} == 9999 ]]; then
+ EGIT_REPO_URI="https://github.com/ziglang/zig.git"
+ inherit git-r3
+else
+ VERIFY_SIG_METHOD=minisig
+ VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
+ inherit verify-sig
+
+ SRC_URI="
+ https://ziglang.org/download/${PV}/${P}.tar.xz
+ verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
+ "
+ KEYWORDS="~amd64 ~arm ~arm64"
+
+ BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
+fi
+
+# project itself: MIT
+# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
+# Files that are unnecessary for cross-compilation are removed by upstream
+# and therefore their licenses (if any special) are not included.
+# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
+# lib/libc/musl: MIT BSD-2
+# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
+# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
+LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
+SLOT="${ZIG_SLOT}"
+IUSE="doc +llvm test"
+RESTRICT="!test? ( test )"
+REQUIRED_USE="
+ !llvm? ( !doc )
+ llvm? ( ${LLVM_REQUIRED_USE} )
+"
+
+# Used by both cmake and zig-build eclass.
+BUILD_DIR="${WORKDIR}/${P}_build"
+
+# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
+# (non-LLVM backends don't require these)
+# They are not required "on their own", so please don't add them here.
+# You can check https://github.com/ziglang/zig-bootstrap in future, to see
+# options that are passed to LLVM CMake building (excluding "static" ofc).
+DEPEND="
+ llvm? (
+ $(llvm_gen_dep '
+ sys-devel/clang:${LLVM_SLOT}
+ sys-devel/lld:${LLVM_SLOT}
+ sys-devel/llvm:${LLVM_SLOT}[zstd]
+ ')
+ )
+"
+BDEPEND+="
+ test? ( !!<sys-apps/sandbox-2.39 )
+ ${DEPEND}
+"
+RDEPEND="${DEPEND}"
+IDEPEND="app-eselect/eselect-zig"
+
+DOCS=("README.md" "doc/build.zig.zon.md")
+
+PATCHES=(
+ "${FILESDIR}/zig-0.13.0-test-std-kernel-version.patch"
+ "${FILESDIR}/zig-0.13.0-skip-test-stack_iterator.patch"
+)
+
+# zig-build does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+
+# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
+# Zig uses self-hosted compiler only
+CHECKREQS_MEMORY="4G"
+
+pkg_setup() {
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig-build_pkg_setup
+
+ export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
+
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
+ check-reqs_pkg_setup
+}
+
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ verify-sig_src_unpack
+ fi
+}
+
+src_prepare() {
+ if use llvm; then
+ cmake_src_prepare
+ else
+ # Sync with zig-build_src_prepare
+ default_src_prepare
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+ # "--system" mode is not used during bootstrap.
+ fi
+
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
+
+src_configure() {
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET=$(zig-toolchain_get_target ${CBUILD:-${CHOST}})
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
+ )
+ fi
+
+ zig-build_src_configure
+
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET}
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
+}
+
+src_compile() {
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
+
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET} CC="${native_cc}" edob ./bootstrap
+ fi
+
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig-build_src_compile --prefix "${BUILD_DIR}/stage3/"
+
+ ./stage3/bin/zig env || die "Zig compilation failed"
+
+ if use doc; then
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_compile langref --prefix "${S}/docgen/"
+ fi
+}
+
+src_test() {
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_test -Dskip-non-native
+}
+
+src_install() {
+ use doc && local HTML_DOCS=("docgen/doc/langref.html")
+
+ ZIG_EXE="./zig2" zig-build_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
+
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
+ mv lib/zig/ lib2/ || die
+ rm -rf lib/ || die
+ mv lib2/ lib/ || die
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
+}
+
+pkg_postinst() {
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
+
+ if ! use llvm; then
+ elog "Currently, Zig built without LLVM support lacks some"
+ elog "important features such as most optimizations, @cImport, etc."
+ elog "They are listed under \"Building from Source without LLVM\""
+ elog "section of the README file from \"/usr/share/doc/${PF}\" ."
+ fi
+}
+
+pkg_postrm() {
+ eselect zig update ifunset || die
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v2 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (2 preceding siblings ...)
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
@ 2024-10-25 21:33 ` Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:33 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use zig-build and zig-toolchain functions instead of
local get_zig_mcpu etc. functions.
* Port "sys-apps/sandbox-2.39" test dependency requirement from
0.13.0 ebuild.
* Stage3 compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig-build.eclass with common options.
* Before migrating to the zig-build.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we use
upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in src_test is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-toolchain functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-toolchain.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with "zig std" command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
dev-lang/zig/zig-9999.ebuild | 244 ++++++++++++++++++-----------------
1 file changed, 125 insertions(+), 119 deletions(-)
diff --git a/dev-lang/zig/zig-9999.ebuild b/dev-lang/zig/zig-9999.ebuild
index 335ac0eab28c..65650ac5c781 100644
--- a/dev-lang/zig/zig-9999.ebuild
+++ b/dev-lang/zig/zig-9999.ebuild
@@ -1,234 +1,240 @@
# Copyright 2019-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
LLVM_COMPAT=( 19 )
LLVM_OPTIONAL=1
-inherit check-reqs cmake edo llvm-r1 toolchain-funcs
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig-build
DESCRIPTION="A robust, optimal, and maintainable programming language"
-HOMEPAGE="https://ziglang.org/"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
if [[ ${PV} == 9999 ]]; then
EGIT_REPO_URI="https://github.com/ziglang/zig.git"
inherit git-r3
else
VERIFY_SIG_METHOD=minisig
VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
inherit verify-sig
SRC_URI="
https://ziglang.org/download/${PV}/${P}.tar.xz
verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
"
KEYWORDS="~amd64 ~arm ~arm64"
BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
fi
# project itself: MIT
# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
# Files that are unnecessary for cross-compilation are removed by upstream
# and therefore their licenses (if any special) are not included.
# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
# lib/libc/musl: MIT BSD-2
# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
-SLOT="$(ver_cut 1-2)"
-IUSE="doc +llvm"
+SLOT="${ZIG_SLOT}"
+IUSE="doc +llvm test"
+RESTRICT="!test? ( test )"
REQUIRED_USE="
!llvm? ( !doc )
llvm? ( ${LLVM_REQUIRED_USE} )
"
-BUILD_DIR="${S}/build"
+# Used by both cmake and zig-build eclass.
+BUILD_DIR="${WORKDIR}/${P}_build"
# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
# (non-LLVM backends don't require these)
# They are not required "on their own", so please don't add them here.
# You can check https://github.com/ziglang/zig-bootstrap in future, to see
# options that are passed to LLVM CMake building (excluding "static" ofc).
DEPEND="
llvm? (
$(llvm_gen_dep '
sys-devel/clang:${LLVM_SLOT}
sys-devel/lld:${LLVM_SLOT}
sys-devel/llvm:${LLVM_SLOT}[zstd]
')
)
"
-
-RDEPEND="
+BDEPEND+="
+ test? ( !!<sys-apps/sandbox-2.39 )
${DEPEND}
"
-
+RDEPEND="${DEPEND}"
IDEPEND="app-eselect/eselect-zig"
-# see https://github.com/ziglang/zig/issues/3382
-# For now, Zig Build System doesn't support enviromental CFLAGS/LDFLAGS/etc.
-QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+DOCS=("README.md" "doc/build.zig.zon.md")
-RESTRICT="!llvm? ( test )"
+# zig-build does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
# Zig uses self-hosted compiler only
CHECKREQS_MEMORY="4G"
-ctarget_to_zigtarget() {
- # Zig's Target Format: arch-os-abi
- local CTARGET="${CTARGET:-${CHOST}}"
-
- local ZIG_ARCH
- case "${CTARGET%%-*}" in
- i?86) ZIG_ARCH=x86;;
- sparcv9) ZIG_ARCH=sparc64;;
- *) ZIG_ARCH="${CTARGET%%-*}";; # Same as in CHOST
- esac
-
- local ZIG_OS
- case "${CTARGET}" in
- *linux*) ZIG_OS=linux;;
- *apple*) ZIG_OS=macos;;
- esac
-
- local ZIG_ABI
- case "${CTARGET##*-}" in
- gnu) ZIG_ABI=gnu;;
- solaris*) ZIG_OS=solaris ZIG_ABI=none;;
- darwin*) ZIG_ABI=none;;
- *) ZIG_ABI="${CTARGET##*-}";; # Same as in CHOST
- esac
-
- echo "${ZIG_ARCH}-${ZIG_OS}-${ZIG_ABI}"
-}
-
-get_zig_mcpu() {
- local ZIG_DEFAULT_MCPU=native
- tc-is-cross-compiler && ZIG_DEFAULT_MCPU=baseline
- echo "${ZIG_MCPU:-${ZIG_DEFAULT_MCPU}}"
-}
-
-get_zig_target() {
- local ZIG_DEFAULT_TARGET=native
- tc-is-cross-compiler && ZIG_DEFAULT_TARGET="$(ctarget_to_zigtarget)"
- echo "${ZIG_TARGET:-${ZIG_DEFAULT_TARGET}}"
-}
-
pkg_setup() {
- # Useful for debugging and a little bit more deterministic.
- export ZIG_LOCAL_CACHE_DIR="${T}/zig-local-cache"
- export ZIG_GLOBAL_CACHE_DIR="${T}/zig-global-cache"
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig-build_pkg_setup
export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
- use llvm && llvm-r1_pkg_setup
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
check-reqs_pkg_setup
}
-src_configure() {
- if ! use llvm; then
- mkdir -p "${BUILD_DIR}/stage3" || die
- # Currently, Zig without LLVM extensions lacks most optimizations.
- export ZIG_BOOTSTRAP_STAGE3_FLAGS=(
- -Dtarget="$(get_zig_target)"
- -Dcpu="$(get_zig_mcpu)"
- -Doptimize=Debug
- -Dstd-docs=false
- -Dno-langref
- -Denable-llvm=false
- -Dforce-link-libc
- )
- return
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ verify-sig_src_unpack
+ fi
+}
+
+src_prepare() {
+ if use llvm; then
+ cmake_src_prepare
+ else
+ # Sync with zig-build_src_prepare
+ default_src_prepare
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+ # "--system" mode is not used during bootstrap.
fi
- local mycmakeargs=(
- -DZIG_USE_CCACHE=OFF
- -DZIG_SHARED_LLVM=ON
- -DZIG_TARGET_TRIPLE="$(get_zig_target)"
- -DZIG_TARGET_MCPU="$(get_zig_mcpu)"
- -DZIG_USE_LLVM_CONFIG=ON
- -DCMAKE_PREFIX_PATH="$(get_llvm_prefix)"
- -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
- )
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
- cmake_src_configure
+src_configure() {
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET=$(zig-toolchain_get_target ${CBUILD:-${CHOST}})
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
+ )
+ fi
+
+ zig-build_src_configure
+
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET}
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
}
src_compile() {
- # Remove "limit memory usage" flags, it's already verified by
- # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
- # according to CI OOM failures, which are higher than during Gentoo build.
- sed -i -e '/\.max_rss = .*,/d' build.zig || die
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
- if ! use llvm; then
- $(tc-getCC) -o bootstrap bootstrap.c || die "Zig's bootstrap.c compilation failed"
- edob ./bootstrap
- edo ./zig2 build install --prefix "${BUILD_DIR}/stage3/" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- return
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE=${ZIG_HOST_AS_TARGET} CC="${native_cc}" edob ./bootstrap
fi
- cmake_src_compile
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig-build_src_compile --prefix "${BUILD_DIR}/stage3/"
- "${BUILD_DIR}/stage3/bin/zig" env || die "Zig compilation failed"
+ ./stage3/bin/zig env || die "Zig compilation failed"
if use doc; then
- cd "${BUILD_DIR}" || die
- edo ./stage3/bin/zig build std-docs --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
- edo ./stage3/bin/zig build langref --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_compile langref --prefix "${S}/docgen/"
fi
}
src_test() {
cd "${BUILD_DIR}" || die
- local ZIG_TEST_ARGS="-Dstatic-llvm=false -Denable-llvm -Dskip-non-native \
- -Doptimize=ReleaseSafe -Dtarget=$(get_zig_target) -Dcpu=$(get_zig_mcpu)"
- local ZIG_TEST_STEPS=(
- test-fmt test-cases test-behavior test-c-import test-compiler-rt test-universal-libc test-compare-output
- test-standalone test-c-abi test-link test-stack-traces test-cli test-asm-link test-translate-c
- test-run-translated-c test-std
- )
-
- local step
- for step in "${ZIG_TEST_STEPS[@]}" ; do
- edob ./stage3/bin/zig build ${step} ${ZIG_TEST_ARGS}
- done
+ ZIG_EXE="./stage3/bin/zig" zig-build_src_test -Dskip-non-native
}
src_install() {
- local DOCS=( "README.md" "doc/build.zig.zon.md" )
- use doc && local HTML_DOCS=( "docgen/doc/langref.html" "docgen/doc/std" )
+ use doc && local HTML_DOCS=("docgen/doc/langref.html")
- if ! use llvm; then
- DESTDIR="${D}" edo ./zig2 build install --prefix "${ZIG_SYS_INSTALL_DEST}" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- einstalldocs
- else
- cmake_src_install
- fi
+ ZIG_EXE="./zig2" zig-build_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
- cd "${ED}/usr/$(get_libdir)/zig/${PV}/" || die
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
mv lib/zig/ lib2/ || die
rm -rf lib/ || die
mv lib2/ lib/ || die
- dosym -r "/usr/$(get_libdir)/zig/${PV}/bin/zig" "/usr/bin/zig-${PV}"
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
}
pkg_postinst() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
if ! use llvm; then
elog "Currently, Zig built without LLVM support lacks some"
elog "important features such as most optimizations, @cImport, etc."
elog "They are listed under \"Building from Source without LLVM\""
elog "section of the README file from \"/usr/share/doc/${PF}\" ."
- elog "It's recommended to use C backend directly with this stage2 build."
fi
}
pkg_postrm() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v2 5/5] sys-fs/ncdu: add 2.6-r1
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (3 preceding siblings ...)
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
@ 2024-10-25 21:33 ` Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-10-25 21:33 UTC (permalink / raw
To: gentoo-dev
Now uses "zig-build" eclass.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
sys-fs/ncdu/ncdu-2.6-r1.ebuild | 50 ++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 sys-fs/ncdu/ncdu-2.6-r1.ebuild
diff --git a/sys-fs/ncdu/ncdu-2.6-r1.ebuild b/sys-fs/ncdu/ncdu-2.6-r1.ebuild
new file mode 100644
index 000000000000..6fb3c76328cc
--- /dev/null
+++ b/sys-fs/ncdu/ncdu-2.6-r1.ebuild
@@ -0,0 +1,50 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/yoranheling.asc
+# Upstream states 0.12.x and 0.13.x support,
+# but eclass supports only one slot.
+ZIG_SLOT="0.13"
+inherit verify-sig zig-build
+
+DESCRIPTION="NCurses Disk Usage"
+HOMEPAGE="https://dev.yorhel.nl/ncdu"
+SRC_URI="
+ https://dev.yorhel.nl/download/${P}.tar.gz
+ verify-sig? ( https://dev.yorhel.nl/download/${P}.tar.gz.asc )
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~amd64"
+
+BDEPEND="verify-sig? ( sec-keys/openpgp-keys-yorhel )"
+DEPEND="
+ app-arch/zstd
+ sys-libs/ncurses:=[unicode(+)]
+"
+RDEPEND="${DEPEND}"
+
+DOCS=("README.md" "ChangeLog")
+
+src_unpack() {
+ verify-sig_src_unpack
+}
+
+src_configure() {
+ local my_zbs_args=(
+ -Dpie=true
+ # Upstream recommends this default:
+ --release=fast
+ )
+
+ zig-build_src_configure
+}
+
+src_install() {
+ zig-build_src_install
+
+ doman ncdu.1
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
` (6 preceding siblings ...)
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
@ 2024-12-13 20:07 ` Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 1/5] zig-utils.eclass: new eclass Eric Joldasov
` (4 more replies)
7 siblings, 5 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-12-13 20:07 UTC (permalink / raw
To: gentoo-dev
Hello everyone,
This patch series adds 2 new eclasses for better integration with the
Zig toolchain and rewrites ebuilds in `::gentoo` repository to use them.
The `zig-utils.eclass` is designed for other eclasses and ebuilds that
directly call `zig` command (like `zig.eclass` which runs `zig build`,
or some packages in wild that have `zig build-exe` in their Makefiles
or something similar). It is fairly low-level compared to `zig.eclass`,
so for most Zig projects ebuild authors shoud use latter instead.
The `zig.eclass` works with `build.zig` system, called ZBS here to
highlight distinction between it and `zig build-exe` command or other
build systems with Zig support. It manages dependencies integration for
official package manager and options configuration system (some basic
options with sane defaults that can be combined with additional
options from ebuild authors and users) and makes packaging more
convenient by automatically exporting required dependencies and phase
functions.
This is 3-rd version, with changes requested on GitHub PR.
Big thanks to Michał Górny and Sam James for their review comments there.
I won't attach interdiff here (it's unreadable IMHO, mostly because of
renamings), so instead I wrote small overview:
* Eclasses renamed: `zig-toolchain` to `zig-utils`, `zig-build` to `zig`.
Some functions are also renamed, for example `init_base_args` to `setup`.
* Target and CPU convertion functions now accept 2-nd required
argument with `CFLAGS`-like value, for more precise convertion and
needed by new `ZIG_CPU` logic. CPU convertion logic was added for
more arches. Both functions are now also covered by tests (can
optionally compile and run Zig code with resulting target and CPU).
* `ZIG_CPU` now defaults to "value converted from CHOST and CFLAGS
rather" than `native`, to be more consistent with existing policies
and other ecosystems.
* `src_install` does not change CWD when using `einstalldocs` anymore.
* Other functions were rewritten for simplicity or readability without
significant changes in behaviour (maybe I forgot some changes).
Eric Joldasov (5):
zig-utils.eclass: new eclass
zig.eclass: new eclass
dev-lang/zig: add 0.13.0-r2
dev-lang/zig: sync 9999 with 0.13.0-r2
sys-fs/ncdu: add 2.7-r1
....13.0-skip-test-stack_iterator.patch (new) | 32 +
dev-lang/zig/zig-0.13.0-r2.ebuild (new) | 248 ++++++++
dev-lang/zig/zig-9999.ebuild | 243 ++++----
eclass/tests/zig-utils.sh (new +x) | 320 ++++++++++
eclass/zig-utils.eclass (new) | 538 +++++++++++++++++
eclass/zig.eclass (new) | 558 ++++++++++++++++++
sys-fs/ncdu/ncdu-2.7-r1.ebuild (new) | 52 ++
7 files changed, 1873 insertions(+), 118 deletions(-)
create mode 100644 dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
create mode 100644 dev-lang/zig/zig-0.13.0-r2.ebuild
create mode 100755 eclass/tests/zig-utils.sh
create mode 100644 eclass/zig-utils.eclass
create mode 100644 eclass/zig.eclass
create mode 100644 sys-fs/ncdu/ncdu-2.7-r1.ebuild
--
2.47.0
^ permalink raw reply [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v3 1/5] zig-utils.eclass: new eclass
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
@ 2024-12-13 20:07 ` Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 2/5] zig.eclass: " Eric Joldasov
` (3 subsequent siblings)
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-12-13 20:07 UTC (permalink / raw
To: gentoo-dev
This eclass handles dependency on Zig toolchain and finds appropriate
versions/slots, converts "CHOST-style and CFLAGS" to "Zig target tuple
and CPU" formats and sets environment variables to be used by other
eclasses and ebuilds.
Most of the projects written in Zig use `build.zig` system and should
use `zig.eclass` from next commit instead. This eclass is more
low-level and can be used when `zig` commands are called from other
build systems directly. For example, when authors use `zig build-exe`
or `zig test` commands in their Makefile/meson.build/Cargo etc.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/tests/zig-utils.sh (new +x) | 320 +++++++++++++++++
eclass/zig-utils.eclass (new) | 538 +++++++++++++++++++++++++++++
2 files changed, 858 insertions(+)
diff --git a/eclass/tests/zig-utils.sh b/eclass/tests/zig-utils.sh
new file mode 100755
index 000000000000..14af1d2105e3
--- /dev/null
+++ b/eclass/tests/zig-utils.sh
@@ -0,0 +1,320 @@
+#!/bin/bash
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+source tests-common.sh || exit
+
+inherit zig-utils
+
+# Set ZIG_TEST_COMPILATION env-var to "1" if you want to test binary
+# compilation and running under QEMU. Assumes "zig" is present in PATH
+# and qemu binfmt is enabled.
+#
+# If CPU is marked with ":no-run", it means program compiled for it
+# successfully but crashed when running under QEMU.
+if [[ "${ZIG_TEST_COMPILATION:-0}" -eq 1 ]]; then
+ MY_WORKDIR="$(mktemp -d)"
+ my_cleanup() {
+ popd > /dev/null
+ rm -rf "${MY_WORKDIR}"
+ }
+ trap 'my_cleanup' EXIT
+
+ pushd "${MY_WORKDIR}" > /dev/null || die
+ cat <<- _EOF_ > main.zig || die
+ const std = @import("std");
+
+ pub fn main() !void {
+ const stdout = std.io.getStdOut();
+ try stdout.writeAll("Hello, Gentoo!\n");
+ }
+ _EOF_
+
+ zig_test_compile_and_run() {
+ eindent
+ einfo "${1}: ${2}"
+ eoutdent
+
+ if [[ "${2}" == native* ]]; then
+ return 0
+ fi
+
+ if [[ "${1}" == arm* ]]; then
+ # Bunch of unimplemented Zig
+ # routines for more "bare-bone" arm.
+ case "${2}" in
+ # Some errors in inline assembly, likely too low baseline
+ generic-soft_float | generic+soft_float) return 0;;
+ # undefined symbol: __sync_fetch_and_add_1
+ # compiler-rt not implemented in upstream for it yet:
+ # https://github.com/ziglang/zig/issues/4959
+ generic+v5te-soft_float) return 0;;
+ *) ;;
+ esac
+ fi
+
+ local ret=0
+
+ local args=(
+ -target "${1}"
+ -mcpu "${2//:no-run/}"
+ main.zig
+ )
+ if ! zig build-exe "${args[@]}" > /dev/null; then
+ eerror "Failed to compile for: ${1}, ${2}"
+ ((++ret))
+ return ${ret}
+ fi
+
+ # Can't run macOS binaries in Linux user-mode QEMU emulators
+ if [[ "${1}" == *macos* || "${2}" == *":no-run" ]]; then
+ return ${ret}
+ fi
+
+ if ! ./main > /dev/null; then
+ eerror "Failed to run for: ${1}, ${2}"
+ ((++ret))
+ fi
+
+ return ${ret}
+ }
+else
+ zig_test_compile_and_run() { :; }
+fi
+
+test-convert_c_env_to_zig_tuple() {
+ local ret=0
+
+ local -n map=${1}
+
+ local c_tuple
+ for key in "${!map[@]}"; do
+ local expected="${map["${key}"]}"
+
+ local c_tuple
+ local c_flags
+ if [[ "${key}" == *:* ]]; then
+ c_tuple="${key%%:*}"
+ c_flags="${key##*:}"
+ else
+ c_tuple="${key}"
+ c_flags=""
+ fi
+
+ local actual="$(zig-utils_c_env_to_zig_target "${c_tuple}" "${c_flags}")"
+ if [[ "${expected}" != "${actual}" ]]; then
+ eerror "Translating ${c_tuple}: expected ${expected}, found ${actual}"
+ ((++ret))
+ continue
+ fi
+
+ local zig_cpu="$(zig-utils_c_env_to_zig_cpu "${c_tuple}" "${c_flags}")"
+ if ! zig_test_compile_and_run "${expected}" "${zig_cpu}"; then
+ ((++ret))
+ continue
+ fi
+ done
+
+ return ${ret}
+}
+
+test-convert_c_env_to_zig_cpu() {
+ local ret=0
+
+ local -n map=${1}
+ local chost=${2}
+
+ local c_flags
+ for c_flags in "${!map[@]}"; do
+ local expected="${map["${c_flags}"]}"
+ local actual="$(zig-utils_c_env_to_zig_cpu "${chost}" "${c_flags}")"
+ if [[ "${expected//:no-run/}" != "${actual}" ]]; then
+ eerror "Translating ${c_flags}: expected ${expected//:no-run/}, found ${actual}"
+ ((++ret))
+ continue
+ fi
+
+ local zig_target="$(zig-utils_c_env_to_zig_target "${chost}" "${c_flags}")"
+ if ! zig_test_compile_and_run "${zig_target}" "${expected}"; then
+ ((++ret))
+ continue
+ fi
+ done
+
+ return ${ret}
+}
+
+tbegin '"C tuple to Zig tuple"'
+declare -A c_to_zig_map=(
+ # Just remove "vendor" field
+ [aarch64-unknown-linux-gnu]=aarch64-linux-gnu
+ [arm-unknown-linux-musleabi]=arm-linux-musleabi
+ [x86_64-pc-linux-gnu]=x86_64-linux-gnu
+ [loongarch64-unknown-linux-gnu]=loongarch64-linux-gnu
+ [powerpc64le-unknown-linux-gnu]=powerpc64le-linux-gnu
+
+ # ARM big-endian
+ [armeb-unknown-linux-gnueabi]=armeb-linux-gnueabi
+
+ # https://bugs.gentoo.org/924920
+ [armv7a-unknown-linux-gnueabihf]=arm-linux-gnueabihf
+
+ # ARM to Thumb
+ [arm-unknown-linux-musleabi:"-march=armv7e-m"]=thumb-linux-musleabi
+
+ # ARM families
+ [armv6j-unknown-linux-gnueabihf]=arm-linux-gnueabihf
+ [armv6j-linux-gnueabihf]=arm-linux-gnueabihf
+ [armv7a-softfp-linux-gnueabi]=arm-linux-gnueabi
+ [armv7a-linux-gnueabi]=arm-linux-gnueabi
+
+ # X86 (32-bit) families
+ [i486-pc-linux-gnu]=x86-linux-gnu
+ [i686-linux-gnu]=x86-linux-gnu
+
+ # MacOS
+ [x86_64-apple-darwin15]=x86_64-macos-none
+ [arm64-apple-darwin24]=aarch64-macos-none
+)
+test-convert_c_env_to_zig_tuple c_to_zig_map
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for ARM"'
+CHOST="armv7a-unknown-linux-musleabihf"
+c_to_zig_map=(
+ [" "]="generic-soft_float"
+ ["-mcpu=native"]="native-soft_float"
+ ["-mcpu=cortex-a9"]="cortex_a9-soft_float"
+
+ ["-mcpu=cortex-a9 -march=iwmmxt2"]="cortex_a9+iwmmxt2-soft_float"
+
+ ["-march=armv7e-m"]="generic+v7em-soft_float"
+ ["-march=armv5te"]="generic+v5te-soft_float"
+ ["-march=armv6j -mfpu=vfp"]="generic+v6j+vfp2-soft_float"
+ ["-march=armv7-a -mfpu=vfpv3-d16"]="generic+v7a+vfp3d16-soft_float"
+ ["-march=armv7-a -mfpu=crypto-neon-fp-armv8"]="generic+v7a+crypto+neon+fp_armv8-soft_float"
+
+ # https://bugs.gentoo.org/924920
+ ["-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"]=generic+v7a+vfp3d16-soft_float
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for AARCH64"'
+CHOST="aarch64-unknown-linux-gnu"
+c_to_zig_map=(
+ [" "]="generic"
+ ["-mcpu=native"]="native"
+ ["-mcpu=cortex-a78"]="cortex_a78"
+
+ ["-march=armv8.3-a"]="generic+v8_3a"
+ ["-mcpu=cortex-a78 -march=armv8.3-a"]="cortex_a78+v8_3a"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for X86"'
+CHOST="i686-pc-linux-gnu"
+c_to_zig_map=(
+ [" "]="i686"
+ ["-march=native"]="native"
+
+ ["-march=i486"]="i486"
+ ["-march=i586"]="i586"
+ ["-march=i686"]="i686"
+ ["-O2 -pipe -march=pentium-m"]="pentium_m"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for X86-64"'
+CHOST="x86_64-pc-linux-gnu"
+c_to_zig_map=(
+ [" "]="x86_64"
+ ["-march=native"]="native"
+
+ ["-march=x86-64-v2"]="x86_64_v2"
+ ["-march=x86-64"]="x86_64"
+ ["-march=znver2"]="znver2"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for RISCV32"'
+CHOST="riscv32-unknown-linux-gnu"
+c_to_zig_map=(
+ [" "]="generic_rv32"
+ ["-mcpu=native"]="native"
+ ["-mcpu=sifive-e31"]="sifive_e31"
+
+ ["-mabi=ilp32d -march=rv32imafdc"]="generic_rv32+i+m+a+f+d+c+d"
+ ["-mcpu=native -mabi=ilp32 -march=rv32imac"]="native+i+m+a+c"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for RISCV64"'
+CHOST="riscv64-unknown-linux-gnu"
+c_to_zig_map=(
+ [" "]="generic_rv64"
+ ["-mcpu=native"]="native"
+ ["-mcpu=sifive-u74"]="sifive_u74"
+
+ ["-mabi=lp64 -march=rv64imac"]="generic_rv64+i+m+a+c"
+ ["-mabi=lp64d -march=rv64gc"]="generic_rv64+i+m+a+f+d+zicsr+zifencei+c+d"
+ ["-march=rv64gcv"]="generic_rv64+i+m+a+f+d+zicsr+zifencei+c+v"
+ ["-march=rv64imafdc -mcpu=sifive-u74"]="sifive_u74+i+m+a+f+d+c"
+ ["-mcpu=native -mabi=lp64 -march=rv64imac"]="native+i+m+a+c"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for LoongArch64"'
+CHOST="loongarch64-unknown-linux-gnu"
+c_to_zig_map=(
+ [" "]="generic_la64"
+ ["-march=native"]="native"
+ ["-march=la664"]="la664"
+
+ ["-march=loongarch64 -mabi=lp64d"]="loongarch64+d"
+ ["-mabi=lp64f"]="generic_la64+f"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for PowerPC"'
+CHOST="powerpc-unknown-linux-gnu"
+c_to_zig_map=(
+ [" "]="ppc"
+ ["-mcpu=native"]="native"
+
+ ["-mcpu=G5"]="g5"
+
+ # qemu: uncaught target signal 4 (Illegal instruction) - core dumped
+ ["-mcpu=power7"]="pwr7:no-run"
+ ["-mcpu=power8"]="pwr8:no-run"
+
+ ["-mcpu=powerpc"]="ppc"
+ ["-mcpu=powerpcle"]="ppc"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+tbegin '"CFLAGS to Zig CPU for PowerPC64"'
+CHOST="powerpc64-unknown-linux-gnu"
+c_to_zig_map=(
+ [" "]="ppc64"
+ ["-mcpu=native"]="native"
+
+ # qemu: uncaught target signal 4 (Illegal instruction) - core dumped
+ ["-mcpu=power10"]="pwr10:no-run"
+
+ ["-mcpu=power9"]="pwr9"
+ ["-mcpu=powerpc64"]="ppc64"
+ ["-mcpu=powerpc64le"]="ppc64le"
+)
+test-convert_c_env_to_zig_cpu c_to_zig_map "${CHOST}"
+tend ${?}
+
+texit
diff --git a/eclass/zig-utils.eclass b/eclass/zig-utils.eclass
new file mode 100644
index 000000000000..ca72e89ed6ea
--- /dev/null
+++ b/eclass/zig-utils.eclass
@@ -0,0 +1,538 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig-utils.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @BLURB: Prepare Zig toolchain and set global variables
+# @DESCRIPTION:
+# Prepare Zig toolchain and set global variables.
+# Supports Zig 0.13+.
+# Does not set any default function, ebuilds must call them manually.
+# Generally, only "zig-utils_setup" is needed.
+#
+# Intended to be used by ebuilds that call "zig build-exe/lib/obj"
+# or "zig test" directly and by "dev-lang/zig".
+# For ebuilds with ZBS (Zig Build System), it's usually better
+# to inherit zig.eclass instead, as it has default phases-functions.
+
+if [[ -z ${_ZIG_UTILS_ECLASS} ]]; then
+_ZIG_UTILS_ECLASS=1
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit edo flag-o-matic linux-info
+
+# @ECLASS_VARIABLE: ZIG_SLOT
+# @PRE_INHERIT
+# @REQUIRED
+# @DESCRIPTION:
+# Zig slot that will be used in "ezig" function. Also, if
+# ZIG_OPTIONAL is empty, adds dev-lang/zig and dev-lang/zig-bin
+# dependency to BDEPEND. Must be >= "0.13".
+#
+# Example:
+# @CODE
+# ZIG_SLOT="0.13"
+# @CODE
+#
+# When a new Zig release occurs, it is advisable for maintainers to
+# check whether their ebuild supports that new version. If yes, they
+# they should bump ZIG_SLOT to the latest version; if not supported,
+# they need to patch any issues with new version and again bump
+# ZIG_SLOT. This helps to reduce dependencies on outdated Zig
+# versions.
+#
+# This policy of "1 exclusive Zig slot" will work until it
+# stabilizes enough (probably near 1.0), then it will be re-evaluated
+# and most likely changed to more common in other eclasses ZIG_MIN/
+# ZIG_MAX form.
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-utils and
+# zig eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
+#
+# For zig-utils.eclass users:
+# You have to add Zig dependency in your BDEPEND manually and call
+# at least "zig-utils_setup" before using "ezig".
+#
+# For zig.eclass users: see documentation in zig.eclass
+# instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND="
+ || (
+ dev-lang/zig:${ZIG_SLOT}
+ dev-lang/zig-bin:${ZIG_SLOT}
+ )
+ "
+fi
+
+# @ECLASS_VARIABLE: ZIG_TARGET
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Zig target tuple to use. Has the following format:
+# arch-os[.os_version_range]-abi[.abi_version]
+# Can be passed as:
+# * "-target " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dtarget=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
+#
+# Can be set by user in make.conf. If not set, then auto-generated by
+# "zig-utils_setup".
+#
+# Example:
+# @CODE
+# # Autodetected by Zig:
+# ZIG_TARGET="native"
+# # Machine running Linux x86_64 system, with glibc:
+# ZIG_TARGET="x86_64-linux-gnu"
+# # Similar to above, but versions are passed explicitly:
+# ZIG_TARGET="x86_64-linux.6.1.12...6.6.16-gnu.2.38"
+# # Machine running Linux PPC64 little-endian system, with musl
+# ZIG_TARGET="powerpc64le-linux-musl"
+# @CODE
+#
+# Note for eclass users: it is discouraged to overwrite ZIG_TARGET
+# value by ebuilds. In most cases, if you need to hardcode value for
+# -Dtarget, it's better to change "build.zig" code instead to use
+# appropriate values. For example, if some build-time executable
+# intented for host is compiled for cross-platform target, change in
+# build.zig "target" for that executable to be "b.graph.host".
+#
+# In rare cases, if you really need to hardcode ZIG_TARGET, use this
+# syntax before calling `zig-utils_setup` (or `zig_pkg_setup`) to
+# allow user override:
+# @CODE
+# pkg_setup() {
+# : "${ZIG_TARGET:=aarch64-freestanding-none}"
+# zig_pkg_setup
+# }
+# @CODE
+
+# @ECLASS_VARIABLE: ZIG_CPU
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Zig target CPU and features to use. Has the following format:
+# family_name(\+enable_feature|\-disable_feature)*
+# Can be passed as:
+# * "-mcpu " option in "zig test" or "zig build-exe/lib/obj",
+# * "-Dcpu=" option in "zig build"
+# (if project uses "std.Build.standardTargetOptions").
+#
+# Can be set by user in make.conf. If not set, then auto-generated by
+# "zig-utils_setup".
+#
+# Example:
+# @CODE
+# # Autodetected by Zig:
+# ZIG_CPU="native"
+# # AMD Zen 2 processor
+# ZIG_CPU="znver2"
+# # x86_64 processor, X87 support enabled, SSE2 support disabled
+# ZIG_CPU="x86_64+x87-sse2"
+# @CODE
+#
+# Note for eclass users: it is discouraged to overwrite ZIG_CPU
+# value by ebuilds. In most cases, if you need to hardcode value for
+# -Dcpu, it's better to change "build.zig" code instead to use
+# appropriate values. For example, if some build-time executable
+# intented for host is compiled for cross-platform target, change in
+# build.zig "target" for that executable to be "b.graph.host".
+#
+# In rare cases, if you really need to hardcode ZIG_CPU, use this
+# syntax before calling `zig-utils_setup` (or `zig_pkg_setup`) to
+# allow user override:
+# @CODE
+# pkg_setup() {
+# : "${ZIG_CPU:=apple_m1}"
+# zig_pkg_setup
+# }
+# @CODE
+
+# @ECLASS_VARIABLE: ZIG_EXE
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Absolute path to the used Zig executable.
+# Set by "zig-utils_setup"/"zig-utils_find_installation".
+#
+# Please note that when passing one flag several times with different
+# values:
+# * (only "zig build") in "-Dbar=false -Dbar" form:
+# errors due to conflict of flags,
+# * (only "zig build") in "-Dbar=false -Dbar=true" form:
+# "bar" becomes a list, which is likely not what you want,
+# * in "-fbar -fno-bar" form:
+# latest value overwrites values before.
+# Example above shows only boolean option, but it is same with other
+# types of options (enums, "std.zig.BuildId", "std.SemanticVersion",
+# integers, strings, etc.).
+
+# @ECLASS_VARIABLE: ZIG_VER
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# Zig version as reported in dev-lang/zig-${PV} PV part.
+# Set by "zig-utils_setup"/"zig-utils_find_installation".
+#
+# Example:
+# @CODE
+# 0.13.0
+# @CODE
+
+# @FUNCTION: zig-utils_c_env_to_zig_target
+# @USAGE: <C-style target tuple> <CFLAGS>
+# @DESCRIPTION:
+# Translates C-style target tuple (like CHOST) and CFLAGS to Zig-style
+# target tuple. For full information "zig-utils_c_env_to_zig_cpu" is
+# needed, because some information is located in different places in C
+# and Zig, for example:
+# * Moved from C target to Zig CPU: x86 and ARM families,
+# * Moved from CFLAGS to Zig tuple: ARM Thumb mode.
+#
+# Mostly used during cross-compilation to get target triple if user
+# did not set ZIG_TARGET variable, and always during bootstraping Zig.
+#
+# See ZIG_TARGET description for more information.
+zig-utils_c_env_to_zig_target() {
+ if [[ ${#} -ne 2 ]]; then
+ die "${FUNCNAME[0]}: expected 2 arguments, got ${#}"
+ fi
+ local c_tuple="${1}"
+ local c_arch="${c_tuple%%-*}"
+ local c_abi="${c_tuple##*-}"
+
+ local c_flags="${2}"
+ local c_flags_march="$(CFLAGS="${c_flags}" get-flag march)"
+
+ local arch os abi
+
+ case "${c_arch}" in
+ i?86) arch=x86;;
+ arm64) arch=aarch64;;
+ arm*)
+ if [[ "${c_flags_march}" == *-m ]]; then
+ arch=thumb
+ else
+ arch=arm
+ fi
+
+ if [[ "${c_arch}" == *eb ]]; then
+ arch+="eb"
+ fi
+ ;;
+ *) arch="${c_arch}";;
+ esac
+
+ case "${c_tuple}" in
+ *-linux*) os=linux;;
+ *-apple*) os=macos;;
+ esac
+
+ case "${c_abi}" in
+ darwin*) abi=none;;
+ *) abi="${c_abi}";;
+ esac
+
+ echo "${arch}-${os}-${abi}"
+}
+
+# @FUNCTION: zig-utils_c_env_to_zig_cpu
+# @USAGE: <C-style target tuple> <CFLAGS>
+# @DESCRIPTION:
+# Translates C-style target tuple (like CHOST) and CFLAGS to Zig-style
+# target CPU and features. For full information
+# "zig-utils_c_env_to_zig_target" is needed, because some information
+# is located in different places in C and Zig, for example:
+# * Moved from C target to Zig CPU: x86 and ARM families,
+# * Moved from CFLAGS to Zig tuple: ARM Thumb mode.
+#
+# Used to get target CPU if user did not set ZIG_CPU variable.
+#
+# See ZIG_CPU description for more information.
+zig-utils_c_env_to_zig_cpu() {
+ if [[ ${#} -ne 2 ]]; then
+ die "${FUNCNAME[0]}: expected 2 arguments, got ${#}"
+ fi
+ local c_tuple="${1}"
+ local c_arch="${c_tuple%%-*}"
+
+ local c_flags="${2}"
+ local c_flags_mabi="$(CFLAGS="${c_flags}" get-flag mabi)"
+ local c_flags_march="$(CFLAGS="${c_flags}" get-flag march)"
+ local c_flags_mcpu="$(CFLAGS="${c_flags}" get-flag mcpu)"
+ local c_flags_mfpu="$(CFLAGS="${c_flags}" get-flag mfpu)"
+
+ local base_cpu features=""
+
+ case "${c_arch}" in
+ x86_64 | i?86)
+ local c_cpu="${c_flags_march}"
+ case "${c_cpu}" in
+ "") base_cpu="${c_arch}";;
+ *) base_cpu="${c_cpu//[-.]/_}";;
+ esac
+ ;;
+ aarch64 | aarch64_be | arm*)
+ local c_cpu="${c_flags_mcpu}"
+ case "${c_cpu}" in
+ "") base_cpu=generic;;
+ *) base_cpu="${c_cpu//[-.]/_}";;
+ esac
+
+ case "${c_flags_march}" in
+ "") ;;
+ armv*)
+ local c_arm_family="${c_flags_march##arm}"
+ c_arm_family="${c_arm_family//./_}"
+ c_arm_family="${c_arm_family//-/}"
+ features+="+${c_arm_family}"
+ ;;
+ *) features+="+${c_flags_march}";;
+ esac
+
+ if [[ "${c_arch}" != aarch64* && "${c_arch}" != arm64 ]]; then
+ if [[ "${c_flags_mfpu}" == crypto-* ]]; then
+ c_flags_mfpu="${c_flags_mfpu##crypto-}"
+ features+="+crypto"
+ fi
+ if [[ "${c_flags_mfpu}" == neon-* ]]; then
+ c_flags_mfpu="${c_flags_mfpu##neon-}"
+ features+="+neon"
+ fi
+
+ case "${c_flags_mfpu}" in
+ "" | auto) ;;
+ neon) features+="+neon";;
+ fp16) features+="+fp16";;
+ fp-armv8) features+="+fp_armv8";;
+
+ vfp | vfpv2) features+="+vfp2";;
+
+ vfp3 | vfpv3) features+="+vfp3";;
+ vfpv3-fp16) features+="+vfp3sp";;
+ vfpv3-d16) features+="+vfp3d16";;
+ vfpv3-d16-fp16) features+="+vfp3d16sp";;
+ vfpv3xd) features+="+vfp3d16sp";;
+ vfpv3xd-fp16) features+="+vfp3d16sp+fp16";;
+
+ vfpv4) features+="+vfp4";;
+ vfpv4-fp16) features+="+vfp4sp";;
+ vfpv4-d16) features+="+vfp4d16";;
+ fpv4-sp-fp16) features+="+vfp4d16sp";;
+
+ fpv5-d16) features+="+fp_armv8d16+fp64";;
+ *) die -n "Unknown ARM FPU: ${c_flags_mfpu}";;
+ esac
+
+ local is_softfloat="$(CTARGET="${c_tuple}" tc-tuple-is-softfloat)"
+ case "${is_softfloat}" in
+ only | yes) features+="+soft_float";;
+ softfp | no) features+="-soft_float";;
+ *) die -n "tc-tuple-is-softfloat returned unexpected value: ${is_softfloat}"
+ esac
+ fi
+ ;;
+ riscv32 | riscv64)
+ local c_cpu="${c_flags_mcpu}"
+ case "${c_cpu}" in
+ "")
+ case "${c_arch}" in
+ riscv32) base_cpu=generic_rv32;;
+ riscv64) base_cpu=generic_rv64;;
+ esac
+ ;;
+ *) base_cpu="${c_cpu//[-.]/_}";;
+ esac
+
+ local base_isa="${c_flags_march:0:4}"
+ local extensions="${c_flags_march:4}"
+
+ case "${base_isa}" in
+ "" | rv32 | rv64) ;;
+ *) die -n "Unknown RISC-V architecture: ${base_isa}";;
+ esac
+
+ local extension
+ while read -n 1 extension; do
+ case "${extension}" in
+ "") ;;
+ g) features+="+i+m+a+f+d+zicsr+zifencei";;
+ _) die -n "Can't translate multi-letter RISC-V extensions yet";;
+ *) features+="+${extension}";;
+ esac
+ done <<< "${extensions}"
+
+ case "${c_flags_mabi}" in
+ ilp32d | lp64d) features+="+d";;
+ ilp32e | lp64e) features+="+e";;
+ ilp32f | lp64f) features+="+f";;
+ "" | ilp32 | lp64) ;;
+ *) die -n "Unknown RISC-V ABI: ${c_flags_mabi}";;
+ esac
+ ;;
+ loongarch64)
+ local c_cpu="${c_flags_march}"
+ case "${c_cpu}" in
+ "") base_cpu=generic_la64;;
+ *) base_cpu="${c_cpu//[-.]/_}";;
+ esac
+
+ case "${c_flags_mabi}" in
+ lp64d) features+="+d";;
+ lp64f) features+="+f";;
+ lp64s | "") ;;
+ *) die -n "Unknown LoongArch ABI: ${c_flags_mabi}";;
+ esac
+ ;;
+ powerpc | powerpcle | powerpc64 | powerpc64le)
+ local c_cpu="${c_flags_mcpu}"
+ case "${c_cpu}" in
+ "")
+ case "${c_arch}" in
+ powerpc | powerpcle) base_cpu=ppc;;
+ powerpc64 | powerpc64le) base_cpu=ppc64;;
+ esac
+ ;;
+ G*) base_cpu="${c_cpu//G/g}";;
+ powerpcle) base_cpu=ppc;;
+ powerpc*) base_cpu="${c_cpu//powerpc/ppc}";;
+ power*) base_cpu="${c_cpu//power/pwr}";;
+ *) base_cpu="${c_cpu//[-.]/_}";;
+ esac
+ ;;
+ *) base_cpu=generic;;
+ esac
+
+ echo "${base_cpu}${features}"
+}
+
+# @FUNCTION: zig-utils_find_installation
+# @DESCRIPTION:
+# Detects suitable Zig installation and sets ZIG_VER and ZIG_EXE
+# variables.
+#
+# See ZIG_EXE and ZIG_VER descriptions for more information.
+zig-utils_find_installation() {
+ # Adapted from https://github.com/gentoo/gentoo/pull/28986
+ # Many thanks to Florian Schmaus (Flowdalic)!
+
+ [[ -n "${ZIG_SLOT}" ]] || die "${FUNCNAME[0]}: ZIG_SLOT must be set"
+ if ver_test "${ZIG_SLOT}" -lt "0.13"; then
+ die "${ECLASS}: ZIG_SLOT must be >= 0.13, found ${ZIG_SLOT}"
+ fi
+
+ einfo "Searching Zig ${ZIG_SLOT}..."
+
+ local zig_supported_versions=(
+ "9999"
+ "0.13.1"
+ "0.13.0"
+ )
+
+ local base_path="${BROOT}/usr/bin"
+
+ local selected_path selected_ver
+ for selected_ver in "${zig_supported_versions[@]}"; do
+ # Check if candidate satisfies ZIG_SLOT condition.
+ if [[ "${selected_ver}" != "${ZIG_SLOT}"* ]]; then
+ continue
+ fi
+
+ # Prefer "dev-lang/zig" over "dev-lang/zig-bin"
+ local candidate_path
+ for candidate_path in "${base_path}"/zig{,-bin}-"${selected_ver}"; do
+ if [[ -x "${candidate_path}" ]]; then
+ selected_path="${candidate_path}"
+ break 2
+ fi
+ done
+ done
+
+ if [[ -z "${selected_path}" ]]; then
+ die "Could not find (suitable) Zig at \"${base_path}\""
+ fi
+
+ declare -g ZIG_EXE="${selected_path}"
+ declare -g ZIG_VER="${selected_ver}"
+ # Sanity check, comment from upstream:
+ # > Check libc++ linkage to make sure Zig was built correctly,
+ # > but only for "env" and "version" to avoid affecting the
+ # > startup time for build-critical commands
+ # > (check takes about ~10 μs)
+ "${ZIG_EXE}" version > /dev/null ||
+ die "Sanity check failed for \"${ZIG_EXE}\""
+}
+
+# @FUNCTION: zig-utils_setup
+# @DESCRIPTION:
+# Checks if running Linux kernel version is supported by Zig.
+# Populates ZIG_TARGET, ZIG_CPU, ZIG_EXE and ZIG_VER global
+# variables with detected values, or, if user set them already,
+# leaves as-is.
+zig-utils_setup() {
+ # Should be first because it sets ZIG_VER which might be used
+ # in the future when setting ZIG_TARGET and ZIG_CPU variables
+ # for incompatible versions.
+ if [[ -z "${ZIG_EXE}" ]]; then
+ zig-utils_find_installation
+ fi
+
+ : "${ZIG_CPU:=$(zig-utils_c_env_to_zig_cpu "${CHOST}" "${CFLAGS}")}"
+ if tc-is-cross-compiler; then
+ : "${ZIG_TARGET:=$(zig-utils_c_env_to_zig_target "${CHOST}" "${CFLAGS}")}"
+ else
+ : "${ZIG_TARGET:=native}"
+ fi
+ declare -g ZIG_CPU ZIG_TARGET
+
+ einfo "ZIG_EXE: \"${ZIG_EXE}\""
+ einfo "ZIG_VER: ${ZIG_VER}"
+ einfo "ZIG_TARGET: ${ZIG_TARGET}"
+ einfo "ZIG_CPU: ${ZIG_CPU}"
+}
+
+# @FUNCTION: ezig
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Runs ZIG_EXE with supplied arguments. Dies if ZIG_EXE is not set or
+# if command exits with error. Respects `nonfatal`.
+#
+# Always disables progress tree. By default enables ANSI escape codes
+# (colors, etc.), user can set NO_COLOR environment variable to
+# disable them.
+#
+# Note that color support also determines how compile errors will be
+# printed: source code lines and reference traces are not available
+# when colors are disabled.
+ezig() {
+ # Sync description above and comments below with upstream's
+ # "std.io.tty.detectConfig".
+ debug-print-function "${FUNCNAME[0]}" "${@}"
+
+ if [[ -z "${ZIG_EXE}" ]] ; then
+ die "${FUNCNAME[0]}: ZIG_EXE is not set. Was 'zig-utils_setup' called before using ezig?"
+ fi
+
+ # Progress tree is helpful indicator in TTY, but unfortunately
+ # they make Portage logs harder to read in plaintext.
+ #
+ # We don't have global toggle for all Zig commands to disable
+ # progress tree, however we can emulate this using 2 steps.
+
+ # Disable progress tree and colors. Errors are now less detailed.
+ local -x TERM=dumb
+ # Re-enable colors. Errors are now yet again detailed for reading.
+ local -x CLICOLOR_FORCE=1
+ # User's NO_COLOR has more priority and can disable colors again.
+ "${ZIG_EXE}" "${@}" || die -n "Failed to run command: ${ZIG_EXE} ${@}"
+}
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v3 2/5] zig.eclass: new eclass
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 1/5] zig-utils.eclass: new eclass Eric Joldasov
@ 2024-12-13 20:07 ` Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 3/5] dev-lang/zig: add 0.13.0-r2 Eric Joldasov
` (2 subsequent siblings)
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-12-13 20:07 UTC (permalink / raw
To: gentoo-dev
This eclass is built on top of `zig-utils.eclass` and works with
`zig build` sub-commands and `build.zig` system, here called ZBS or
Zig Build System. By default it adds convenient default dependencies
and phase functions (which can be opt-out by setting `ZIG_OPTIONAL=1`)
that:
* work with dependencies from official package manager,
* configures basic sane options for `zig build`, which can be further
complemented by ebuild authors and users,
* respects user settings for verbosity and jobs number,
* has some basic support for cross-compilation, which works on my PC
with `crossdev` and QEMU-ed Docker container, but it was not tested
on real machine yet.
This is a major step in unifying behaviour and de-duplicating logic
spanning multiple ebuilds (target convertion and jobs amount
in `dev-lang/zig`, different Zig search and build options configuration
in `sys-fs/ncdu` and other ebuilds in community overlays). Mentioned
ebuilds are converted in next commits.
It is recommended to use https://github.com/BratishkaErik/zig-ebuilder
with this eclass to generate base for new ebuilds.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
eclass/zig.eclass (new) | 558 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 558 insertions(+)
diff --git a/eclass/zig.eclass b/eclass/zig.eclass
new file mode 100644
index 000000000000..e838616ef72a
--- /dev/null
+++ b/eclass/zig.eclass
@@ -0,0 +1,558 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: zig.eclass
+# @MAINTAINER:
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @AUTHOR:
+# Alfred Wingate <parona@protonmail.com>
+# Violet Purcell <vimproved@inventati.org>
+# Eric Joldasov <bratishkaerik@landless-city.net>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: zig-utils
+# @BLURB: Functions for working with ZBS (Zig Build System)
+# @DESCRIPTION:
+# Functions for working with Zig build system and package manager.
+# Supports Zig 0.13+. Exports default functions for convenience.
+#
+# Note that zig.eclass is mostly tailored for projects that:
+# 1) Install something in build.zig steps: "artifacts" (executable,
+# libraries, objects), source codes, assets, tests, scripts etc. But
+# many authors also use it to write Zig "modules", build logic
+# and/or bindings/wrappers for C/C++ libraries. They install nothing
+# and are only used at build-time, so it's unneccessary and mostly
+# useless to make ebuilds for them.
+# 2) Have required `target`, `cpu` and optional `optimize` options in
+# build.zig that accept standard Zig-style target and optimize mode.
+# They are usually created by calling `b.standardTargetOptions` and
+# `b.standardOptimizeOption` functions.
+#
+# For end-user executables, usually it's recommended to patch to call
+# these options and upstream it, but in some cases authors have good
+# reasons to not have them, f.e. if it is built only for WASM
+# platform with ReleaseSmall, and is not intended to run in /usr/bin/.
+# In this case, declare dummy options using `b.option` and ignore
+# their values, or else eclass wouldn't work.
+#
+# Another case is when upstream has `target` option but it has
+# custom format and does not accept usual Zig targets, but rather
+# something specific to the project like "linux-baseline-lts", or
+# combine CPU and target in one option.
+# In this case, it's best to rename that option to something like
+# `target-custom`, then declare `target` option and make converter
+# from one value to other.
+#
+# For non-executable binaries like C libraries, objects etc. our
+# policy is stricter, all 3 options are required and should not
+# be ignored, with no exceptions.
+
+if [[ -z ${_ZIG_ECLASS} ]]; then
+_ZIG_ECLASS=1
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+inherit multiprocessing zig-utils
+
+# @ECLASS_VARIABLE: ZIG_OPTIONAL
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, all logic in zig-utils and
+# zig eclasses will be considered optional. No dependencies
+# will be added and no phase functions will be exported.
+#
+# For zig.eclass users:
+# You need to add Zig and pkgconfig dependencies in your BDEPEND, set
+# QA_FLAGS_IGNORED and call all phase functions manually. If you want
+# to use "ezig build" directly, call "zig_pkg_setup" before it.
+#
+# For zig-utils.eclass users: see documentation in
+# zig-utils.eclass instead.
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ BDEPEND="virtual/pkgconfig"
+
+ # See https://github.com/ziglang/zig/issues/3382
+ # Zig Build System does not support CFLAGS/LDFLAGS/etc.
+ QA_FLAGS_IGNORED=".*"
+fi
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Bash associative array with all tarballs that will be fetched by
+# "ezig fetch" in zig_src_unpack phase. Value is URL where
+# tarball is located, key is name under which it would be downloaded
+# and renamed. So generally it has effect of "value -> key".
+#
+# Note: if Zig Build System dependency can't be represented in SRC_URI
+# (like direct Git commit URIs), you should do the following
+# (zig-ebuilder does archiving automatically for you):
+# 1. Archive each folder with dependency content in some tarball,
+# so f.e. if you have 2 Git dependencies, create 2 tarballs.
+# 2. Archive all previous tarballs into one combined tarball (also
+# called tarball-tarball from now on), no subdirs, so that eclass
+# can firstly unpack this tarball with "unpack",
+# and secondly unpack its content with "zig fetch".
+# 3. (zig-ebuilder can't do this) Host this tarball somewhere
+# and put URL of this tarball in SRC_URI, and archives in
+# ZBS_DEPENDENCIES, keys must be names of archives, values empty.
+#
+# Example:
+# @CODE
+# declare -r -A ZBS_DEPENDENCIES=(
+# [tarball_a-<long-hash>.tar.gz]='URL_A'
+# [tarball_b-<long-hash>.tar.gz]='URL_B'
+#
+# # If there are Git dependencies:
+# [git_c-<long-hash>.tar.gz]=''
+# # Tarball-tarball should contain inside above tarball flatly.
+# )
+# @CODE
+
+# @ECLASS_VARIABLE: ZBS_DEPENDENCIES_SRC_URI
+# @OUTPUT_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Content of ZBS_DEPENDENCIES converted at inherit-time, to be used in
+# SRC_URI. Note that elements with empty keys will be skipped.
+# Example:
+# @CODE
+# SRC_URI="
+# <URL to project sources, patches, non-Zig resources etc.>
+#
+# # If there are Git dependencies:
+# # <URL to tarball-tarball>
+#
+# ${ZBS_DEPENDENCIES_SRC_URI}
+# "
+# @CODE
+
+# @FUNCTION: _zig_set_zbs_uris
+# @INTERNAL
+# @DESCRIPTION:
+# Sets ZBS_DEPENDENCIES_SRC_URI variable based on ZBS_DEPENDENCIES.
+_zig_set_zbs_uris() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ ZBS_DEPENDENCIES_SRC_URI=
+
+ local dependency
+ for dependency in "${!ZBS_DEPENDENCIES[@]}"; do
+ local uri="${ZBS_DEPENDENCIES[${dependency}]}"
+ if [[ -n "${uri}" ]]; then
+ ZBS_DEPENDENCIES_SRC_URI+=" ${uri} -> ${dependency}"
+ fi
+ done
+}
+_zig_set_zbs_uris
+
+# @ECLASS_VARIABLE: my_zbs_args
+# @DESCRIPTION:
+# Bash array with ebuild-specified arguments to pass to the
+# "zig build" after "src_configure".
+# It's appended to the ZBS_ARGS during "src_configure". Note: if you
+# need to override default optimize mode of this eclass (ReleaseSafe)
+# with your default, please use "--release=small" etc. syntax so that
+# user can still override it in ZBS_ARGS_EXTRA.
+#
+# Example:
+# @CODE
+# src_configure() {
+# local my_zbs_args=(
+# -Dpie=true
+# )
+#
+# zig_src_configure
+# }
+# @CODE
+: "${my_zbs_args:=}"
+
+# @ECLASS_VARIABLE: ZBS_ARGS_EXTRA
+# @USER_VARIABLE
+# @DESCRIPTION:
+# Bash string with user-specified arguments to pass to the "zig build"
+# after "src_configure".
+# It's appended to the ZBS_ARGS during "zig_src_configure".
+#
+# If this does not have amount of jobs, eclass will try to take amount
+# of jobs from MAKEOPTS, and if it also does not have them, it will
+# default to $(nproc).
+#
+# Example:
+# @CODE
+# ZBS_ARGS_EXTRA="-j8 --release=small"
+# @CODE
+: "${ZBS_ARGS_EXTRA:=}"
+
+# @ECLASS_VARIABLE: ZBS_VERBOSE
+# @USER_VARIABLE
+# @DESCRIPTION:
+# If enabled, eclass will add "--summary all --verbose" options to
+# "ezig build", so that it prints every command before executing,
+# and summarry tree at the end of step. If not, will do nothing.
+# Enabled by default. Set to OFF to disable these verbose messages.
+#
+# Note: this variable does not control other options starting with
+# "--verbose-", such as "--verbose-link" or "--verbose-cimport". If
+# you need them, add them manually to ZBS_ARGS_EXTRA.
+: "${ZBS_VERBOSE:=ON}"
+
+# @ECLASS_VARIABLE: BUILD_DIR
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Directory where all "ezig build" calls will be proceeded.
+# Defaults to "${WORKDIR}/${P}-build" if not set.
+: "${BUILD_DIR:=${WORKDIR}/${P}-build}"
+
+# @ECLASS_VARIABLE: ZBS_ECLASS_DIR
+# @DESCRIPTION:
+# Directory where various files used by this eclass are stored.
+# They can be supplied by the ebuild or by eclass.
+# Currently, it's used only for Zig packages, which are stored in "p/"
+# subdirectory.
+# Defaults to "${WORKDIR}/zig-eclass" if not set.
+# Should be set before calling "zig_src_unpack" or
+# "zig_live_fetch".
+: "${ZBS_ECLASS_DIR:=${WORKDIR}/zig-eclass}"
+
+# @FUNCTION: zig_get_jobs
+# @DESCRIPTION:
+# Returns number of jobs from ZBS_ARGS_EXTRA or MAKEOPTS.
+# If there is none, defaults to number of available processing units.
+zig_get_jobs() {
+ local all_args="${MAKEOPTS} ${ZBS_ARGS_EXTRA}"
+ local default_jobs="$(get_nproc)"
+ local jobs="$(makeopts_jobs "${all_args}" "${default_jobs}")"
+
+ if [[ "${jobs}" == "0" ]]; then
+ # Zig build system does not allow "-j0", and does not have
+ # option for unlimited parallelism. Pass our default number
+ # of jobs here.
+ echo "${default_jobs}"
+ else
+ echo "${jobs}"
+ fi
+}
+
+# @FUNCTION: zig_init_base_args
+# @DESCRIPTION:
+# Stores basic args for future "ezig build" calls in ZBS_ARGS_BASE.
+# Package manager option is managed by "zig_src_prepare",
+# ebuild and user options are added by "zig_src_configure".
+#
+# This function is used by "zig_pkg_setup", and it is neccessary
+# that args are available as early as possible, so that ebuilds
+# could use them in steps like "src_unpack" if neccessary, while
+# still having verbosity and amount of jobs from user respected.
+#
+#
+# TODO: currently this function enables "--search-prefix" (1) and
+# "--sysroot" (2) only when cross-compiling, should be fixed to
+# unconditionally enabling it.
+#
+# For solving (1) this patch should be reworked and upstreamed:
+# https://paste.sr.ht/~bratishkaerik/2ddffe2bf0f8f9d6dfb60403c2e9560334edaa88
+#
+# (2)
+# "--sysroot" should be passed together with "--search-prefix" above,
+# if we pass only "--sysroot" it gives these errors:
+# @CODE
+# error: unable to find dynamic system library 'zstd' using strategy 'paths_first'. searched paths: none
+# @CODE
+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_
+
+ declare -g -a ZBS_ARGS_BASE=(
+ -j$(zig_get_jobs)
+
+ -Dtarget="${ZIG_TARGET}"
+ -Dcpu="${ZIG_CPU}"
+ --release=safe
+
+ --prefix-exe-dir bin/
+ --prefix-lib-dir "$(get_libdir)/"
+ --prefix-include-dir include/
+
+ # Should be relative path to make other calls easier,
+ # so remove leading slash here.
+ --prefix "${EPREFIX:+${EPREFIX#/}/}usr/"
+
+ --libc "${T}/zig_libc.txt"
+ )
+ if [[ "${ZBS_VERBOSE}" != OFF ]]; then
+ ZBS_ARGS_BASE+=( --summary all --verbose )
+ fi
+
+ if tc-is-cross-compiler; then
+ ZBS_ARGS_BASE+=(
+ --search-prefix "${ESYSROOT}/usr/"
+ --sysroot "${ESYSROOT}/"
+ )
+ fi
+}
+
+# @FUNCTION: zig_pkg_setup
+# @DESCRIPTION:
+# Sets up environmental variables for Zig toolchain
+# and basic args for Zig Build System.
+zig_pkg_setup() {
+ [[ "${MERGE_TYPE}" != binary ]] || return 0
+
+ zig-utils_setup
+ zig_init_base_args
+
+ mkdir "${T}/zig-cache/" || die
+
+ # Environment variables set by this eclass.
+
+ # Used by Zig Build System to find `pkg-config`.
+ # UPSTREAM Used only by 9999 for now, should land in future
+ # 0.14 release.
+ export PKG_CONFIG="${PKG_CONFIG:-"$(tc-getPKG_CONFIG)"}"
+ # Used by whole Zig toolchain (most of the sub-commands)
+ # to find local and global cache directories.
+ export ZIG_LOCAL_CACHE_DIR="${T}/zig-cache/local/"
+ export ZIG_GLOBAL_CACHE_DIR="${T}/zig-cache/global/"
+}
+
+# @FUNCTION: zig_live_fetch
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Fetches packages, if they exist, to the "ZBS_ECLASS_DIR/p/".
+# Adds build file path to ZBS_BASE_ARGS.
+# If you have some lazy dependency which is not triggered in default
+# configuration, pass options like you would pass them for regular
+# "ezig build". Try to cover all of them before "src_configure".
+# **Note**: this function will be deprecated once/if
+# https://github.com/ziglang/zig/pull/19975 lands.
+#
+# Example:
+# @CODE
+# src_unpack() {
+# # If there are no lazy dependency:
+# zig_live_fetch
+#
+# # If there are lazy dependencies that can be triggered together:
+# zig_live_fetch -Denable-wayland -Denable-xwayland
+#
+# # If there are 2 lazy dependencies that can't be triggered
+# # together in one call because they conflict:
+# zig_live_fetch -Dmain-backend=opengl
+# zig_live_fetch -Dmain-backend=vulkan
+# }
+# @CODE
+zig_live_fetch() {
+ # This function will likely be called in src_unpack,
+ # before [zig_]src_prepare, so this directory might not
+ # exist yet.
+ mkdir -p "${BUILD_DIR}" > /dev/null || die
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ ZBS_ARGS_BASE+=( --build-file "${S}/build.zig" )
+
+ local args=(
+ "${ZBS_ARGS_BASE[@]}"
+
+ --global-cache-dir "${ZBS_ECLASS_DIR}/"
+
+ # Function arguments
+ "${@}"
+ )
+
+ einfo "ZBS: live-fetching with:"
+ einfo "${args[@]}"
+ ezig build --help "${args[@]}" > /dev/null
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig_src_unpack
+# @DESCRIPTION:
+# Unpacks every archive in SRC_URI and ZBS_DEPENDENCIES,
+# in that order. Adds build file path to ZBS_BASE_ARGS.
+zig_src_unpack() {
+ # Thanks to Alfred Wingate "parona" for inspiration here:
+ # https://gitlab.com/Parona/parona-overlay/-/blob/874dcfe03116574a33ed51f469cc993e98db1fa2/eclass/zig.eclass
+
+ ZBS_ARGS_BASE+=( --build-file "${S}/build.zig" )
+
+ if [[ "${#ZBS_DEPENDENCIES_SRC_URI}" -eq 0 ]]; then
+ default_src_unpack
+ return
+ fi
+
+ local zig_deps=()
+ for dependency in "${!ZBS_DEPENDENCIES[@]}"; do
+ zig_deps+=("${dependency}")
+ done
+
+ # First unpack non-Zig dependencies, so that
+ # tarball with all Git dependencies tarballs is unpacked early.
+ local dist
+ for dist in ${A}; do
+ if ! has "${dist}" "${zig_deps[@]}"; then
+ unpack "${dist}"
+ fi
+ done
+
+ # Now unpack all Zig dependencies, including those that are
+ # now unpacked from tarball-tarball.
+ local zig_dep
+ for zig_dep in "${zig_deps[@]}"; do
+ # Hide now-spammy hash from stdout
+ ezig fetch --global-cache-dir "${ZBS_ECLASS_DIR}/" \
+ "${DISTDIR}/${zig_dep}" > /dev/null
+ done
+ einfo "ZBS: ${#zig_deps[@]} dependencies unpacked"
+}
+
+# @FUNCTION: zig_src_prepare
+# @DESCRIPTION:
+# Calls default "src_prepare" function, creates BUILD_DIR directory
+# and enables system mode (by adding to ZBS_BASE_ARGS).
+#
+# System mode is toggled here and not in "src_unpack" because they
+# could have been fetched by "live_fetch" in live ebuilds instead.
+zig_src_prepare() {
+ default_src_prepare
+
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+
+ local system_dir="${ZBS_ECLASS_DIR}/p/"
+ mkdir -p "${system_dir}" || die
+ ZBS_ARGS_BASE+=(
+ # Disable network access after ensuring all dependencies
+ # are unpacked (by "src_unpack" or "live_fetch")
+ --system "${system_dir}"
+ )
+}
+
+# @FUNCTION: zig_src_configure
+# @DESCRIPTION:
+# Creates ZBS_ARGS array which can be used in all future phases,
+# by combining ZBS_ARGS_BASE set previously, my_zbs_args from ebuild,
+# and ZBS_ARGS_EXTRA by user, in this order.
+#
+# Specific flags currently only add support for the cross-compilation.
+# They are likely to be extended in the future.
+zig_src_configure() {
+ # Handle quoted whitespace.
+ eval "local -a ZBS_ARGS_EXTRA=( ${ZBS_ARGS_EXTRA} )"
+
+ # Since most arguments in array are also cached by ZBS, we
+ # want to reuse array as much as possible, so prevent
+ # modification of it.
+ declare -g -a -r ZBS_ARGS=(
+ # Base arguments from pkg_setup/setup_base_args
+ "${ZBS_ARGS_BASE[@]}"
+
+ # Arguments from ebuild
+ "${my_zbs_args[@]}"
+
+ # Arguments from user
+ "${ZBS_ARGS_EXTRA[@]}"
+ )
+
+ einfo "ZBS: configured with:"
+ einfo "${ZBS_ARGS[@]}"
+}
+
+# @FUNCTION: zig_src_compile
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build" with previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+zig_src_compile() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ einfo "ZBS: compiling with: ${args[@]}"
+ nonfatal ezig build "${args[@]}" || die "ZBS: compilation failed"
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig_src_test
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# If "test" step exist, calls "ezig build test" with previously set
+# ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Note: currently step detection might give false positives in
+# very rare cases, it will be improved in the future.
+zig_src_test() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+
+ # UPSTREAM std.testing.tmpDir and a lot of other functions
+ # do not respect --cache-dir or ZIG_LOCAL_CACHE_DIR:
+ # https://github.com/ziglang/zig/issues/19874
+ mkdir ".zig-cache/" || die
+
+ # UPSTREAM Currently, step name can have any characters in it,
+ # including whitespaces, so splitting names and descriptions
+ # by whitespaces is not enough for some cases.
+ # We probably need something like "--list-steps names_only".
+ # In practice, almost nobody sets such names.
+ if grep -q '^[ ]*test[ ]' < <(
+ nonfatal ezig build --list-steps "${args[@]}" ||
+ die "ZBS: listing steps failed"
+ ); then
+ einfo "ZBS: testing with: ${args[@]}"
+ nonfatal ezig build test "${args[@]}" ||
+ die "ZBS: tests failed"
+ else
+ einfo "Test step not found, skipping."
+ fi
+
+ popd > /dev/null || die
+}
+
+# @FUNCTION: zig_src_install
+# @USAGE: [<args>...]
+# @DESCRIPTION:
+# Calls "ezig build" with DESTDIR and previously set ZBS_ARGS.
+# Args passed to this function will be passed after ZBS_ARGS.
+# Also installs documentation via "einstalldocs".
+zig_src_install() {
+ pushd "${BUILD_DIR}" > /dev/null || die
+ local args=( "${ZBS_ARGS[@]}" "${@}" )
+ einfo "ZBS: installing with: ${args[@]}"
+ DESTDIR="${D}" nonfatal ezig build "${args[@]}" ||
+ die "ZBS: installing failed"
+ popd > /dev/null || die
+
+ einstalldocs
+}
+
+fi
+
+if [[ ! ${ZIG_OPTIONAL} ]]; then
+ EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install
+fi
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v3 3/5] dev-lang/zig: add 0.13.0-r2
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 1/5] zig-utils.eclass: new eclass Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 2/5] zig.eclass: " Eric Joldasov
@ 2024-12-13 20:07 ` Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 4/5] dev-lang/zig: sync 9999 with 0.13.0-r2 Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 5/5] sys-fs/ncdu: add 2.7-r1 Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-12-13 20:07 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use llvm-r1 eclass instead of llvm, zig and
zig-utils eclasses instead of local get_zig_mcpu etc. functions.
* Port "llvm USE-flag" from 9999 ebuild.
* "stage3" compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig.eclass with common options.
* Before migrating to the zig.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we
use upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in `src_test` is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-utils.eclass functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-utils.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with `zig std` command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
....13.0-skip-test-stack_iterator.patch (new) | 32 +++
dev-lang/zig/zig-0.13.0-r2.ebuild (new) | 248 ++++++++++++++++++
2 files changed, 280 insertions(+)
diff --git a/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
new file mode 100644
index 000000000000..e088af2102ed
--- /dev/null
+++ b/dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch
@@ -0,0 +1,32 @@
+From: Eric Joldasov <bratishkaerik@landless-city.net>
+
+Skip standalone test "stack_iterator" that fail on Gentoo Linux x86_64.
+Fails in ReleaseSafe, ReleaseFast and ReleaseSmall, but not in Debug.
+Reported to upstream here https://github.com/ziglang/zig/issues/19944 .
+
+Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
+
+diff --git a/test/standalone/stack_iterator/shared_lib_unwind.zig b/test/standalone/stack_iterator/shared_lib_unwind.zig
+index 57513a49c6..75fddb04c9 100644
+--- a/test/standalone/stack_iterator/shared_lib_unwind.zig
++++ b/test/standalone/stack_iterator/shared_lib_unwind.zig
+@@ -35,6 +35,7 @@ extern fn frame0(
+ ) void;
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
+diff --git a/test/standalone/stack_iterator/unwind.zig b/test/standalone/stack_iterator/unwind.zig
+index 69c463a0c1..40963af63d 100644
+--- a/test/standalone/stack_iterator/unwind.zig
++++ b/test/standalone/stack_iterator/unwind.zig
+@@ -87,6 +87,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {
+ }
+
+ pub fn main() !void {
++ if (true) return;
+ // Disabled until the DWARF unwinder bugs on .aarch64 are solved
+ if (builtin.omit_frame_pointer and comptime builtin.target.isDarwin() and builtin.cpu.arch == .aarch64) return;
+
diff --git a/dev-lang/zig/zig-0.13.0-r2.ebuild b/dev-lang/zig/zig-0.13.0-r2.ebuild
new file mode 100644
index 000000000000..b970092ce4e4
--- /dev/null
+++ b/dev-lang/zig/zig-0.13.0-r2.ebuild
@@ -0,0 +1,248 @@
+# Copyright 2019-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+LLVM_COMPAT=( 18 )
+LLVM_OPTIONAL=1
+
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig
+
+DESCRIPTION="A robust, optimal, and maintainable programming language"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
+if [[ ${PV} == 9999 ]]; then
+ EGIT_REPO_URI="https://github.com/ziglang/zig.git"
+ inherit git-r3
+else
+ VERIFY_SIG_METHOD=minisig
+ VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
+ inherit verify-sig
+
+ SRC_URI="
+ https://ziglang.org/download/${PV}/${P}.tar.xz
+ verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
+ https://codeberg.org/BratishkaErik/distfiles/releases/download/dev-lang%2Fzig-${PV}/${P}-llvm-18.1.8-r6-fix.patch
+ "
+ KEYWORDS="~amd64 ~arm ~arm64"
+
+ BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
+fi
+
+# project itself: MIT
+# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
+# Files that are unnecessary for cross-compilation are removed by upstream
+# and therefore their licenses (if any special) are not included.
+# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
+# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
+# lib/libc/musl: MIT BSD-2
+# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
+# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
+LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
+SLOT="${ZIG_SLOT}"
+IUSE="doc +llvm"
+REQUIRED_USE="
+ !llvm? ( !doc )
+ llvm? ( ${LLVM_REQUIRED_USE} )
+"
+
+# Used by both "cmake" and "zig" eclasses.
+BUILD_DIR="${WORKDIR}/${P}_build"
+
+# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
+# (non-LLVM backends don't require these)
+# They are not required "on their own", so please don't add them here.
+# You can check https://github.com/ziglang/zig-bootstrap in future, to see
+# options that are passed to LLVM CMake building (excluding "static" ofc).
+DEPEND="
+ llvm? (
+ $(llvm_gen_dep '
+ llvm-core/clang:${LLVM_SLOT}
+ llvm-core/lld:${LLVM_SLOT}
+ llvm-core/llvm:${LLVM_SLOT}[zstd]
+ ')
+ )
+"
+BDEPEND+="
+ ${DEPEND}
+"
+RDEPEND="${DEPEND}"
+IDEPEND="app-eselect/eselect-zig"
+
+DOCS=( "README.md" "doc/build.zig.zon.md" )
+
+PATCHES=(
+ "${FILESDIR}/zig-0.13.0-test-std-kernel-version.patch"
+ "${FILESDIR}/zig-0.13.0-skip-test-stack_iterator.patch"
+ "${DISTDIR}/${P}-llvm-18.1.8-r6-fix.patch"
+)
+
+# zig.eclass does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+
+# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
+# Zig uses self-hosted compiler only
+CHECKREQS_MEMORY="4G"
+
+pkg_setup() {
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig_pkg_setup
+
+ export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
+
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
+ check-reqs_pkg_setup
+}
+
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ if use verify-sig; then
+ verify-sig_verify_detached "${DISTDIR}"/${P}.tar.xz{,.minisig}
+ fi
+ fi
+ zig_src_unpack
+}
+
+src_prepare() {
+ if use llvm; then
+ cmake_src_prepare
+ else
+ # Sync with zig_src_prepare
+ default_src_prepare
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+ # "--system" mode is not used during bootstrap.
+ fi
+
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
+
+src_configure() {
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET="$(zig-utils_c_env_to_zig_target "${CBUILD:-${CHOST}}" "${CFLAGS}"})"
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
+ )
+ fi
+
+ zig_src_configure
+
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE="${ZIG_HOST_AS_TARGET}"
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
+}
+
+src_compile() {
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
+
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE="${ZIG_HOST_AS_TARGET}" CC="${native_cc}" edo ./bootstrap
+ fi
+
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig_src_compile --prefix "${BUILD_DIR}/stage3/"
+
+ ./stage3/bin/zig env || die "Zig compilation failed"
+
+ if use doc; then
+ ZIG_EXE="./stage3/bin/zig" zig_src_compile langref --prefix "${S}/docgen/"
+ fi
+}
+
+src_test() {
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./stage3/bin/zig" zig_src_test -Dskip-non-native
+}
+
+src_install() {
+ use doc && local HTML_DOCS=( "docgen/doc/langref.html" )
+
+ ZIG_EXE="./zig2" zig_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
+
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
+ mv lib/zig/ lib2/ || die
+ rm -rf lib/ || die
+ mv lib2/ lib/ || die
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
+}
+
+pkg_postinst() {
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
+
+ if ! use llvm; then
+ elog "Currently, Zig built without LLVM support lacks some"
+ elog "important features such as most optimizations, @cImport, etc."
+ elog "They are listed under \"Building from Source without LLVM\""
+ elog "section of the README file from \"/usr/share/doc/${PF}\" ."
+ fi
+}
+
+pkg_postrm() {
+ eselect zig update ifunset || die
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v3 4/5] dev-lang/zig: sync 9999 with 0.13.0-r2
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
` (2 preceding siblings ...)
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 3/5] dev-lang/zig: add 0.13.0-r2 Eric Joldasov
@ 2024-12-13 20:07 ` Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 5/5] sys-fs/ncdu: add 2.7-r1 Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-12-13 20:07 UTC (permalink / raw
To: gentoo-dev; +Cc: Eric Joldasov
From: Eric Joldasov <bratishkaerik@getgoogleoff.me>
* Update to use zig-utils and zig eclasses instead of local
get_zig_mcpu etc. functions.
* "stage3" compilation is unified by combining build.zig options,
now both cmake (+llvm) and bootstrap.c (-llvm) build up to "zig2"
target, after that we use zig.eclass with common options.
* Before migrating to the zig.eclass, test steps in src_test
have been ran sequentially in for-loop, which allowed logic inside
each step to ran parallelly but not several steps at a time. Now we
use upstream "test" step instead of separately calling all dependant
steps, so that build system can now ran all of them paralelly.
This means time spent in `src_test` is now significantly shorter.
* "zig2" in both scenarios now has explicit target which is set by
using zig-utils.eclass functions on a CBUILD/CHOST. This allows us
to skip convertion logic in CMake and bootstrap.c, so that instead
of patching them we can just update converter in zig-utils.eclass
and unify target behaviour.
* Disable autodocs generation for "std" module, since it can now
be generated on-fly with `zig std` command.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
dev-lang/zig/zig-9999.ebuild | 243 ++++++++++++++++++-----------------
1 file changed, 125 insertions(+), 118 deletions(-)
diff --git a/dev-lang/zig/zig-9999.ebuild b/dev-lang/zig/zig-9999.ebuild
index 858ec3be9405..4f0358a96629 100644
--- a/dev-lang/zig/zig-9999.ebuild
+++ b/dev-lang/zig/zig-9999.ebuild
@@ -1,234 +1,241 @@
# Copyright 2019-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
LLVM_COMPAT=( 19 )
LLVM_OPTIONAL=1
-inherit check-reqs cmake edo llvm-r1 toolchain-funcs
+ZIG_SLOT="$(ver_cut 1-2)"
+ZIG_OPTIONAL=1
+
+inherit check-reqs cmake flag-o-matic edo llvm-r1 toolchain-funcs zig
DESCRIPTION="A robust, optimal, and maintainable programming language"
-HOMEPAGE="https://ziglang.org/"
+HOMEPAGE="https://ziglang.org/ https://github.com/ziglang/zig/"
if [[ ${PV} == 9999 ]]; then
EGIT_REPO_URI="https://github.com/ziglang/zig.git"
inherit git-r3
else
VERIFY_SIG_METHOD=minisig
VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/minisig-keys/zig-software-foundation.pub
inherit verify-sig
SRC_URI="
https://ziglang.org/download/${PV}/${P}.tar.xz
verify-sig? ( https://ziglang.org/download/${PV}/${P}.tar.xz.minisig )
"
KEYWORDS="~amd64 ~arm ~arm64"
BDEPEND="verify-sig? ( sec-keys/minisig-keys-zig-software-foundation )"
fi
# project itself: MIT
# There are bunch of projects under "lib/" folder that are needed for cross-compilation.
# Files that are unnecessary for cross-compilation are removed by upstream
# and therefore their licenses (if any special) are not included.
# lib/libunwind: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxxabi: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libcxx: Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )
# lib/libc/wasi: || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain
# lib/libc/musl: MIT BSD-2
# lib/libc/mingw: ZPL public-domain BSD-2 ISC HPND
# lib/libc/glibc: BSD HPND ISC inner-net LGPL-2.1+
LICENSE="MIT Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT ) || ( Apache-2.0-with-LLVM-exceptions Apache-2.0 MIT BSD-2 ) public-domain BSD-2 ZPL ISC HPND BSD inner-net LGPL-2.1+"
-SLOT="$(ver_cut 1-2)"
+SLOT="${ZIG_SLOT}"
IUSE="doc +llvm"
REQUIRED_USE="
!llvm? ( !doc )
llvm? ( ${LLVM_REQUIRED_USE} )
"
-BUILD_DIR="${S}/build"
+# Used by both "cmake" and "zig" eclasses.
+BUILD_DIR="${WORKDIR}/${P}_build"
# Zig requires zstd and zlib compression support in LLVM, if using LLVM backend.
# (non-LLVM backends don't require these)
# They are not required "on their own", so please don't add them here.
# You can check https://github.com/ziglang/zig-bootstrap in future, to see
# options that are passed to LLVM CMake building (excluding "static" ofc).
DEPEND="
llvm? (
$(llvm_gen_dep '
llvm-core/clang:${LLVM_SLOT}
llvm-core/lld:${LLVM_SLOT}
llvm-core/llvm:${LLVM_SLOT}[zstd]
')
)
"
-
-RDEPEND="
+BDEPEND+="
${DEPEND}
"
-
+RDEPEND="${DEPEND}"
IDEPEND="app-eselect/eselect-zig"
-# see https://github.com/ziglang/zig/issues/3382
-# For now, Zig Build System doesn't support enviromental CFLAGS/LDFLAGS/etc.
-QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
+DOCS=( "README.md" "doc/build.zig.zon.md" )
-RESTRICT="!llvm? ( test )"
+# zig.eclass does not set this for us since we use ZIG_OPTIONAL=1
+QA_FLAGS_IGNORED="usr/.*/zig/${PV}/bin/zig"
# Since commit https://github.com/ziglang/zig/commit/e7d28344fa3ee81d6ad7ca5ce1f83d50d8502118
# Zig uses self-hosted compiler only
CHECKREQS_MEMORY="4G"
-ctarget_to_zigtarget() {
- # Zig's Target Format: arch-os-abi
- local CTARGET="${CTARGET:-${CHOST}}"
-
- local ZIG_ARCH
- case "${CTARGET%%-*}" in
- i?86) ZIG_ARCH=x86;;
- sparcv9) ZIG_ARCH=sparc64;;
- *) ZIG_ARCH="${CTARGET%%-*}";; # Same as in CHOST
- esac
-
- local ZIG_OS
- case "${CTARGET}" in
- *linux*) ZIG_OS=linux;;
- *apple*) ZIG_OS=macos;;
- esac
-
- local ZIG_ABI
- case "${CTARGET##*-}" in
- gnu) ZIG_ABI=gnu;;
- solaris*) ZIG_OS=solaris ZIG_ABI=none;;
- darwin*) ZIG_ABI=none;;
- *) ZIG_ABI="${CTARGET##*-}";; # Same as in CHOST
- esac
-
- echo "${ZIG_ARCH}-${ZIG_OS}-${ZIG_ABI}"
-}
-
-get_zig_mcpu() {
- local ZIG_DEFAULT_MCPU=native
- tc-is-cross-compiler && ZIG_DEFAULT_MCPU=baseline
- echo "${ZIG_MCPU:-${ZIG_DEFAULT_MCPU}}"
-}
-
-get_zig_target() {
- local ZIG_DEFAULT_TARGET=native
- tc-is-cross-compiler && ZIG_DEFAULT_TARGET="$(ctarget_to_zigtarget)"
- echo "${ZIG_TARGET:-${ZIG_DEFAULT_TARGET}}"
-}
-
pkg_setup() {
- # Useful for debugging and a little bit more deterministic.
- export ZIG_LOCAL_CACHE_DIR="${T}/zig-local-cache"
- export ZIG_GLOBAL_CACHE_DIR="${T}/zig-global-cache"
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig_pkg_setup
export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
- use llvm && llvm-r1_pkg_setup
+ if use llvm; then
+ tc-is-cross-compiler && die "USE=llvm is not yet supported when cross-compiling"
+ llvm-r1_pkg_setup
+ fi
+
check-reqs_pkg_setup
}
-src_configure() {
- if ! use llvm; then
- mkdir -p "${BUILD_DIR}/stage3" || die
- # Currently, Zig without LLVM extensions lacks most optimizations.
- export ZIG_BOOTSTRAP_STAGE3_FLAGS=(
- -Dtarget="$(get_zig_target)"
- -Dcpu="$(get_zig_mcpu)"
- -Doptimize=Debug
- -Dstd-docs=false
- -Dno-langref
- -Denable-llvm=false
- -Dforce-link-libc
- )
- return
+src_unpack() {
+ if [[ ${PV} == 9999 ]]; then
+ git-r3_src_unpack
+ else
+ if use verify-sig; then
+ verify-sig_verify_detached "${DISTDIR}"/${P}.tar.xz{,.minisig}
+ fi
+ fi
+ zig_src_unpack
+}
+
+src_prepare() {
+ if use llvm; then
+ cmake_src_prepare
+ else
+ # Sync with zig_src_prepare
+ default_src_prepare
+ mkdir -p "${BUILD_DIR}" || die
+ einfo "BUILD_DIR: \"${BUILD_DIR}\""
+ # "--system" mode is not used during bootstrap.
fi
- local mycmakeargs=(
- -DZIG_USE_CCACHE=OFF
- -DZIG_SHARED_LLVM=ON
- -DZIG_TARGET_TRIPLE="$(get_zig_target)"
- -DZIG_TARGET_MCPU="$(get_zig_mcpu)"
- -DZIG_USE_LLVM_CONFIG=ON
- -DCMAKE_PREFIX_PATH="$(get_llvm_prefix)"
- -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
- )
+ # Remove "limit memory usage" flags, it's already verified by
+ # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
+ # according to CI OOM failures, which are not applicable to normal Gentoo build.
+ sed -i -e '/\.max_rss = .*,/d' build.zig || die
+}
- cmake_src_configure
+src_configure() {
+ # Has no effect on final binary and only causes failures during bootstrapping.
+ filter-lto
+
+ # Used during bootstrapping. stage1/stage2 have limited functionality
+ # and can't resolve native target, so we pass target in exact form.
+ declare -r -g ZIG_HOST_AS_TARGET="$(zig-utils_c_env_to_zig_target "${CBUILD:-${CHOST}}" "${CFLAGS}"})"
+
+ # Note that if we are building with CMake, "my_zbs_args"
+ # are used only after compiling zig2.
+ local my_zbs_args=(
+ --zig-lib-dir "${S}/lib/"
+ # Will be a subdir under ZIG_SYS_INSTALL_DEST.
+ --prefix-lib-dir lib/
+
+ # These are built separately
+ -Dno-langref
+ -Dstd-docs=false
+
+ --release=fast
+ )
+ if use llvm; then
+ my_zbs_args+=(
+ -Denable-llvm=true
+ -Dstatic-llvm=false
+ -Dconfig_h="${BUILD_DIR}/config.h"
+ )
+ else
+ my_zbs_args+=(
+ -Denable-llvm=false
+ )
+ fi
+
+ zig_src_configure
+
+ if use llvm; then
+ # Build for native only, it's for zig2 (build-time executable)
+ # LLVM from BDEPEND
+ local mycmakeargs=(
+ -DZIG_SHARED_LLVM=ON
+ -DZIG_USE_LLVM_CONFIG=ON
+
+ -DZIG_TARGET_TRIPLE=native
+ -DZIG_TARGET_MCPU=native
+ -DZIG_HOST_TARGET_TRIPLE="${ZIG_HOST_AS_TARGET}"
+
+ -DCMAKE_PREFIX_PATH="$(get_llvm_prefix -b)"
+ -DCMAKE_INSTALL_PREFIX="${ZIG_SYS_INSTALL_DEST}"
+ )
+
+ cmake_src_configure
+ fi
}
src_compile() {
- # Remove "limit memory usage" flags, it's already verified by
- # CHECKREQS_MEMORY and causes unneccessary errors. Upstream set them
- # according to CI OOM failures, which are higher than during Gentoo build.
- sed -i -e '/\.max_rss = .*,/d' build.zig || die
+ if use llvm; then
+ cmake_build zig2
+ else
+ cd "${BUILD_DIR}" || die
+ ln -s "${S}/stage1/" . || die
+ ln -s "${S}/src/" . || die
+ ln -s "${S}/lib/" . || die
- if ! use llvm; then
- $(tc-getCC) -o bootstrap bootstrap.c || die "Zig's bootstrap.c compilation failed"
- edob ./bootstrap
- edo ./zig2 build install --prefix "${BUILD_DIR}/stage3/" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- return
+ local native_cc="$(tc-getBUILD_CC)"
+ "${native_cc}" -o bootstrap "${S}/bootstrap.c" || die "Zig's bootstrap.c compilation failed"
+ ZIG_HOST_TARGET_TRIPLE="${ZIG_HOST_AS_TARGET}" CC="${native_cc}" edo ./bootstrap
fi
- cmake_src_compile
+ cd "${BUILD_DIR}" || die
+ ZIG_EXE="./zig2" zig_src_compile --prefix "${BUILD_DIR}/stage3/"
- "${BUILD_DIR}/stage3/bin/zig" env || die "Zig compilation failed"
+ ./stage3/bin/zig env || die "Zig compilation failed"
if use doc; then
- cd "${BUILD_DIR}" || die
- edo ./stage3/bin/zig build std-docs --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
- edo ./stage3/bin/zig build langref --zig-lib-dir "${BUILD_DIR}/stage3/lib/zig/" --prefix "${S}/docgen/"
+ ZIG_EXE="./stage3/bin/zig" zig_src_compile langref --prefix "${S}/docgen/"
fi
}
src_test() {
cd "${BUILD_DIR}" || die
- local ZIG_TEST_ARGS="-Dstatic-llvm=false -Denable-llvm -Dskip-non-native \
- -Doptimize=ReleaseSafe -Dtarget=$(get_zig_target) -Dcpu=$(get_zig_mcpu)"
- local ZIG_TEST_STEPS=(
- test-fmt test-cases test-behavior test-c-import test-compiler-rt test-universal-libc test-compare-output
- test-standalone test-c-abi test-link test-stack-traces test-cli test-asm-link test-translate-c
- test-run-translated-c test-std
- )
-
- local step
- for step in "${ZIG_TEST_STEPS[@]}" ; do
- edob ./stage3/bin/zig build ${step} ${ZIG_TEST_ARGS}
- done
+ ZIG_EXE="./stage3/bin/zig" zig_src_test -Dskip-non-native
}
src_install() {
- local DOCS=( "README.md" "doc/build.zig.zon.md" )
- use doc && local HTML_DOCS=( "docgen/doc/langref.html" "docgen/doc/std" )
+ use doc && local HTML_DOCS=( "docgen/doc/langref.html" )
- if ! use llvm; then
- DESTDIR="${D}" edo ./zig2 build install --prefix "${ZIG_SYS_INSTALL_DEST}" "${ZIG_BOOTSTRAP_STAGE3_FLAGS[@]}"
- einstalldocs
- else
- cmake_src_install
- fi
+ ZIG_EXE="./zig2" zig_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
- cd "${ED}/usr/$(get_libdir)/zig/${PV}/" || die
+ cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
mv lib/zig/ lib2/ || die
rm -rf lib/ || die
mv lib2/ lib/ || die
- dosym -r "/usr/$(get_libdir)/zig/${PV}/bin/zig" "/usr/bin/zig-${PV}"
+ dosym -r "${ZIG_SYS_INSTALL_DEST}/bin/zig" /usr/bin/zig-${PV}
}
pkg_postinst() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
+
+ elog "Starting from 0.12.0, Zig no longer installs"
+ elog "precompiled standard library documentation."
+ elog "Instead, you can call \`zig std\` to compile it on-the-fly."
+ elog "It reflects all edits in standard library automatically."
+ elog "See \`zig std --help\` for more information."
+ elog "More details here: https://ziglang.org/download/0.12.0/release-notes.html#Redesign-How-Autodoc-Works"
if ! use llvm; then
elog "Currently, Zig built without LLVM support lacks some"
elog "important features such as most optimizations, @cImport, etc."
elog "They are listed under \"Building from Source without LLVM\""
elog "section of the README file from \"/usr/share/doc/${PF}\" ."
- elog "It's recommended to use C backend directly with this stage2 build."
fi
}
pkg_postrm() {
- eselect zig update ifunset
+ eselect zig update ifunset || die
}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH v3 5/5] sys-fs/ncdu: add 2.7-r1
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
` (3 preceding siblings ...)
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 4/5] dev-lang/zig: sync 9999 with 0.13.0-r2 Eric Joldasov
@ 2024-12-13 20:07 ` Eric Joldasov
4 siblings, 0 replies; 29+ messages in thread
From: Eric Joldasov @ 2024-12-13 20:07 UTC (permalink / raw
To: gentoo-dev
Now uses `zig.eclass`.
Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
---
sys-fs/ncdu/ncdu-2.7-r1.ebuild (new) | 52 ++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/sys-fs/ncdu/ncdu-2.7-r1.ebuild b/sys-fs/ncdu/ncdu-2.7-r1.ebuild
new file mode 100644
index 000000000000..96b32f45abb3
--- /dev/null
+++ b/sys-fs/ncdu/ncdu-2.7-r1.ebuild
@@ -0,0 +1,52 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/yoranheling.asc
+
+ZIG_SLOT="0.13"
+inherit verify-sig zig
+
+DESCRIPTION="NCurses Disk Usage"
+HOMEPAGE="https://dev.yorhel.nl/ncdu https://code.blicky.net/yorhel/ncdu"
+SRC_URI="
+ https://dev.yorhel.nl/download/${P}.tar.gz
+ verify-sig? ( https://dev.yorhel.nl/download/${P}.tar.gz.asc )
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~amd64"
+
+BDEPEND="verify-sig? ( sec-keys/openpgp-keys-yorhel )"
+DEPEND="
+ app-arch/zstd:=
+ sys-libs/ncurses:=[unicode(+)]
+"
+RDEPEND="${DEPEND}"
+
+DOCS=( "README.md" "ChangeLog" )
+
+src_unpack() {
+ if use verify-sig; then
+ verify-sig_verify_detached "${DISTDIR}"/${P}.tar.gz{,.asc}
+ fi
+ zig_src_unpack
+}
+
+src_configure() {
+ local my_zbs_args=(
+ -Dpie=true
+ # Upstream recommends this default:
+ --release=fast
+ )
+
+ zig_src_configure
+}
+
+src_install() {
+ zig_src_install
+
+ doman ncdu.1
+}
--
2.47.0
^ permalink raw reply related [flat|nested] 29+ messages in thread
end of thread, other threads:[~2024-12-13 20:10 UTC | newest]
Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-24 1:46 [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
2024-10-24 7:32 ` Ulrich Müller
2024-10-24 7:38 ` Matt Jolly
2024-10-24 8:50 ` Florian Schmaus
2024-10-24 13:00 ` Michael Orlitzky
2024-10-24 1:46 ` [gentoo-dev] [PATCH 2/5] zig-build.eclass: " Eric Joldasov
2024-10-24 9:16 ` Maciej Barć
2024-10-24 1:46 ` [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
2024-10-24 1:46 ` [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 2/5] zig-build.eclass: " Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
2024-10-25 21:20 ` [gentoo-dev] [PATCH 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 0/5] Ziglang eclasses for 0.13+ Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 1/5] zig-toolchain.eclass: new eclass Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 2/5] zig-build.eclass: " Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 3/5] dev-lang/zig: add 0.13.0-r1 Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 4/5] dev-lang/zig: sync 9999 with 0.13.0-r1 Eric Joldasov
2024-10-25 21:33 ` [gentoo-dev] [PATCH v2 5/5] sys-fs/ncdu: add 2.6-r1 Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 0/5] Zig: new eclasses, rewrite existing ebuilds to use them Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 1/5] zig-utils.eclass: new eclass Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 2/5] zig.eclass: " Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 3/5] dev-lang/zig: add 0.13.0-r2 Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 4/5] dev-lang/zig: sync 9999 with 0.13.0-r2 Eric Joldasov
2024-12-13 20:07 ` [gentoo-dev] [PATCH v3 5/5] sys-fs/ncdu: add 2.7-r1 Eric Joldasov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox