mirror of
https://github.com/gentoo-mirror/gentoo.git
synced 2026-08-24 18:58:08 -07:00
zig.eclass: always use absolute path for --prefix argument
Needed for correctness when `build.zig` uses them to manipulate default pathes in compiled artifact. Without `DESTDIR` it would try to install to root directly, so to fix this we set `DESTDIR` where appliable. Co-authored-by: Eric Joldasov <bratishkaerik@landless-city.net> Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net> Closes: https://github.com/gentoo/gentoo/pull/40197 Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
@@ -92,7 +92,7 @@ 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}"
|
||||
declare -r -g 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"
|
||||
@@ -142,7 +142,8 @@ src_configure() {
|
||||
# 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 "${ZIG_SYS_INSTALL_DEST}/"
|
||||
--prefix-lib-dir lib/
|
||||
|
||||
# These are built separately
|
||||
@@ -199,12 +200,12 @@ src_compile() {
|
||||
fi
|
||||
|
||||
cd "${BUILD_DIR}" || die
|
||||
ZIG_EXE="./zig2" zig_src_compile --prefix "${BUILD_DIR}/stage3/"
|
||||
ZIG_EXE="./zig2" zig_src_compile --prefix 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/"
|
||||
ZIG_EXE="./stage3/bin/zig" zig_src_compile langref --prefix docgen/
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -241,9 +242,9 @@ src_test() {
|
||||
}
|
||||
|
||||
src_install() {
|
||||
use doc && local HTML_DOCS=( "docgen/doc/langref.html" )
|
||||
use doc && local HTML_DOCS=( "${BUILD_DIR}/docgen/doc/langref.html" )
|
||||
|
||||
ZIG_EXE="./zig2" zig_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
|
||||
ZIG_EXE="./zig2" zig_src_install
|
||||
|
||||
cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
|
||||
mv lib/zig/ lib2/ || die
|
||||
|
||||
@@ -143,7 +143,8 @@ src_configure() {
|
||||
# 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 "${ZIG_SYS_INSTALL_DEST}/"
|
||||
--prefix-lib-dir lib/
|
||||
|
||||
# These are built separately
|
||||
@@ -283,7 +284,7 @@ src_compile() {
|
||||
./stage3/bin/zig env || die "Zig compilation failed"
|
||||
|
||||
if use doc; then
|
||||
ZIG_EXE="./stage3/bin/zig" zig_src_compile langref --prefix "${S}/docgen/"
|
||||
ZIG_EXE="./stage3/bin/zig" zig_src_compile langref --prefix docgen/
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -321,9 +322,9 @@ src_test() {
|
||||
}
|
||||
|
||||
src_install() {
|
||||
use doc && local HTML_DOCS=( "docgen/doc/langref.html" )
|
||||
use doc && local HTML_DOCS=( "${BUILD_DIR}/docgen/doc/langref.html" )
|
||||
|
||||
ZIG_EXE="./zig2" zig_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
|
||||
ZIG_EXE="./zig2" zig_src_install
|
||||
|
||||
cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
|
||||
mv lib/zig/ lib2/ || die
|
||||
|
||||
@@ -136,7 +136,8 @@ src_configure() {
|
||||
# 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 "${ZIG_SYS_INSTALL_DEST}/"
|
||||
--prefix-lib-dir lib/
|
||||
|
||||
# These are built separately
|
||||
@@ -276,7 +277,7 @@ src_compile() {
|
||||
./stage3/bin/zig env || die "Zig compilation failed"
|
||||
|
||||
if use doc; then
|
||||
ZIG_EXE="./stage3/bin/zig" zig_src_compile langref --prefix "${S}/docgen/"
|
||||
ZIG_EXE="./stage3/bin/zig" zig_src_compile langref --prefix docgen/
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@@ -314,9 +315,9 @@ src_test() {
|
||||
}
|
||||
|
||||
src_install() {
|
||||
use doc && local HTML_DOCS=( "docgen/doc/langref.html" )
|
||||
use doc && local HTML_DOCS=( "${BUILD_DIR}/docgen/doc/langref.html" )
|
||||
|
||||
ZIG_EXE="./zig2" zig_src_install --prefix "${ZIG_SYS_INSTALL_DEST}"
|
||||
ZIG_EXE="./zig2" zig_src_install
|
||||
|
||||
cd "${D}/${ZIG_SYS_INSTALL_DEST}" || die
|
||||
mv lib/zig/ lib2/ || die
|
||||
|
||||
@@ -160,6 +160,8 @@ _zig_set_zbs_uris
|
||||
# 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.
|
||||
# Note: `--prefix` and other relative arguments will
|
||||
# process here as relative to BUILD_DIR.
|
||||
#
|
||||
# Example:
|
||||
# @CODE
|
||||
@@ -292,14 +294,18 @@ zig_init_base_args() {
|
||||
-Dcpu="${ZIG_CPU}"
|
||||
--release=safe
|
||||
|
||||
# We want absolute path here so that it would appear correctly
|
||||
# when embedded to binaries with build.zig, but without DESTDIR
|
||||
# it would try to escape sandbox and install directly to root.
|
||||
#
|
||||
# Therefore, we set DESTDIR each time to be:
|
||||
# 1) BUILD_DIR in phases before `src_install`,
|
||||
# 2) D during `src_install`.
|
||||
--prefix "${EPREFIX}/usr/"
|
||||
--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
|
||||
@@ -486,12 +492,17 @@ zig_src_configure() {
|
||||
# @DESCRIPTION:
|
||||
# Calls "ezig build" with previously set ZBS_ARGS.
|
||||
# Args passed to this function will be passed after ZBS_ARGS.
|
||||
# They can be used to call custom steps or override some
|
||||
# options temporarily like `--prefix`.
|
||||
# Note that `--prefix` and other relative arguments will
|
||||
# process here as relative to BUILD_DIR.
|
||||
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"
|
||||
DESTDIR="${BUILD_DIR}" nonfatal ezig build "${args[@]}" ||
|
||||
die "ZBS: compilation failed"
|
||||
|
||||
popd > /dev/null || die
|
||||
}
|
||||
@@ -504,6 +515,8 @@ zig_src_compile() {
|
||||
# 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.
|
||||
# Note that `--prefix` and other relative arguments will
|
||||
# process here as relative to BUILD_DIR.
|
||||
zig_src_test() {
|
||||
pushd "${BUILD_DIR}" > /dev/null || die
|
||||
|
||||
@@ -525,7 +538,7 @@ zig_src_test() {
|
||||
nonfatal ezig build --list-steps "${args[@]}"
|
||||
); then
|
||||
einfo "ZBS: testing with: ${args[@]}"
|
||||
nonfatal ezig build test "${args[@]}" ||
|
||||
DESTDIR="${BUILD_DIR}" nonfatal ezig build test "${args[@]}" ||
|
||||
die "ZBS: tests failed"
|
||||
else
|
||||
einfo "Test step not found, skipping."
|
||||
@@ -540,6 +553,8 @@ zig_src_test() {
|
||||
# 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".
|
||||
# Note that `--prefix` and other relative arguments will
|
||||
# process here as relative to D.
|
||||
zig_src_install() {
|
||||
pushd "${BUILD_DIR}" > /dev/null || die
|
||||
local args=( "${ZBS_ARGS[@]}" "${@}" )
|
||||
|
||||
Reference in New Issue
Block a user