diff --git a/.github/workflows/crossdev.yml b/.github/workflows/crossdev.yml index f74cf03..fd03d1c 100644 --- a/.github/workflows/crossdev.yml +++ b/.github/workflows/crossdev.yml @@ -18,63 +18,147 @@ jobs: # requests fixing them welcome! target: - target: aarch64-unknown-linux-gnu + gcc: true + llvm: false - target: aarch64-unknown-linux-musl + gcc: true + llvm: true - target: aarch64_be-unknown-linux-gnu + gcc: true + llvm: false - target: alpha-unknown-linux-gnu + gcc: true + llvm: false - target: arm-unknown-linux-gnueabi + gcc: true + llvm: false - target: arm-unknown-linux-gnueabihf + gcc: true + llvm: false - target: arm-unknown-linux-musleabi + gcc: true + llvm: false - target: arm-unknown-linux-musleabihf + gcc: true + llvm: false - target: armeb-unknown-linux-gnueabi + gcc: true + llvm: false - target: armeb-unknown-linux-gnueabihf + gcc: true + llvm: false - target: armeb-unknown-linux-musleabi + gcc: true + llvm: false - target: armeb-unknown-linux-musleabihf + gcc: true + llvm: false - target: armv7-unknown-linux-musleabi + gcc: true + llvm: false - target: armv7-unknown-linux-musleabihf + gcc: true + llvm: false - target: armv6j-softfp-linux-gnueabi + gcc: true + llvm: false - target: armv6j-unknown-linux-gnueabihf + gcc: true + llvm: false - target: armv7a-softfp-linux-gnueabi + gcc: true + llvm: false - target: armv7a-unknown-linux-gnueabihf + gcc: true + llvm: false - target: hppa1.1-unknown-linux-gnu + gcc: true + llvm: false - target: hppa2.0-unknown-linux-gnu + gcc: true + llvm: false - target: hppa64-unknown-linux-gnu args: --skip-system + gcc: true + llvm: false - target: loongarch64-unknown-linux-gnu + gcc: true + llvm: false # musl ebuilds don't support loong. The target is supported upstream, # we need to fix and test our ebuilds. #- target: loongarch64-unknown-linux-musl - target: m68k-unknown-linux-gnu + gcc: true + llvm: false - target: mips-unknown-linux-gnu + gcc: true + llvm: false - target: mips-unknown-linux-musl + gcc: true + llvm: false - target: mipsel-unknown-linux-gnu + gcc: true + llvm: false - target: mipsel-unknown-linux-musl + gcc: true + llvm: false - target: mips64-unknown-linux-gnu + gcc: true + llvm: false # libgcc_s.so fails to build: `cannot find crti.o: No such file or # directory`. # - target: mips64-unknown-linux-musl - target: mips64el-unknown-linux-gnu + gcc: true + llvm: false # libgcc_s.so fails to build: `cannot find crti.o: No such file or # directory`. # - target: mips64el-unknown-linux-musl - target: or1k-unknown-linux-gnu args: --skip-system + gcc: true + llvm: false - target: or1k-unknown-linux-musl args: --skip-system + gcc: true + llvm: false - target: powerpc-unknown-linux-gnu + gcc: true + llvm: false - target: powerpc-unknown-linux-musl + gcc: true + llvm: false - target: powerpc64-unknown-linux-gnu + gcc: true + llvm: false - target: powerpc64-unknown-linux-musl + gcc: true + llvm: false - target: powerpc64le-unknown-linux-gnu + gcc: true + llvm: false - target: riscv32-unknown-linux-gnu + gcc: true + llvm: false # busybox fails to build: `‘SYS_settimeofday’ undeclared`. # - target: riscv32-unknown-linux-musl - target: riscv64-unknown-linux-gnu + gcc: true + llvm: false - target: riscv64-unknown-linux-musl + gcc: true + llvm: true # glibc fails to build: `no support for pre-v8 sparc`. # - target: sparc-unknown-linux-gnu - target: sparc64-unknown-linux-gnu + gcc: true + llvm: false - target: s390-ibm-linux-gnu + gcc: true + llvm: false - target: s390x-ibm-linux-gnu + gcc: true + llvm: false # musl ebuilds don't support s390x. The target is supported upstream, # we need to fix and test our ebuilds. # - target: s390x-unknown-linux-musl @@ -89,30 +173,58 @@ jobs: # - target: sh4eb-unknown-linux-gnu # - target: sh4eb-unknown-linux-musl - target: x86_64-unknown-linux-gnu + gcc: true + llvm: false - target: x86_64-unknown-linux-musl + gcc: true + llvm: true # Embedded or otherwise special targets - target: arm-none-eabi args: --skip-system + gcc: true + llvm: false - target: avr args: --skip-system + gcc: true + llvm: false - target: nvptx-none args: --skip-system + gcc: true + llvm: false - target: bpf-unknown-none args: --skip-system + gcc: true + llvm: false stage3: - - latest # `openrc` (glibc+GCC) is tagged as `latest` - - musl + - latest # glibc+GCC + - llvm # glibc+LLVM and GCC as a fallback + - musl # musl+GCC fail-fast: false name: crossdev target=${{ matrix.target.target }} stage3=${{ matrix.stage3 }} + env: + CONTAINER_ENGINE: docker runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Create cross environment - env: - CONTAINER_ENGINE: docker + - name: Create cross environment with GCC + # Building GCC-based sysroots on llvm stage3 should be possible, since + # it contains a fallback GCC toolchain. But in practice, it fails for + # certain architectures. Pull requests welcome! + if: ${{ matrix.target.gcc && !contains(matrix.stage3, 'llvm') }} run: | ./scripts/container_test.sh \ --tag ${{ matrix.stage3 }} \ --target ${{ matrix.target.target }} \ ${{ matrix.target.args }} + + - name: Create cross environment with LLVM + # * We need LLVM toolchain to be present in the stage3. + # * Building sysroots with glibc and LLVM is not yet supported. + if: ${{ matrix.target.llvm && contains(matrix.stage3, 'llvm') }} + run: | + ./scripts/container_test.sh \ + --llvm \ + --tag ${{ matrix.stage3 }} \ + --target ${{ matrix.target.target }} \ + ${{ matrix.target.args }} diff --git a/crossdev b/crossdev index fb03720..c3e0ead 100755 --- a/crossdev +++ b/crossdev @@ -906,6 +906,9 @@ KCAT="sys-kernel" ; KPKG="linux-headers" ; KVER="" KUSE="" KENV="" KOVL="" KMASK LCAT="sys-libs" ; LPKG="[none]" ; LVER="" LUSE="" LENV="" LOVL="" LMASK="" LFORCE="" DCAT="dev-debug" ; DPKG="gdb" ; DVER="" DUSE="" DENV="" DOVL="" DMASK="" DFORCE="" RCAT="llvm-runtimes" ; RPKG="compiler-rt" ; RVER="" RUSE="" RENV="" ROVL="" RMASK="" RFORCE="" +UCAT="llvm-runtimes" ; UPKG="libunwind" ; UVER="" UUSE="" UENV="" UOVL="" UMASK="" UFORCE="" +ACAT="llvm-runtimes" ; APKG="libcxxabi" ; AVER="" AUSE="" AENV="" AOVL="" AMASK="" AFORCE="" +PCAT="llvm-runtimes" ; PPKG="libcxx" ; PVER="" PUSE="" PENV="" POVL="" PMASK="" PFORCE="" CCAT="sys-devel" ; CPKG="clang-crossdev-wrappers" ; CVER="" CUSE="" CENV="" COVL="" CMASK="" CFORCE="" XPKGS=() XVERS=() XUSES=() XENVS=() XOVLS=() XMASKS=() XFORCES=() DEFAULT_VER="[latest]" @@ -948,69 +951,84 @@ LLVM="no" while [[ $# -gt 0 ]] ; do case $1 in - -V|--version) echo "crossdev-${CROSSDEV_VER}"; exit 0;; - -t|--target) shift; parse_target $1;; - --b|--binutils) shift; BVER=$1;; - --benv) shift; BENV=$1;; - -ob|--ov-binutils) shift; BOVL=$1;; - --bcat) shift; BCAT=$1;; - --bpkg) shift; BPKG=$1;; - --d|--gdb) shift; DVER=$1;; - --denv) shift; DENV=$1;; - -od|--ov-gdb) shift; DOVL=$1;; - --dcat) shift; DCAT=$1;; - --dpkg) shift; DPKG=$1;; - --g|--gcc) shift; GVER=$1;; - --genv) shift; GENV=$1;; - -og|--ov-gcc) shift; GOVL=$1;; - --gcat) shift; GCAT=$1;; - --gpkg) shift; GPKG=$1;; - --k|--kernel) shift; KVER=$1;; - --kenv) shift; KENV=$1;; - -ok|--ov-kernel) shift; KOVL=$1;; - --kcat) shift; KCAT=$1;; - --kpkg) shift; KPKG=$1;; - --l|--libc) shift; LVER=$1;; - --lenv) shift; LENV=$1;; - -ol|--ov-libc) shift; LOVL=$1;; - --lcat) shift; LCAT=$1;; - --lpkg) shift; LPKG=$1;; - --r|--crt) shift; RVER=$1;; - --renv) shift; RENV=$1;; - -or|--ov-crt) shift; ROVL=$1;; - --rcat) shift; RCAT=$1;; - --rpkg) shift; RPKG=$1;; - --c|--ccw) shift; CVER=$1;; - --cenv) shift; CENV=$1;; - -oc|--ov-ccw) shift; COVL=$1;; - --ccat) shift; CCAT=$1;; - --cpkg) shift; CPKG=$1;; - -ox|--ov-extra) shift; XOVLS+=( "$1" );; - --env) shift; AENV=$1;; - -L|--llvm) LLVM="yes";; - -A|--abis) shift; MULTILIB_ABIS=$1;; - --host-abi) shift; HOST_ABI=$1;; - -S|--stable) DEFAULT_VER="[stable]";; - -C|--clean) shift; parse_target $1; ACTION="uninstall";; - -s?|--stage?) STAGE=${1:0-1};; - -oS|--overlays) shift; SEARCH_OVERLAYS=$1;; - -oO|--ov-output) shift; CROSSDEV_OVERLAY=$1;; - --ex-only) EX_FAST="yes";; - --ex-gcc) EX_GCC="yes";; - --ex-gdb) EX_GDB="yes";; - --ex-pkg) shift; XPKGS+=( "$1" );; - --with-*) eval $(set_withval $1);; - --without-*) eval $(set_withval $1);; - -f|--force) FORCE="yes";; - -x) SET_X="yes";; - --show-target-cfg) SHOW_TARGET_CFG="yes";; - --init-target) INIT_TARGET_ONLY="yes";; - --show-fail-log) SHOW_FAIL_LOG="yes";; - --show-repo-cfg) show_repo_cfg "$2";; - -P|--portage) UOPTS="${UOPTS} $2"; shift;; - -h|--help) usage;; - -*) eerror "UNKNOWN OPTION: '$1'" ; usage 1;; - *) parse_target $1;; + -V|--version) echo "crossdev-${CROSSDEV_VER}"; exit 0;; + -t|--target) shift; parse_target $1;; + --b|--binutils) shift; BVER=$1;; + --benv) shift; BENV=$1;; + -ob|--ov-binutils) shift; BOVL=$1;; + --bcat) shift; BCAT=$1;; + --bpkg) shift; BPKG=$1;; + --d|--gdb) shift; DVER=$1;; + --denv) shift; DENV=$1;; + -od|--ov-gdb) shift; DOVL=$1;; + --dcat) shift; DCAT=$1;; + --dpkg) shift; DPKG=$1;; + --g|--gcc) shift; GVER=$1;; + --genv) shift; GENV=$1;; + -og|--ov-gcc) shift; GOVL=$1;; + --gcat) shift; GCAT=$1;; + --gpkg) shift; GPKG=$1;; + --k|--kernel) shift; KVER=$1;; + --kenv) shift; KENV=$1;; + -ok|--ov-kernel) shift; KOVL=$1;; + --kcat) shift; KCAT=$1;; + --kpkg) shift; KPKG=$1;; + --l|--libc) shift; LVER=$1;; + --lenv) shift; LENV=$1;; + -ol|--ov-libc) shift; LOVL=$1;; + --lcat) shift; LCAT=$1;; + --lpkg) shift; LPKG=$1;; + --r|--crt) shift; RVER=$1;; + --renv) shift; RENV=$1;; + -or|--ov-crt) shift; ROVL=$1;; + --rcat) shift; RCAT=$1;; + --rpkg) shift; RPKG=$1;; + --u|--libunwind) shift; UVER=$1;; + --uenv) shift; UENV=$1;; + -ou|--ov-libuinwind) shift; UOVL=$1;; + --ucat) shift; UCAT=$1;; + --upkg) shift; UPKG=$1;; + --a|--libcxxabi) shift; AVER=$1;; + --aenv) shift; AENV=$1;; + -oa|--ov--libcxxabi) shift; AOVL=$1;; + --acat) shift; ACAT=$1;; + --apkg) shift; APKG=$1;; + --p|--libcxx) shift; PVER=$1;; + --penv) shift; PENV=$1;; + -op|--ov-libcxx) shift; POVL=$1;; + --pcat) shift; PCAT=$1;; + --ppkg) shift; PPKG=$1;; + --c|--ccw) shift; CVER=$1;; + --cenv) shift; CENV=$1;; + -oc|--ov-ccw) shift; COVL=$1;; + --ccat) shift; CCAT=$1;; + --cpkg) shift; CPKG=$1;; + -ox|--ov-extra) shift; XOVLS+=( "$1" );; + --env) shift; AENV=$1;; + -L|--llvm) LLVM="yes";; + -A|--abis) shift; MULTILIB_ABIS=$1;; + --host-abi) shift; HOST_ABI=$1;; + -S|--stable) DEFAULT_VER="[stable]";; + -C|--clean) shift; parse_target $1; ACTION="uninstall";; + -s?|--stage?) STAGE=${1:0-1};; + -oS|--overlays) shift; SEARCH_OVERLAYS=$1;; + -oO|--ov-output) shift; CROSSDEV_OVERLAY=$1;; + --ex-only) EX_FAST="yes";; + --ex-gcc) EX_GCC="yes";; + --ex-gdb) EX_GDB="yes";; + --ex-pkg) shift; XPKGS+=( "$1" );; + --with-*) eval $(set_withval $1);; + --without-*) eval $(set_withval $1);; + -f|--force) FORCE="yes";; + -x) SET_X="yes";; + --show-target-cfg) SHOW_TARGET_CFG="yes";; + --init-target) INIT_TARGET_ONLY="yes";; + --show-fail-log) SHOW_FAIL_LOG="yes";; + --show-repo-cfg) show_repo_cfg "$2";; + -P|--portage) UOPTS="${UOPTS} $2"; shift;; + -h|--help) usage;; + -*) eerror "UNKNOWN OPTION: '$1'" ; usage 1;; + *) parse_target $1;; esac shift done @@ -1038,6 +1056,10 @@ GVER=${GVER:-${DEFAULT_VER}} KVER=${KVER:-${DEFAULT_VER}} LVER=${LVER:-${DEFAULT_VER}} DVER=${DVER:-${DEFAULT_VER}} +RVER=${RVER:-${DEFAULT_VER}} +AVER=${AVER:-${DEFAULT_VER}} +PVER=${PVER:-${DEFAULT_VER}} +UVER=${UVER:-${DEFAULT_VER}} STAGE=${STAGE:-${STAGE_DEFAULT}} [[ -z ${CTARGET} ]] && usage 1 for with in HEADERS ; do @@ -1054,8 +1076,6 @@ if [[ ${LPKG} == "newlib" && ${LVER} == "[stable]" ]]; then LVER="[latest]" fi -RVER="[latest]" - show_target_cfg() { local pkgs crosspkgs=() @@ -1245,6 +1265,12 @@ einfo "headers: `pretty_atom ${KPKG}- ${KVER}`" is_s3 && { einfo "libc: `pretty_atom ${LPKG}- ${LVER}`" } +is_s4 && { +[[ "${LLVM}" == "yes" ]] && \ +einfo "llvm-libunwind: `pretty_atom ${UPKG}- ${UVER}`" +einfo "libcxxabi: `pretty_atom ${APKG}- ${AVER}`" +einfo "libcxx: `pretty_atom ${PPKG}- ${PVER}`" +} } ex_gcc && { einfo "Extra: gcc pass: DO IT" @@ -1587,7 +1613,7 @@ done pkglist=( K L ) if [[ ${LLVM} == "yes" ]] ; then - pkglist+=( R C ) + pkglist+=( R C A P U ) else pkglist+=( B G D ) fi @@ -1770,14 +1796,10 @@ if [[ "${LLVM}" == "yes" ]]; then [[ -d "${CLANG_CROSS_CFG_DIR}" ]] || mkdir -p "${CLANG_CROSS_CFG_DIR}" export CLANG_CROSS_CFG="${CLANG_CROSS_CFG_DIR}/${CTARGET}.cfg" - # Force --unwindlib=none for now cat <<-EOF > "${CLANG_CROSS_CFG}" - --rtlib=compiler-rt --sysroot=/usr/${CTARGET} --target=${CTARGET} - --unwindlib=libunwind - --stdlib=libc++ - -fuse-ld=lld + @../gentoo-runtimes.cfg EOF # Workaround until LLVM libc supports dynamic linking and SSP [[ "${LPKG}" == "llvm-libc" ]] && cat <<-EOF >> "${CLANG_CROSS_CFG}" @@ -1885,10 +1907,22 @@ if ! ex_fast ; then 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 + if is_s4 ; then + if [[ "${LLVM}" == "yes" ]]; 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} + + USE="${AUSE} ${USE}" \ + doemerge ${APKG} + USE="${PUSE} ${USE}" \ + doemerge ${PPKG} + else + EOPTS="${EOPTS_UP} --newuse" \ + USE="${GUSE} ${USE} ${GUSE_DISABLE_STAGE_2}" \ + doemerge ${GPKG} ${GPKG}-stage2 + fi fi fi diff --git a/scripts/container_test.sh b/scripts/container_test.sh index 4205dbd..85311bf 100755 --- a/scripts/container_test.sh +++ b/scripts/container_test.sh @@ -6,6 +6,7 @@ print_help() { echo "Usage: $0 [OPTIONS] Options: + --llvm Use LLVM/Clang as a cross compiler --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. @@ -54,6 +55,7 @@ CONTAINER_NAME=${CONTAINER_NAME:-"crossdev"} CONTAINER_URI=${CONTAINER_URI:-"docker.io/gentoo/stage3"} CONTAINER_TAG="latest" EMERGE_SYSTEM=1 +USE_LLVM=0 TOPDIR=$(git rev-parse --show-toplevel) remove_container || true @@ -65,6 +67,10 @@ while [[ $# -gt 0 ]]; do print_help exit 0 ;; + --llvm) + USE_LLVM=1 + shift 1 + ;; --skip-system) EMERGE_SYSTEM=0 shift 1 @@ -85,7 +91,13 @@ while [[ $# -gt 0 ]]; do esac done +EXTRA_ARGS=() +if [[ "${USE_LLVM}" -eq 1 ]]; then + EXTRA_ARGS+="--llvm" +fi + "${CONTAINER_ENGINE}" run -d \ + --pull always \ --name "${CONTAINER_NAME}" \ -v "${TOPDIR}:/workspace" \ -w /workspace \ @@ -97,7 +109,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 "${EXTRA_ARGS[@]}" --target "${TARGET}" if [[ "${EMERGE_SYSTEM}" -eq 1 ]]; then run_in_container "${TARGET}-emerge" @system fi