Skip to content

Commit

Permalink
Update to GCC 12.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed Aug 25, 2023
1 parent d01264d commit 54828f2
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 71 deletions.
77 changes: 55 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,64 @@ on:
- '**'

jobs:
build:
native-build:
name: 'Native build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
with:
submodules: true
- name: Build Atar
run: |
bash './build.sh' 'native'
- name: Generate tarball
run: |
declare tarball_filename='/tmp/x86_64-linux-gnu.tar.xz'
tar --directory='/tmp' --create --file=- 'atar' | xz --threads='0' --compress -9 > "${tarball_filename}"
sha256sum "${tarball_filename}" | sed 's|/tmp/||' > "${tarball_filename}.sha256"
- name: Upload artifact
uses: actions/upload-artifact@main
with:
name: native-toolchain
if-no-files-found: error
path: |
/tmp/x86_64-linux-gnu.tar.xz
/tmp/x86_64-linux-gnu.tar.xz.sha256
cross-build:
name: 'Cross build'
needs: native-build
runs-on: ubuntu-latest
strategy:
matrix:
target: [
alpha-unknown-linux-gnu,
x86_64-unknown-linux-gnu,
i386-unknown-linux-gnu,
arm-unknown-linux-gnueabi,
arm-unknown-linux-gnueabihf,
hppa-unknown-linux-gnu,
aarch64-unknown-linux-gnu,
mips-unknown-linux-gnu,
mipsel-unknown-linux-gnu,
powerpc-unknown-linux-gnu,
s390-unknown-linux-gnu,
s390x-unknown-linux-gnu,
sparc-unknown-linux-gnu,
powerpc64le-unknown-linux-gnu
'alpha-unknown-linux-gnu',
'x86_64-unknown-linux-gnu',
'i386-unknown-linux-gnu',
'arm-unknown-linux-gnueabi',
'arm-unknown-linux-gnueabihf',
'hppa-unknown-linux-gnu',
'aarch64-unknown-linux-gnu',
'mips-unknown-linux-gnu',
'mipsel-unknown-linux-gnu',
'powerpc-unknown-linux-gnu',
's390-unknown-linux-gnu',
's390x-unknown-linux-gnu',
'sparc-unknown-linux-gnu',
'powerpc64le-unknown-linux-gnu'
]
steps:
- uses: actions/checkout@main
with:
submodules: true
- name: Install required dependencies
- name: Download artifact
uses: actions/download-artifact@main
with:
name: native-toolchain
- name: Setup toolchain
run: |
sudo apt-get install --assume-yes libfl-dev
tar --directory='/tmp' --extract --file='./x86_64-linux-gnu.tar.xz'
mv '/tmp/atar' '/tmp/atar-toolchain'
- name: Build Atar with OBGGCC
run: |
source './tools/setup_toolchain.sh'
Expand All @@ -41,12 +72,14 @@ jobs:
bash './build.sh' '${{ matrix.target }}'
- name: Generate tarball
run: |
declare tarball_filename='${{ matrix.target }}.tar.xz'
tar --directory='/tmp' --create --file=- 'atar' | xz --threads=0 --compress -9 > "${tarball_filename}"
sha256sum "${tarball_filename}" > "${tarball_filename}.sha256"
declare tarball_filename='/tmp/${{ matrix.target }}.tar.xz'
tar --directory='/tmp' --create --file=- 'atar' | xz --threads='0' --compress -9 > "${tarball_filename}"
sha256sum "${tarball_filename}" | sed 's|/tmp/||' > "${tarball_filename}.sha256"
- name: Upload artifact
uses: actions/upload-artifact@main
with:
name: cross-toolchain
if-no-files-found: error
path: |
${{ matrix.target }}.tar.xz
${{ matrix.target }}.tar.xz.sha256
/tmp/${{ matrix.target }}.tar.xz
/tmp/${{ matrix.target }}.tar.xz.sha256
114 changes: 66 additions & 48 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,37 @@ declare -r mpc_tarball='/tmp/mpc.tar.gz'
declare -r mpc_directory='/tmp/mpc-1.3.1'

declare -r binutils_tarball='/tmp/binutils.tar.xz'
declare -r binutils_directory='/tmp/binutils-2.40'
declare -r binutils_directory='/tmp/binutils-2.41'

declare -r gcc_tarball='/tmp/gcc.tar.xz'
declare -r gcc_directory='/tmp/gcc-12.2.0'
declare -r gcc_directory='/tmp/gcc-12.3.0'

