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
5 changes: 4 additions & 1 deletion .github/workflows/crossdev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ jobs:
- target: riscv32-unknown-linux-gnu
gcc: true
llvm: false
# busybox fails to build: `‘SYS_settimeofday’ undeclared`.
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
gcc: true
llvm: false
args: --profile default/linux/riscv/23.0/rv64/lp64
- target: riscv64-unknown-linux-musl
gcc: true
llvm: true
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
160 changes: 43 additions & 117 deletions crossdev
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,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 @@ -1061,6 +1062,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 @@ -1303,6 +1305,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 @@ -1701,93 +1708,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.
if [[ ${CTARGET} == *-gnu* ]] ; then
# Identify if it is really Hurd or not
case ${CTARGET} in
*-linux*)
# Same as non-Hurd patch
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib
;;
i[3-7]86*-gnu*)
# Hurd is special as it defaults upstream to implicit inverse usr-merge
# (i.e. /usr -> /). If we don't do this here, then when we build
# cross glibc, startup files are in /usr/lib while libc.so is in
# /lib.
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/bin
ln -s usr/lib "${EPREFIX}"/usr/${CTARGET}/lib
ln -s usr/bin "${EPREFIX}"/usr/${CTARGET}/bin
ln -s usr/bin "${EPREFIX}"/usr/${CTARGET}/sbin
ln -s bin "${EPREFIX}"/usr/${CTARGET}/usr/sbin
;;
x86_64-gnu)
# Hurd is special as it defaults upstream to implicit inverse usr-merge
# (i.e. /usr -> /). If we don't do this here, then when we build
# cross glibc, startup files are in /usr/lib64 while libc.so is in
# /lib64.
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib{,64}
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/bin
ln -s usr/lib "${EPREFIX}"/usr/${CTARGET}/lib
ln -s usr/lib64 "${EPREFIX}"/usr/${CTARGET}/lib64
ln -s usr/bin "${EPREFIX}"/usr/${CTARGET}/bin
ln -s usr/bin "${EPREFIX}"/usr/${CTARGET}/sbin
ln -s bin "${EPREFIX}"/usr/${CTARGET}/usr/sbin
;;
*)
die "Unknown Hurd target, please file a bug"
;;
esac
else
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/lib
xmkdir -p "${EPREFIX}"/usr/${CTARGET}/usr/lib
fi

###
### 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 @@ -1833,30 +1754,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 @@ -1917,6 +1839,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 @@ -1949,9 +1875,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 @@ -1962,7 +1888,7 @@ if ! ex_fast ; then
# install kernel headers (since the C library often uses them)
USE="${KUSE} ${USE} headers-only" \
EOPTS="${EOPTS}$(is_s2 && printf ' --buildpkg=n')" \
doemerge ${KPKG} ${KPKG}-quick
do_emerge_cross ${KPKG} ${KPKG}-quick

if [[ -n ${LPKG} ]] ; then
# install C library headers
Expand All @@ -1971,19 +1897,19 @@ if ! ex_fast ; then
# care about at this point -- we aren't compiling yet
USE="${LUSE} ${USE} ${LUSE_DISABLE} headers-only" \
EOPTS="${EOPTS} --nodeps$(is_s3 && printf ' --buildpkg=n')" \
doemerge ${LPKG} ${LPKG}-headers
do_emerge_cross ${LPKG} ${LPKG}-headers
fi
fi

# then finally get around to the C compiler
if [[ "${LLVM}" == "yes" ]]; then
# Compile compiler-rt
USE="${RUSE} ${USE}" \
doemerge ${RPKG}
do_emerge_cross ${RPKG}
else
USE="${GUSE} ${USE} ${GUSE_DISABLE_STAGE_1}" \
EOPTS="${EOPTS}$(is_s4 && printf ' --buildpkg=n')" \
doemerge ${GPKG} ${GPKG}-stage1
do_emerge_cross ${GPKG} ${GPKG}-stage1
fi

fi
Expand All @@ -1994,7 +1920,7 @@ if ! ex_fast ; then

USE="${KUSE} ${USE} headers-only" \
EOPTS="${EOPTS}$([[ ${K2PKG} != "[none]" ]] && printf ' --buildpkg=n')" \
doemerge ${KPKG} ${KPKG}-stage1
do_emerge_cross ${KPKG} ${KPKG}-stage1

