From e4f57bea82fe2869e9bc744498c5658d3e160089 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Mon, 19 Jul 2021 14:24:42 +0000 Subject: [PATCH 1/3] bootstrap_sdk: fix issues around lib->lib64 symlink The arm64 profiles don't specify SYMLINK_LIB=yes, which makes sense since arm64 systems don't support multilib in the way that we are used to from x86. What this means is that build artifacts are installed into separate lib and lib64 directories. The root overlay installed in stage4 needs to check for SYMLINK_LIB before trying to create a symlink, otherwise it fails to be applied because it collides with the directory in the rootfs. This uncovered a second minor issues - the rust toolchain bootstrap scripts checked for /usr/lib64/rust*, but the ebuild installs to /usr/lib/rust. Signed-off-by: Jeremi Piotrowski --- bootstrap_sdk | 6 +++++- build_library/toolchain_util.sh | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bootstrap_sdk b/bootstrap_sdk index f3fb419e12..631b057959 100755 --- a/bootstrap_sdk +++ b/bootstrap_sdk @@ -92,7 +92,11 @@ if [[ "$STAGES" =~ stage4 ]]; then libdir=$(get_sdk_libdir) mkdir -p "${ROOT_OVERLAY}/usr/${libdir}" if [[ "${libdir}" != lib ]]; then - ln -s "${libdir}" "${ROOT_OVERLAY}/usr/lib" + if [[ "$(get_sdk_symlink_lib)" == "yes" ]]; then + ln -s "${libdir}" "${ROOT_OVERLAY}/usr/lib" + else + mkdir -p "${ROOT_OVERLAY}/usr/lib" + fi fi "${BUILD_LIBRARY_DIR}/set_lsb_release" \ --root "${ROOT_OVERLAY}" diff --git a/build_library/toolchain_util.sh b/build_library/toolchain_util.sh index d48f1c4f6c..286735d2cc 100644 --- a/build_library/toolchain_util.sh +++ b/build_library/toolchain_util.sh @@ -167,6 +167,10 @@ get_sdk_libdir() { portageq envvar "LIBDIR_$(get_sdk_arch)" } +get_sdk_symlink_lib() { + portageq envvar "SYMLINK_LIB" +} + # Usage: get_sdk_binhost [version...] # If no versions are specified the current and SDK versions are used. get_sdk_binhost() { @@ -333,7 +337,7 @@ install_cross_toolchain() { $sudo emerge "${emerge_flags[@]}" \ "cross-${cross_chost}/gdb" "${cross_pkgs[@]}" if [ "${cross_chost}" = aarch64-cros-linux-gnu ] && \ - [ ! -d /usr/lib64/rust-*/rustlib/aarch64-unknown-linux-gnu ] && [ ! -d /usr/lib64/rustlib/aarch64-unknown-linux-gnu ]; then + [ ! -d /usr/lib/rust-*/rustlib/aarch64-unknown-linux-gnu ] && [ ! -d /usr/lib/rustlib/aarch64-unknown-linux-gnu ]; then # If no aarch64 folder exists, warn about the situation but don't compile Rust here or download it as binary package echo "WARNING: No aarch64 cross-compilation Rust libraries found!" echo "In case building fails, make sure the old Rust version is deleted with: sudo emerge -C virtual/rust dev-lang/rust" From 4ba3218d6ac38c43b2898002f0f5caff135e5c60 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Mon, 19 Jul 2021 14:33:08 +0000 Subject: [PATCH 2/3] boostrap_sdk: only build aarch64 cross-rust on x86 hosts The rust ebuild has some magic to detect cross-toolchains present on the system and enable building additional cross targets. The code to trigger the rebuild of rust is part of install_cross_rust, and checks whether the cross directories exist in the rust installation. If they don't, then rust is removed and rebuilt to allow for the auto-detection to happen. Right now there are two issues with the code. Firstly, the path that is checked is wrong, which leads to rust always being removed and rebuilt. The path checked is /usr/lib/rust-*/rustlib but /usr/lib/rustlib is where the files are installed. The second issue is that it checks for aarch64 dirs when CHOST is aarch64-cros-linux-gnu. However, on an aarch64 host the aarch64 dirs will already exist from building the sdk itself. The rust ebuild is not ready to handle aarch64 hosts yet and blows up. The correct behavior is to combine the check for CHOST with a check for the right CBUILD. On an aarch64 host we should presumably check for the x86 CHOST and rust dirs, but that can be added later, because it needs more work. Signed-off-by: Jeremi Piotrowski --- build_library/toolchain_util.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build_library/toolchain_util.sh b/build_library/toolchain_util.sh index 286735d2cc..278e7664b1 100644 --- a/build_library/toolchain_util.sh +++ b/build_library/toolchain_util.sh @@ -399,6 +399,7 @@ install_cross_libs() { install_cross_rust() { local cross_chost="$1"; shift local emerge_flags=( "$@" --binpkg-respect-use=y --update ) + local cbuild="$(portageq envvar CBUILD)" # may be called from either catalyst (root) or upgrade_chroot (user) local sudo="env" @@ -406,10 +407,10 @@ install_cross_rust() { sudo="sudo -E" fi - if [ "${cross_chost}" = "aarch64-cros-linux-gnu" ]; then + if [ "${cbuild}" = "x86_64-pc-linux-gnu" ] && [ "${cross_chost}" = "aarch64-cros-linux-gnu" ]; then echo "Building Rust for arm64" # If no aarch64 folder exists, try to remove any existing Rust packages. - [ ! -d /usr/lib/rust-*/rustlib/aarch64-unknown-linux-gnu ] && ($sudo emerge -C dev-lang/rust || true) + [ ! -d /usr/lib/rustlib/aarch64-unknown-linux-gnu ] && ($sudo emerge -C dev-lang/rust || true) $sudo emerge "${emerge_flags[@]}" dev-lang/rust fi } From 6ce5d3165f8ccc395ac63202d7a1e938b96aa9b4 Mon Sep 17 00:00:00 2001 From: Jeremi Piotrowski Date: Wed, 28 Jul 2021 16:47:13 +0200 Subject: [PATCH 3/3] build_library/toolchain_util: check CBUILD+CHOST for rust warning For consistency with code further down in the file: aarch64 cross compilation only applies when CBUILD is x86, for native aarch64 builds rust is guaranteed to have aarch64 rustlibs. --- build_library/toolchain_util.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build_library/toolchain_util.sh b/build_library/toolchain_util.sh index 278e7664b1..b48ca19936 100644 --- a/build_library/toolchain_util.sh +++ b/build_library/toolchain_util.sh @@ -293,6 +293,7 @@ install_cross_toolchain() { local cross_flags=( --gdb '[stable]' --ex-gdb --stable --target "${cross_chost}" ) local cross_cfg="/usr/${cross_chost}/etc/portage/${cross_chost}-crossdev" local cross_cfg_data=$(_crossdev_info "${cross_flags[@]}") + local cbuild="$(portageq envvar CBUILD)" local emerge_flags=( "$@" --binpkg-respect-use=y --update --newuse ) # Forcing binary packages for toolchain packages breaks crossdev since it @@ -336,7 +337,7 @@ install_cross_toolchain() { echo "Installing existing binaries" $sudo emerge "${emerge_flags[@]}" \ "cross-${cross_chost}/gdb" "${cross_pkgs[@]}" - if [ "${cross_chost}" = aarch64-cros-linux-gnu ] && \ + if [ "${cbuild}" = "x86_64-pc-linux-gnu" ] && [ "${cross_chost}" = aarch64-cros-linux-gnu ] && \ [ ! -d /usr/lib/rust-*/rustlib/aarch64-unknown-linux-gnu ] && [ ! -d /usr/lib/rustlib/aarch64-unknown-linux-gnu ]; then # If no aarch64 folder exists, warn about the situation but don't compile Rust here or download it as binary package echo "WARNING: No aarch64 cross-compilation Rust libraries found!"