declare -r optflags='-Os'
declare -r linkflags='-Wl,-s'

source "./submodules/obggcc/toolchains/${1}.sh"
declare -r max_jobs="$(($(nproc) * 8))"

declare build_type="${1}"

if [ -z "${build_type}" ]; then
build_type='native'
fi

declare is_native='0'

if [ "${build_type}" == 'native' ]; then
is_native='1'
fi

declare OBGGCC_TOOLCHAIN='/tmp/obggcc-toolchain'
declare CROSS_COMPILE_TRIPLET=''

declare cross_compile_flags=''

if ! (( is_native )); then
source "./submodules/obggcc/toolchains/${build_type}.sh"
cross_compile_flags+="--host=${CROSS_COMPILE_TRIPLET}"
fi

if ! [ -f "${gmp_tarball}" ]; then
wget --no-verbose 'https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz' --output-document="${gmp_tarball}"
Expand All @@ -40,12 +62,12 @@ if ! [ -f "${mpc_tarball}" ]; then
fi

if ! [ -f "${binutils_tarball}" ]; then
wget --no-verbose 'https://ftp.gnu.org/gnu/binutils/binutils-2.40.tar.xz' --output-document="${binutils_tarball}"
wget --no-verbose 'https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.xz' --output-document="${binutils_tarball}"
tar --directory="$(dirname "${binutils_directory}")" --extract --file="${binutils_tarball}"
fi

if ! [ -f "${gcc_tarball}" ]; then
wget --no-verbose 'https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz' --output-document="${gcc_tarball}"
wget --no-verbose 'https://ftp.gnu.org/gnu/gcc/gcc-12.3.0/gcc-12.3.0.tar.xz' --output-document="${gcc_tarball}"
tar --directory="$(dirname "${gcc_directory}")" --extract --file="${gcc_tarball}"
fi

Expand All @@ -59,15 +81,15 @@ cd "${gmp_directory}/build"
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--prefix="${toolchain_directory}" \
--enable-shared \
--enable-static \
${cross_compile_flags} \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(($(nproc) * 8))"
make all --jobs
make install

[ -d "${mpfr_directory}/build" ] || mkdir "${mpfr_directory}/build"
Expand All @@ -76,16 +98,16 @@ cd "${mpfr_directory}/build"
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--prefix="${toolchain_directory}" \
--with-gmp="${toolchain_directory}" \
--enable-shared \
--enable-static \
${cross_compile_flags} \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(($(nproc) * 8))"
make all --jobs
make install

[ -d "${mpc_directory}/build" ] || mkdir "${mpc_directory}/build"
Expand All @@ -94,68 +116,68 @@ cd "${mpc_directory}/build"
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--prefix="${toolchain_directory}" \
--with-gmp="${toolchain_directory}" \
--enable-shared \
--enable-static \
${cross_compile_flags} \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(($(nproc) * 8))"
make all --jobs
make install

sed -i 's/#include <stdint.h>/#include <stdint.h>\n#include <stdio.h>/g' "${toolchain_directory}/include/mpc.h"

[ -d "${binutils_directory}/build" ] || mkdir "${binutils_directory}/build"

declare -r targets=(
'amd64'
'i386'
'hppa'
'alpha'
'amd64'
'i386'
)

for target in "${targets[@]}"; do
case "${target}" in
amd64)
declare triple='x86_64-unknown-openbsd';;
declare triplet='x86_64-unknown-openbsd';;
i386)
declare triple='i386-unknown-openbsd';;
declare triplet='i386-unknown-openbsd';;
hppa)
declare triple='hppa-unknown-openbsd';;
declare triplet='hppa-unknown-openbsd';;
alpha)
declare triple='alpha-unknown-openbsd';;
declare triplet='alpha-unknown-openbsd';;
esac

wget --no-verbose "https://ftp.openbsd.org/pub/OpenBSD/7.0/${target}/base70.tgz" --output-document='/tmp/base.tgz'
wget --no-verbose "https://ftp.openbsd.org/pub/OpenBSD/7.0/${target}/comp70.tgz" --output-document='/tmp/comp.tgz'
wget --no-verbose "https://mirrors.ucr.ac.cr/pub/OpenBSD/7.0/${target}/base70.tgz" --output-document='/tmp/base.tgz'
wget --no-verbose "https://mirrors.ucr.ac.cr/pub/OpenBSD/7.0/${target}/comp70.tgz" --output-document='/tmp/comp.tgz'

