Skip to content

Commit

Permalink
Utilize Debian style sysroot (#48)
Browse files Browse the repository at this point in the history
* Add patches to support Debian style library paths

* Don't fail if `strip` cannot be found

* Tell Debian patches that there are more directories to look in

* Update GNU mirror

* flag cleanup.

Debian CXX linkage broken. All of RoboRIO support needs testing.

* disable multilib

* autoclean on failure

* Delete even when write protected

* Allow quicker backend builds for debian targets
  • Loading branch information
RyanHir authored Jan 7, 2023
1 parent b4fa054 commit b57d1be
Show file tree
Hide file tree
Showing 14 changed files with 872 additions and 57 deletions.
4 changes: 3 additions & 1 deletion makes/src/11-sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ FUNC_ONLY=true
source "$(dirname "$0")/common.sh"

function download_or_die() {
echo "[INFO] Downloading from $1"

wget -nc -nv "$1" &>/dev/null ||
die "Failed to download archive from $1"
}
Expand All @@ -39,7 +41,7 @@ rm -rf "${DOWNLOAD_DIR}"
mkdir -p "${DOWNLOAD_DIR}"

xpushd "${DOWNLOAD_DIR}"
GNU_MIRROR="https://ftpmirror.gnu.org/gnu"
GNU_MIRROR="https://mirrors.kernel.org/gnu"
GCC_INFRA_MIRROR="https://gcc.gnu.org/pub/gcc/infrastructure"
EXPAT_MIRROR="https://github.com/libexpat/libexpat/releases/download"
SAVANNAH_MIRROR="https://git.savannah.gnu.org/cgit/config.git/plain"
Expand Down
11 changes: 11 additions & 0 deletions makes/src/12-patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ function patch_project() {
src="gcc-${V_GCC}"
ver="${V_GCC}"
;;
bin)
proj="binutils"
src="binutils-${V_BIN}"
ver="${V_BIN}"
;;
*) die "Unknown config" ;;
esac

Expand All @@ -53,6 +58,11 @@ function patch_project() {
# builds
continue
fi
if [[ "$_patch" =~ debian ]] && [ "$TARGET_DISTRO" != "debian" ] &&
[ "$TARGET_DISTRO" != "raspbian" ]; then
# Do not apply debian patches to roborio targets
continue
fi
_patch="${PWD}/$_patch"
xpushd "${DOWNLOAD_DIR}/${src}"
patch_or_die "$_patch"
Expand All @@ -71,6 +81,7 @@ function patch_project() {
}

patch_project gcc
patch_project bin

if [ -d "${PATCH_DIR}/targets/consts/${TOOLCHAIN_NAME}" ]; then
xpushd "${PATCH_DIR}/targets/consts/${TOOLCHAIN_NAME}"
Expand Down
54 changes: 12 additions & 42 deletions makes/src/13-normalize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,60 +57,30 @@ if [ "${TARGET_DISTRO}" = "roborio" ] ||
fi

else
# lib
rm -rf lib/ld-linux*.so*
rsync -aEL lib/"${TARGET_TUPLE}"/ lib/
rm -rf lib/"${TARGET_TUPLE}"

# usr/include
rsync -aEL usr/include/"${TARGET_TUPLE}"/ usr/include/
rm -rf usr/include/"${TARGET_TUPLE}"

# usr/lib
rsync -aEL usr/lib/"${TARGET_TUPLE}"/ usr/lib/
rm -rf usr/lib/"${TARGET_TUPLE}"

cp usr/lib/gcc/"${TARGET_TUPLE}/${V_GCC/.*/}"/*.so* \
usr/lib/gcc/"${TARGET_TUPLE}/${V_GCC/.*/}"/lib*_preinit.o \
usr/lib/gcc/"${TARGET_TUPLE}/${V_GCC/.*/}"/libsanitizer.spec \
usr/lib/

rm -rf usr/lib/audit
rm -rf usr/lib/bfd-plugins
rm -rf usr/lib/compat-ld
rm -rf usr/lib/gold-ld
rm -rf usr/lib/ldscripts
rm -rf usr/lib/mime
rm -rf usr/lib/tar

# Point the libc linker script to correct location
sed -i "s/\/lib\/${TARGET_TUPLE}/\/lib/g" usr/lib/libc.so
fi

# Clear GCC unneeded files from sysroot
for item in cc1 \
cc1plus \
collect2 \
f951 \
lto1 \
lto-wrapper \
plugin \
libasan \
libubsan \
libatomic \
libcc1.so \
libgcc_s.so \
liblto_plugin.so; do
rm -rf usr/lib/gcc/"${TARGET_TUPLE}/${V_GCC/.*/}/${item}"*
done

if [ "${TARGET_LIB_REBUILD}" = "true" ]; then
# Delete libstdc++ headers which will be replaced
rm -rf usr/include/c++/

# Delete GCC runtime artifacts
rm -rf usr/lib/gcc/
rm -rf usr/lib/libgcc_s.so*
rm -rf usr/lib/libatomic.so*
rm -rf usr/lib/libstdc++.so*
if [ "${TARGET_DISTRO}" = "roborio" ] ||
[ "${TARGET_DISTRO}" = "roborio-academic" ]; then
rm -rf usr/lib/gcc/
rm -rf usr/lib/libgcc_s.so*
rm -rf usr/lib/libatomic.so*
rm -rf usr/lib/libstdc++.so*
else
rm -rf usr/lib/"${TARGET_TUPLE}"/gcc/
rm -rf usr/lib/"${TARGET_TUPLE}"/libgcc_s.so*
rm -rf usr/lib/"${TARGET_TUPLE}"/libatomic.so*
rm -rf usr/lib/"${TARGET_TUPLE}"/libstdc++.so*
fi
fi
18 changes: 14 additions & 4 deletions makes/src/30-binutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ if is_step_backend && ! is_lib_rebuild_required; then
exit 0
fi

