From bfe51a20f21a13c927bac01bd9280951ea7758d5 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Fri, 3 Jan 2025 15:30:51 +0000 Subject: [PATCH 1/4] Prevent functions.sh from complaining about command line arguments Such as -C, which means --clean for crossdev rather than NO_COLOR. Signed-off-by: James Le Cuirot --- crossdev | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crossdev b/crossdev index 59eb836..9b11ab7 100755 --- a/crossdev +++ b/crossdev @@ -21,7 +21,13 @@ EROOT=${ROOT%/}"${EPREFIX}"/ : ${PORTAGE_CONFIGROOT:=${EROOT}} CONFIGROOT="${PORTAGE_CONFIGROOT}/etc/portage" +# Prevent functions.sh from complaining about command line arguments like -C, +# which has a different meaning for crossdev. +declare -a ARGV=( "${@}" ) +set -- source "${EPREFIX}"/lib/gentoo/functions.sh || exit 1 +set -- "${ARGV[@]}" + esyslog() { :; } die_logs() { echo From 6e8a0eadaed751ab48fa4838ed72163dc0fe3acd Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 26 Jun 2024 12:40:37 +0200 Subject: [PATCH 2/4] Initial support for overriding profile Closes: https://bugs.gentoo.org/748975 Closes: https://github.com/gentoo/crossdev/pull/22 Signed-off-by: James Le Cuirot --- crossdev | 4 +++- wrappers/emerge-wrapper | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crossdev b/crossdev index 9b11ab7..97ecf8c 100755 --- a/crossdev +++ b/crossdev @@ -945,6 +945,7 @@ SHOW_FAIL_LOG="no" SHOW_TARGET_CFG="no" INIT_TARGET_ONLY="no" LLVM="no" +PROFILE="embedded" while [[ $# -gt 0 ]] ; do case $1 in @@ -987,6 +988,7 @@ while [[ $# -gt 0 ]] ; do --cpkg) shift; CPKG=$1;; -ox|--ov-extra) shift; XOVLS+=( "$1" );; --env) shift; AENV=$1;; + --profile) shift; PROFILE=$1;; -L|--llvm) LLVM="yes";; -A|--abis) shift; MULTILIB_ABIS=$1;; --host-abi) shift; HOST_ABI=$1;; @@ -1607,7 +1609,7 @@ hr ### Create links for helper scripts ### xmkdir -p "${EPREFIX}"/usr/${CTARGET} -LLVM="${LLVM}" emerge-wrapper --target ${CTARGET} --init || exit 1 +LLVM="${LLVM}" emerge-wrapper --target "${CTARGET}" --init --profile "${PROFILE}" || exit 1 ############################################################# ### Create directories usually created by sys-apps/baselayout diff --git a/wrappers/emerge-wrapper b/wrappers/emerge-wrapper index eab8f96..fa179f3 100755 --- a/wrappers/emerge-wrapper +++ b/wrappers/emerge-wrapper @@ -37,7 +37,6 @@ cross_wrap_etc() setup_warning=false cp -a "${PREFIX}"/share/crossdev/etc ${SYSROOT}/ || return 1 - ln -snf "${MAIN_REPO_PATH}/profiles/embedded" "${SYSROOT}/etc/portage/make.profile" || return 1 local confs=( ${SYSROOT}/etc/portage/make.conf @@ -131,6 +130,7 @@ cross_wrap() if [[ -d ${SYSROOT} ]] && [[ ! -d ${SYSROOT}/etc ]] ; then cross_wrap_etc "$@" fi + PORTAGE_CONFIGROOT=${SYSROOT} eselect profile set --force "${PROFILE}" return $? } @@ -159,12 +159,18 @@ CHOST=${CHOST%-emerge} CHOST=${CHOST#emerge-} export CHOST +PROFILE="embedded" + if [[ $1 == "--target" ]] ; then CHOST=$2 shift 2 fi if [[ $1 == "--init" ]] ; then + shift + if [[ $1 == "--profile" ]] ; then + PROFILE=$2 + fi cross_init exit $? fi From e76f567ff8d378f030fb6713e062ee69e5b0f1e2 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Tue, 31 Dec 2024 15:25:12 +0000 Subject: [PATCH 3/4] Warn when choosing the embedded profile unless target is bare metal It's almost never what users want and causes issues even if they change the profile later. Closes: https://bugs.gentoo.org/748975 Signed-off-by: James Le Cuirot --- crossdev | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crossdev b/crossdev index 97ecf8c..7d591e3 100755 --- a/crossdev +++ b/crossdev @@ -1224,6 +1224,11 @@ einfo "Stage: ${STAGE} (${STAGE_DISP[${STAGE}]})" einfo "USE=multilib: ${MULTILIB_USE}" [[ ${DEFAULT_ABI} != "${MULTILIB_ABIS}" ]] && def_out=" (default: ${DEFAULT_ABI})" || def_out= einfo "Target ABIs: ${MULTILIB_ABIS}${def_out}" +if [[ ${PROFILE} == embedded && ${KPKG} != "[none]" ]]; then +ewarn "Target Profile: ${PROFILE} (NOT RECOMMENDED, consider recreating with the --profile option)" +else +einfo "Target Profile: ${PROFILE}" +fi echo ex_fast || { is_s0 && { From d77c2dc503cd3578ed3a8a241b1df6ae594d42f1 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Tue, 31 Dec 2024 15:44:09 +0000 Subject: [PATCH 4/4] Install baselayout rather than duplicating dir/symlink behaviour here 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 --- .github/workflows/crossdev.yml | 3 ++ crossdev | 97 ++++++++++------------------------ scripts/container_test.sh | 8 ++- 3 files changed, 38 insertions(+), 70 deletions(-) diff --git a/.github/workflows/crossdev.yml b/.github/workflows/crossdev.yml index f74cf03..0110d46 100644 --- a/.github/workflows/crossdev.yml +++ b/.github/workflows/crossdev.yml @@ -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 diff --git a/crossdev b/crossdev index 7d591e3..3bf3128 100755 --- a/crossdev +++ b/crossdev @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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...) @@ -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 diff --git a/scripts/container_test.sh b/scripts/container_test.sh index 4205dbd..729a339 100755 --- a/scripts/container_test.sh +++ b/scripts/container_test.sh @@ -9,6 +9,7 @@ Options: --skip-system Skip emerging the @system set after setting up crossdev. --tag Specify the container tag to use. Default is 'latest'. --target Specify the target architecture for crossdev. Required. + --profile Specify the Portage profile for crossdev. Default is 'embedded'. -h, --help Show this help message and exit. Environment Variables: @@ -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 @@ -65,6 +67,10 @@ while [[ $# -gt 0 ]]; do print_help exit 0 ;; + --profile) + PROFILE="$2" + shift 2 + ;; --skip-system) EMERGE_SYSTEM=0 shift 1 @@ -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