summaryrefslogtreecommitdiff
path: root/dev-lang/zig
diff options
context:
space:
mode:
Diffstat (limited to 'dev-lang/zig')
-rw-r--r--dev-lang/zig/Manifest4
-rw-r--r--dev-lang/zig/files/zig-0.13.0-skip-test-stack_iterator.patch32
-rw-r--r--dev-lang/zig/zig-0.13.0-r2.ebuild248
-rw-r--r--dev-lang/zig/zig-9999.ebuild235
4 files changed, 404 insertions, 115 deletions
diff --git a/dev-lang/zig/Manifest b/dev-lang/zig/Manifest
index 1bf9498ef41c..258015816825 100644
--- a/dev-lang/zig/Manifest
+++ b/dev-lang/zig/Manifest
@@ -1,8 +1,10 @@
+AUX zig-0.13.0-skip-test-stack_iterator.patch 1443 BLAKE2B 347a7a397c706105456ba83d9511633d3f1a75aa33a06dfccfde457c93af79149c4bb704e0e493a6b69a840784739c34b7a4f570608c368bb84673def0404857 SHA512 7b446efad0a95d3483a570552f3a1df2a535a757e16eb8484571ab1c9fd525b7b68b36ca84fb30bcce77709f9936e4c361ae04362456a60a9f59516824e3a254
AUX zig-0.13.0-test-fmt-no-doc.patch 653 BLAKE2B 92f28d86fde0ce3315b8e7b50dcdf03c1ef8a95964701d3c3c05dc8c16b08f9e327d190e9f9631c2a3a287b8b2945025abbf1b5c75d3bdb3adf719d1a6513703 SHA512 310d356f07505fa44e8425ec32f823eab5e20f9a0144c2e2ecff38e19ac1814d4320430373d4f2fa5ed9cf57000a126089c185fd6336daed8cc7dc0cffc0c023
AUX zig-0.13.0-test-std-kernel-version.patch 1304 BLAKE2B a266cc8d41df8eabc44cc381fe66e5b548d0e10eb0d0098350ddf596602204a77062b8e4632f58250a40781f7a1d5c7e9905c1387ecf7a0c505e330612944f38 SHA512 a62977e3ba675b60866d7cebdc5ff676825e77dac93029d32af403e567b5ae462d49355407f9dbd33843c8b8393d8f05a39de73a8818daf3424df083e0185da6
DIST zig-0.13.0-llvm-18.1.8-r6-fix.patch 45968 BLAKE2B a07c47b22b079d324b200fe84af5c89ffe51a1c81f50ca894a80f9f9db51a9d4119ae51c2e4e84a9b4f0111b2b809978b88adca42480ee800693afbd78f47387 SHA512 148b3f4807763dfb6a4d4e201890fa8204deaf73e620a8b592dfa03b997bc16ed01ea26e4d85f242473e91ccc45b1a06af22f786851f8e26cec1ac821b14efdc
DIST zig-0.13.0.tar.xz 17220728 BLAKE2B f4bbacc2012950c556bebc28fc322fc6424bf20fe118e8362373336b6460e514028978584087f6e7f25ed8b8e6991610edce625676a1dd80c1975c5f9ef48775 SHA512 6f5f31f4ba71a11d8b16c7a5a613e124095e503fa6b02d2b77e5b177674c739287e81d98d96dc261fed24bc836caf196f71c3fcc7a6518387df86ba9e03df4dd
DIST zig-0.13.0.tar.xz.minisig 312 BLAKE2B 2d061257c9c75f9c36b01cfb08dcd2040538a125b9ea2cae8617ae5496e685b165933ce8981494419522b7e19b51fc69a651ecaa4a8930753acf2e4ae3d6e00f SHA512 21c6139c06cba6c5e23a3305fed0c0f1b9b32d9140bd686c26365ce0279d5f53cd081894eaba29f0c1ed51b2e831edf7bd4ae6a7eaee5018a252e312e9b65507
EBUILD zig-0.13.0-r1.ebuild 6212 BLAKE2B dc9966d60858e0c8c9c4a062bc826b502ae56d9432cf447021759976dca3e03d1b8ed7632e210a3f21a5414041d1b490321db970dcffa9181857cc096080577b SHA512 53651f874ee9a26d1d4fd2c6ba5a3d722f1aa086c02d57fed7be6e8e56dcd5dd5746f35c7dfe116cfaf5a008e9033697c8e2fe808f6e4ffc9fb0da357d455b8c
-EBUILD zig-9999.ebuild 6947 BLAKE2B 3e5dfa505821e423d4f2c5a3869d28f7086eee57f2f5f6714bb16c89135f8a0c93dd5a666509b93ce53c31095246b12a7c593711d30cd05babe4340c4ef79d18 SHA512 317c15d456a1a6d505dad24cf111d4228b16537904a52eb7c7a82df3f996f8aa64bd82fd82f5610d891ab10aabaffefe513d5eb527f4d96d5931d71da8288745
+EBUILD zig-0.13.0-r2.ebuild 7263 BLAKE2B e62e6b54292e65fb008e7b005fd87ac1b7dc0caeca7a81c61f45bc3ee03dc18437caef7b320ee2ebf5daefe78799d7a6cde352fe61f4b3397eeee6aef6a9ec0c SHA512 4c535c7407af0bf2f907949e7ae139c06bc864e321829af59a213cc372796f843ebee2b6e449c2eed0b565e3b801521bfc1071487a73d07e5372c4344c16b476
+EBUILD zig-9999.ebuild 6977 BLAKE2B b4c58c01278d130eb0d7bff7bd91c576dda5de97f426ceb55139b0e298836f915f9cb53a39fee3d01de57e2b310d3e2f32d4a16fcf44f22b75a89efdf057f10a SHA512 d998a5b2bee29dd1bf4328858187bd65ac494df53d1e612b61bdaac54c1eba25270a6458c4978e96253ddaa9b23567530b6cec09779f27f56193139f7d51a0e0
MISC metadata.xml 633 BLAKE2B 46cca8909b0b7d65213dee9c7aa7a2c4b5b529734e3bde4f65320074bc38d68420dfaa28041873c7c2c0f1127aca327e32c103c06ab1b5d5ee0e485cb33bb133 SHA512 1d030ca79a3d49b6f573e7995e6f6ef50a6e33ea7e2755a678625645d5b0587f7877a357ea71905034b7029c8c6315b89ebdb5313102b6638b16c467e2ba1864
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
+}
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
@@ -6,10 +6,13 @@ 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
@@ -39,14 +42,15 @@ fi
# 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)
@@ -62,173 +66,176 @@ DEPEND="
')
)
"
-
-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}"
-}
+pkg_setup() {
+ # Skip detecting zig executable.
+ ZIG_EXE="not-applicable" ZIG_VER="${PV}" zig_pkg_setup
-get_zig_mcpu() {
- local ZIG_DEFAULT_MCPU=native
- tc-is-cross-compiler && ZIG_DEFAULT_MCPU=baseline
- echo "${ZIG_MCPU:-${ZIG_DEFAULT_MCPU}}"
-}
+ 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
-get_zig_target() {
- local ZIG_DEFAULT_TARGET=native
- tc-is-cross-compiler && ZIG_DEFAULT_TARGET="$(ctarget_to_zigtarget)"
- echo "${ZIG_TARGET:-${ZIG_DEFAULT_TARGET}}"
+ check-reqs_pkg_setup
}
-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"
+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
+}
- export ZIG_SYS_INSTALL_DEST="${EPREFIX}/usr/$(get_libdir)/zig/${PV}"
+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
- use llvm && llvm-r1_pkg_setup
- check-reqs_pkg_setup
+ # 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
+ # 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
- -Dforce-link-libc
)
- 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_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
- cmake_src_configure
+ -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
}