Skip to content

Commit

Permalink
Install baselayout rather than duplicating dir/symlink behaviour here
Browse files Browse the repository at this point in the history
crossdev environments need to support merged-usr now, especially now
that the profile can be selected. The logic around this is messy and
best handled by the baselayout package when it is supported by the arch.
This package now gets installed immediately before binutils. It means a
few small extra files get installed, but that's a small price to pay. We
could INSTALL_MASK them, but that would just add more complexity.

Signed-off-by: James Le Cuirot <[email protected]>
  • Loading branch information
chewi committed Jan 10, 2025
1 parent e76f567 commit d77c2dc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/crossdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ jobs:
- target: powerpc64-unknown-linux-musl
- target: powerpc64le-unknown-linux-gnu
- target: riscv32-unknown-linux-gnu
args: --profile default/linux/riscv/23.0/rv32/ilp32
# busybox fails to build: `‘SYS_settimeofday’ undeclared`.
# - target: riscv32-unknown-linux-musl
- target: riscv64-unknown-linux-gnu
args: --profile default/linux/riscv/23.0/rv64/lp64
- target: riscv64-unknown-linux-musl
args: --profile default/linux/riscv/23.0/rv64/lp64d/musl
# glibc fails to build: `no support for pre-v8 sparc`.
# - target: sparc-unknown-linux-gnu
- target: sparc64-unknown-linux-gnu
Expand Down
97 changes: 28 additions & 69 deletions crossdev
Original file line number Diff line number Diff line change
Expand Up @@ -1616,52 +1616,6 @@ hr
xmkdir -p "${EPREFIX}"/usr/${CTARGET}
LLVM="${LLVM}" emerge-wrapper --target "${CTARGET}" --init --profile "${PROFILE}" || exit 1

#############################################################
### Create directories usually created by sys-apps/baselayout
###
### Why we do that at all:
### For multilib-aware targets (ppc64, s390x, sparc64, x86_64), Gentoo
### normally uses libdir=lib64.
### For crossdev, it means /lib and /usr/lib does not get created at all
### but gcc relies on their presence by refering to =/lib64 as
### =/usr/lib/../lib64 when builds itself (see https://bugs.gentoo.org/652724)
###
### Thus we create non-symlinked layout early.
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib
###
### We need some special riscv sauce here similar as in baselayout. Ugly.
### step 1: set up all multilib libdirs
### step 2: set up the compat symlink of the default abi for non-multilib
case ${CTARGET} in
riscv*)
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib64
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib64/lp64
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib64/lp64d
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib64
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib64/lp64
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib64/lp64d
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib32
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib32/ilp32
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib32/ilp32d
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib32
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib32/ilp32
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib32/ilp32d
;;&
riscv64*)
rmdir "${EPREFIX}"/usr/${CTARGET}/lib64/${DEFAULT_ABI}
ln -s . "${EPREFIX}"/usr/${CTARGET}/lib64/${DEFAULT_ABI}
rmdir "${EPREFIX}"/usr/${CTARGET}/usr/lib64/${DEFAULT_ABI}
ln -s . "${EPREFIX}"/usr/${CTARGET}/usr/lib64/${DEFAULT_ABI}
;;
riscv32*)
rmdir "${EPREFIX}"/usr/${CTARGET}/lib32/${DEFAULT_ABI}
ln -s ../lib "${EPREFIX}"/usr/${CTARGET}/lib32/${DEFAULT_ABI}
rmdir "${EPREFIX}"/usr/${CTARGET}/usr/lib32/${DEFAULT_ABI}
ln -s ../lib "${EPREFIX}"/usr/${CTARGET}/usr/lib32/${DEFAULT_ABI}
;;
esac

# HOSTCC is used by linux-headers to compile fixdeps program for CBUILD
if [[ "${LLVM}" == "yes" ]] ; then
cat <<-EOF > "${CONFIGROOT}/env/${CROSSDEV_OVERLAY_CATEGORY}/llvm.conf"
Expand Down Expand Up @@ -1706,30 +1660,31 @@ set_eopts_on_pkg_status() {
EOPTS=${EOPTS_UP}
}