# This is a part of the debian specific patch. This is no-op for the roborio.
export APPEND_TOOLLIBDIR=yes
export DEB_TARGET_MULTIARCH="${TARGET_TUPLE}"

CONFIGURE_BINUTILS=(
"${CONFIGURE_COMMON[@]}"
"--enable-poison-system-directories"
"--enable-ld"
"--enable-deterministic-archives"
"--build=${BUILD_TUPLE}" # Build machine
"--host=${HOST_TUPLE}" # Host machine
"--target=${TARGET_TUPLE}" # Target machine
"--prefix=${WPI_HOST_PREFIX}" # Filesystem prefix
"--program-prefix=${TARGET_PREFIX}" # Program prefix
"--disable-werror" # Allow host builds to be permissive
"--disable-nls" # Disable localization
"--disable-multilib" # Disable multilib for 64-bit targets

"--with-sysroot=${SYSROOT_PATH}"
)

xpushd "${BUILD_DIR}/binutils-build"
Expand Down
6 changes: 5 additions & 1 deletion makes/src/99-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ elif [ -e "/usr/bin/${HOST_TUPLE}-strip" ]; then
STRIP_CMD="/usr/bin/${HOST_TUPLE}-strip"
elif [ -e "/usr/bin/${WPI_HOST_TUPLE}-strip" ]; then
STRIP_CMD="/usr/bin/${WPI_HOST_TUPLE}-strip"
elif [ -e "/usr/bin/llvm-strip" ]; then
# LLVM strip is architecture agnostic
STRIP_CMD="/usr/bin/llvm-strip"
elif [ "${WPI_HOST_NAME}" = "Mac" ]; then
# Xcode strip is just LLVM strip
STRIP_CMD="strip"
else
die "Cannot find proper strip command"
warn "Cannot find proper strip command"
fi

# Remove any executables that may have the incorrect names
Expand Down
5 changes: 1 addition & 4 deletions makes/src/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,16 @@ CONFIGURE_COMMON_LITE=(
"--host=${HOST_TUPLE}"
"--prefix=${WPI_HOST_PREFIX}"
"--program-prefix=${TARGET_PREFIX}"
"--enable-lto"
"--disable-nls"
"--disable-plugin"
"--disable-werror"
"--disable-dependency-tracking"
"--disable-multilib"
)

CONFIGURE_COMMON=(
"${CONFIGURE_COMMON_LITE[@]}"
"--target=${TARGET_TUPLE}"
"--with-sysroot=${SYSROOT_PATH}"
"--libdir=${SYSROOT_PATH}/usr/lib"
"--with-toolexeclibdir=${SYSROOT_PATH}/usr/lib"
"--with-build-sysroot=${SYSROOT_BUILD_PATH}"
)

Expand Down
15 changes: 13 additions & 2 deletions makes/src/utils/conf-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ function gcc_make_multi() {
}

CONFIGURE_GCC=(
"${CONFIGURE_COMMON[@]}"
"--enable-poison-system-directories"
"--build=${BUILD_TUPLE}"
"--host=${HOST_TUPLE}"
"--target=${TARGET_TUPLE}"
"--prefix=${WPI_HOST_PREFIX}"
"--program-prefix=${TARGET_PREFIX}"
"--disable-werror"
"--disable-nls"
"--disable-multilib"

"--libdir=${SYSROOT_PATH}/usr/lib"
"--with-sysroot=${SYSROOT_PATH}"
"--with-build-sysroot=${SYSROOT_BUILD_PATH}"

"--enable-threads=posix"
"--enable-shared"
"--with-gcc-major-version-only"
Expand Down
5 changes: 3 additions & 2 deletions makes/src/utils/funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ configure_target_vars() {
gcc_update_target_list() {
env_exists SYSROOT_BUILD_PATH
gcc_need_lib_build() {
local lib="${SYSROOT_BUILD_PATH}/usr/lib/$1"
local lib1="${SYSROOT_BUILD_PATH}/usr/lib/$1"
local lib2="${SYSROOT_BUILD_PATH}/usr/lib/gcc/${TARGET_TUPLE}/${V_GCC/.*/}/$1"
if [ "$TARGET_LIB_REBUILD" = "true" ]; then
return 0
fi
if compgen -G "${lib}.so*" >/dev/null; then
if (compgen -G "${lib1}.so*" || compgen -G "${lib2}.so*") >/dev/null; then
return 1
fi
return 0
Expand Down
14 changes: 14 additions & 0 deletions patches/README.multiarch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Debian sysroot enablement

The Debian filesystem is different from the simple NI Linux layout. Debian chose
to use a design which allowed for the same development packages to be installed
with differing architectures. This can make Debian-to-Debian development quite
easy but it requires further patching to work with a third-party toolchain.

## GCC
* https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-10-debian/debian/patches/gcc-multiarch.diff
* https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-10-debian/debian/patches/gcc-multilib-multiarch.diff
* https://salsa.debian.org/toolchain-team/gcc/-/blob/gcc-10-debian/debian/patches/g%2B%2B-multiarch-incdir.diff

## Binutils
* https://salsa.debian.org/toolchain-team/binutils/-/blob/binutils-2.38/debian/patches/129_multiarch_libpath.patch
Loading

0 comments on commit b57d1be

Please sign in to comment.