if [[ ${K2PKG} != "[none]" ]] ; then
# KPKG may need K2PKG to install everything, so
Expand All @@ -2003,11 +1929,11 @@ if ! ex_fast ; then

USE="${KUSE} ${USE} headers-only" \
EOPTS="${EOPTS}$(is_s3 && printf ' --buildpkg=n')" \
doemerge ${K2PKG} ${K2PKG}-stage1
do_emerge_cross ${K2PKG} ${K2PKG}-stage1

# Go again now we have it.
USE="${KUSE} ${USE}" \
doemerge ${KPKG} ${KPKG}-stage2
do_emerge_cross ${KPKG} ${KPKG}-stage2
fi

if [[ ${K3PKG} != "[none]" ]] ; then
Expand All @@ -2017,7 +1943,7 @@ if ! ex_fast ; then

USE="${KUSE} ${USE} headers-only" \
EOPTS="${EOPTS}$(is_s3 && printf ' --buildpkg=n')" \
doemerge ${K3PKG} ${K3PKG}-stage1
do_emerge_cross ${K3PKG} ${K3PKG}-stage1
fi
fi

Expand All @@ -2028,18 +1954,18 @@ if ! ex_fast ; then
set_eopts_on_pkg_status ${LPKG} headers-only

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

if [[ ${K2PKG} != "[none]" ]] ; then
set_eopts_on_pkg_status ${K2PKG} headers-only

USE="${KUSE} ${USE} -headers-only" doemerge ${K2PKG} ${K2PKG}-stage2
USE="${KUSE} ${USE} -headers-only" do_emerge_cross ${K2PKG} ${K2PKG}-stage2
fi

if [[ ${K3PKG} != "[none]" ]] ; then
set_eopts_on_pkg_status ${K3PKG} headers-only

USE="${KUSE} ${USE} -headers-only" doemerge ${K3PKG} ${K3PKG}-stage2
USE="${KUSE} ${USE} -headers-only" do_emerge_cross ${K3PKG} ${K3PKG}-stage2
fi
fi

Expand All @@ -2049,27 +1975,27 @@ if ! ex_fast ; then
# Static llvm-libunwind is essential for supporting simple static linking in
# general, see the bug #892956. The same is done in the LLVM profile.
USE="${UUSE} ${USE} static-libs" \
doemerge ${UPKG}
do_emerge_cross ${UPKG}

USE="${AUSE} ${USE}" \
doemerge ${APKG}
do_emerge_cross ${APKG}
USE="${PUSE} ${USE}" \
doemerge ${PPKG}
do_emerge_cross ${PPKG}
else
EOPTS="${EOPTS_UP} --newuse" \
USE="${GUSE} ${USE} ${GUSE_DISABLE_STAGE_2}" \
doemerge ${GPKG} ${GPKG}-stage2
do_emerge_cross ${GPKG} ${GPKG}-stage2
fi
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
12 changes: 7 additions & 5 deletions scripts/container_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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 @@ -57,6 +58,7 @@ CONTAINER_TAG="latest"
EMERGE_SYSTEM=1
USE_LLVM=0
TOPDIR=$(git rev-parse --show-toplevel)
unset PROFILE

remove_container || true
trap "remove_container" EXIT
Expand All @@ -71,6 +73,10 @@ while [[ $# -gt 0 ]]; do
USE_LLVM=1
shift 1
;;
--profile)
PROFILE="$2"
shift 2
;;
--skip-system)
EMERGE_SYSTEM=0
shift 1
Expand All @@ -83,10 +89,6 @@ while [[ $# -gt 0 ]]; do
TARGET="$2"
shift 2
;;
--profile)
PROFILE="$2"
shift 2
;;
*)
echo "Unknown option: $1"
print_help
Expand All @@ -113,7 +115,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 "${EXTRA_ARGS[@]}" --target "${TARGET}"
run_in_container crossdev --show-fail-log "${EXTRA_ARGS[@]}" --target "${TARGET}" ${PROFILE+--profile "${PROFILE}"}
if [[ "${EMERGE_SYSTEM}" -eq 1 ]]; then
[[ -v PROFILE ]] && _CONTAINER_ARGS="--env PORTAGE_CONFIGROOT=/usr/${TARGET}" run_in_container "eselect" profile set --force "${PROFILE}"
run_in_container "${TARGET}-emerge" @system
Expand Down
Loading