cd "${binutils_directory}/build"
rm --force --recursive ./*

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--target="${triple}" \
--target="${triplet}" \
--prefix="${toolchain_directory}" \
--enable-gold \
--enable-ld \
--enable-lto \
--disable-gprofng \
--with-static-standard-libraries \
--program-prefix="${triple}-" \
--with-sysroot="${toolchain_directory}/${triplet}" \
${cross_compile_flags} \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
LDFLAGS="${linkflags}"

make all --jobs="$(($(nproc) * 8))"
make all --jobs="${max_jobs}"
make install

tar --directory="${toolchain_directory}/${triple}" --strip=2 --extract --file='/tmp/base.tgz' './usr/lib' './usr/include'
tar --directory="${toolchain_directory}/${triple}" --strip=2 --extract --file='/tmp/comp.tgz' './usr/lib' './usr/include'
tar --directory="${toolchain_directory}/${triplet}" --strip=2 --extract --file='/tmp/base.tgz' './usr/lib' './usr/include'
tar --directory="${toolchain_directory}/${triplet}" --strip=2 --extract --file='/tmp/comp.tgz' './usr/lib' './usr/include'

cd "${toolchain_directory}/${triple}/lib"
cd "${toolchain_directory}/${triplet}/lib"

while read source; do
IFS='.' read -ra parts <<< "${source}"
Expand All @@ -177,14 +199,17 @@ for target in "${targets[@]}"; do
fi

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--target="${triple}" \
--target="${triplet}" \
--prefix="${toolchain_directory}" \
--with-linker-hash-style='gnu' \
--with-gmp="${toolchain_directory}" \
--with-mpc="${toolchain_directory}" \
--with-mpfr="${toolchain_directory}" \
--with-bugurl='https://github.com/AmanoTeam/Atar/issues' \
--with-gcc-major-version-only \
--with-pkgversion="Atar v0.3-${revision}" \
--with-sysroot="${toolchain_directory}/${triplet}" \
--with-native-system-header-dir='/include' \
--enable-__cxa_atexit \
--enable-cet='auto' \
--enable-checking='release' \
Expand All @@ -195,24 +220,21 @@ for target in "${targets[@]}"; do
--enable-link-serialization='1' \
--enable-linker-build-id \
--enable-lto \
--disable-multilib \
--enable-plugin \
--enable-shared \
--enable-threads='posix' \
--enable-libssp \
--enable-languages='c,c++' \
--enable-ld \
--enable-gold \
--disable-multilib \
--disable-libstdcxx-pch \
--disable-werror \
--enable-languages='c,c++' \
--disable-bootstrap \
--disable-libatomic \
--without-headers \
--enable-ld \
--enable-gold \
--with-gcc-major-version-only \
--with-pkgversion="Atar v0.2-${revision}" \
--with-sysroot="${toolchain_directory}/${triple}" \
--with-native-system-header-dir='/include' \
--disable-nls \
--without-headers \
${cross_compile_flags} \
${extra_configure_flags} \
CFLAGS="${optflags}" \
CXXFLAGS="${optflags}" \
Expand All @@ -221,24 +243,20 @@ for target in "${targets[@]}"; do
LD_LIBRARY_PATH="${toolchain_directory}/lib" PATH="${PATH}:${toolchain_directory}/bin" make \
CFLAGS_FOR_TARGET="${optflags} ${linkflags}" \
CXXFLAGS_FOR_TARGET="${optflags} ${linkflags}" \
all --jobs="$(($(nproc) * 8))"
all --jobs="${max_jobs}"
make install

cd "${toolchain_directory}/${triple}/bin"
cd "${toolchain_directory}/${triplet}/bin"

for name in *; do
rm "${name}"
ln -s "../../bin/${triple}-${name}" "${name}"
ln -s "../../bin/${triplet}-${name}" "${name}"
done

rm --recursive "${toolchain_directory}/share"
rm --recursive "${toolchain_directory}/lib/gcc/${triple}/12/include-fixed"

if [ "${CROSS_COMPILE_TRIPLET}" == "${triple}" ]; then
rm "${toolchain_directory}/bin/${triple}-${triple}"*
fi
rm --recursive "${toolchain_directory}/lib/gcc/${triplet}/"*"/include-fixed"

patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/12/cc1"
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/12/cc1plus"
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triple}/12/lto1"
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/cc1"
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/cc1plus"
patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/lto1"
done

0 comments on commit 54828f2

Please sign in to comment.