Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
112 changes: 42 additions & 70 deletions crossdev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -939,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
Expand Down Expand Up @@ -981,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;;
Expand Down Expand Up @@ -1216,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 && {
Expand Down Expand Up @@ -1601,53 +1614,7 @@ hr
### Create links for helper scripts ###

xmkdir -p "${EPREFIX}"/usr/${CTARGET}
LLVM="${LLVM}" emerge-wrapper --target ${CTARGET} --init || 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
LLVM="${LLVM}" emerge-wrapper --target "${CTARGET}" --init --profile "${PROFILE}" || exit 1

# HOSTCC is used by linux-headers to compile fixdeps program for CBUILD
if [[ "${LLVM}" == "yes" ]] ; then
Expand Down Expand Up @@ -1693,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 @@ -1746,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 @@ -1781,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 @@ -1813,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 @@ -1826,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 @@ -1836,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 @@ -1845,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 @@ -1860,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 @@ -1871,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
8 changes: 7 additions & 1 deletion wrappers/emerge-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $?
}

Expand Down Expand Up @@ -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
Expand Down
Loading