doemerge() {
do_emerge_cross() {
local category="${CROSSDEV_OVERLAY_CATEGORY}"
local pn=$1
local atom="${category}/${pn}"

[[ ${pn} == "[none]" ]] && return 0

set_use ${pn} ${USE} $( [[ ${MULTILIB_USE} == "no" ]] && echo - )multilib
do_emerge "${atom}" "${CROSSDEV_OVERLAY_CATEGORY_PREFIX}${2:-${pn}}"
}

[[ ${INIT_TARGET_ONLY} == "yes" ]] && return 0
do_emerge() {
local atom=$1
local pn=${1##*/}

local logfile=${PORT_LOGDIR}/${category}
[[ -z $2 ]] \
&& logfile=${logfile}-${pn}.log \
|| logfile=${logfile}-$2.log
[[ ${INIT_TARGET_ONLY} == "yes" ]] && return 0

local logfile="${PORT_LOGDIR}/cross-${CTARGET}-${2:-${pn}}.log"
einfo "Log: ${logfile}"
ebegin "Emerging ${CROSSDEV_OVERLAY_CATEGORY_PREFIX}${2:-${pn}}"
ebegin "Emerging ${2:-${pn}}"

if has -v ${UOPTS} || has -p ${UOPTS} || has -vp ${UOPTS} || has -pv ${UOPTS} ; then
SHOW_FAIL_LOG="no"
emerge ${atom} ${EOPTS} 2>&1 | tee "${logfile}"
${EMERGE:-emerge} ${atom} ${EOPTS} 2>&1 | tee "${logfile}"
else
emerge ${atom} ${EOPTS} >& "${logfile}"
${EMERGE:-emerge} ${atom} ${EOPTS} >& "${logfile}"
fi
local _pipestatus=${PIPESTATUS[*]}
if [[ "${_pipestatus// /}" -ne 0 ]] ; then
Expand Down Expand Up @@ -1759,7 +1714,7 @@ doemerge() {
# gcc wanting updated mpfr/gmp). Don't use --oneshot anymore to
# follow normal emerge behavior; people can pass the -1 to portage
# themselves if they want that.
EOPTS_DEF="${UOPTS}"
EOPTS_DEF="--buildpkg=n ${UOPTS}"
EOPTS_UP="${EOPTS_DEF} -u"
EOPTS=${EOPTS_UP}
# keep things like --ask from screwing us up
Expand Down Expand Up @@ -1794,6 +1749,10 @@ USE="${USE} -selinux"

if ! ex_fast ; then

# stage 0: baselayout
PORTAGE_CONFIGROOT="${EROOT}/usr/${CTARGET}" portageq best_visible "${EROOT}/usr/${CTARGET}" sys-apps/baselayout >/dev/null &&
USE+=" build" EMERGE="${CTARGET}-emerge" do_emerge sys-apps/baselayout

# stage 0: binutils
if [[ "${LLVM}" == "yes" ]] ; then
if ! portageq has_version / "llvm-core/llvm" ; then
Expand Down Expand Up @@ -1826,9 +1785,9 @@ if ! ex_fast ; then

[[ ${supported_arch} -eq 0 ]] && die "Target architecture not supported by installed LLVM toolchain"

USE="${CUSE}" doemerge ${CPKG}
USE="${CUSE}" do_emerge_cross ${CPKG}
else
USE="${BUSE}" doemerge ${BPKG}
USE="${BUSE}" do_emerge_cross ${BPKG}
fi

# stage1: bare C compiler
Expand All @@ -1839,7 +1798,7 @@ if ! ex_fast ; then
# install kernel headers (since the C library often uses them)
USE="${KUSE} ${USE} headers-only" \
CROSSCOMPILE_OPTS="headers-only" \
doemerge ${KPKG} ${KPKG}-quick
do_emerge_cross ${KPKG} ${KPKG}-quick

if [[ -n ${LPKG} ]] ; then
# install C library headers
Expand All @@ -1849,7 +1808,7 @@ if ! ex_fast ; then
USE="${LUSE} ${USE} ${LUSE_DISABLE} headers-only" \
CROSSCOMPILE_OPTS="headers-only" \
EOPTS="${EOPTS} --nodeps" \
doemerge ${LPKG} ${LPKG}-headers
do_emerge_cross ${LPKG} ${LPKG}-headers
fi
fi

Expand All @@ -1858,11 +1817,11 @@ if ! ex_fast ; then
# Compile compiler-rt
USE="${RUSE} ${USE}" \
CROSSCOMPILE_OPTS="" \
doemerge ${RPKG}
do_emerge_cross ${RPKG}
else
USE="${GUSE} ${USE} ${GUSE_DISABLE_STAGE_1}" \
CROSSCOMPILE_OPTS="" \
doemerge ${GPKG} ${GPKG}-stage1
do_emerge_cross ${GPKG} ${GPKG}-stage1
fi

fi
Expand All @@ -1873,7 +1832,7 @@ if ! ex_fast ; then

USE="${KUSE} ${USE}" \
CROSSCOMPILE_OPTS="" \
doemerge ${KPKG}
do_emerge_cross ${KPKG}
fi

# stage3: full C library (headers/libs/etc...)
Expand All @@ -1884,24 +1843,24 @@ if ! ex_fast ; then

USE="${LUSE} ${USE} ${LUSE_DISABLE}" \
CROSSCOMPILE_OPTS="" \
doemerge ${LPKG}
do_emerge_cross ${LPKG}
fi

# stage4: full compiler (C/C++/etc...)
if is_s4 && [[ "${LLVM}" != "yes" ]] ; then
EOPTS="${EOPTS_UP} --newuse" \
USE="${GUSE} ${USE} ${GUSE_DISABLE_STAGE_2}" \
doemerge ${GPKG} ${GPKG}-stage2
do_emerge_cross ${GPKG} ${GPKG}-stage2
fi
fi

# all the extra things (like debuggers)
EOPTS="${EOPTS_UP} --newuse"
ex_gcc && USE="${GUSE} ${USE}" doemerge ${GPKG} ${GPKG}-extra
ex_gdb && USE="${DUSE} ${USE}" doemerge ${DPKG}
ex_gcc && USE="${GUSE} ${USE}" do_emerge_cross ${GPKG} ${GPKG}-extra
ex_gdb && USE="${DUSE} ${USE}" do_emerge_cross ${DPKG}
if ex_pkgs ; then
for pkg in "${XPKGS[@]}" ; do
doemerge "${pkg#*/}"
do_emerge_cross "${pkg#*/}"
done
fi

Expand Down
8 changes: 7 additions & 1 deletion scripts/container_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Options:
--skip-system Skip emerging the @system set after setting up crossdev.
--tag <tag> Specify the container tag to use. Default is 'latest'.
--target <target> Specify the target architecture for crossdev. Required.
--profile <profile> Specify the Portage profile for crossdev. Default is 'embedded'.
-h, --help Show this help message and exit.
Environment Variables:
Expand Down Expand Up @@ -55,6 +56,7 @@ CONTAINER_URI=${CONTAINER_URI:-"docker.io/gentoo/stage3"}
CONTAINER_TAG="latest"
EMERGE_SYSTEM=1
TOPDIR=$(git rev-parse --show-toplevel)
unset PROFILE

remove_container || true
trap "remove_container" EXIT
Expand All @@ -65,6 +67,10 @@ while [[ $# -gt 0 ]]; do
print_help
exit 0
;;
--profile)
PROFILE="$2"
shift 2
;;
--skip-system)
EMERGE_SYSTEM=0
shift 1
Expand Down Expand Up @@ -97,7 +103,7 @@ run_in_container getuto
run_in_container emerge --getbinpkg app-eselect/eselect-repository sys-apps/config-site
run_in_container make install
run_in_container eselect repository create crossdev
run_in_container crossdev --show-fail-log --target "${TARGET}"
run_in_container crossdev --show-fail-log --target "${TARGET}" ${PROFILE+--profile "${PROFILE}"}
if [[ "${EMERGE_SYSTEM}" -eq 1 ]]; then
run_in_container "${TARGET}-emerge" @system
fi

0 comments on commit d77c2dc

Please sign in to comment.