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 1ffeabe commit c8d6470
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 73 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 Dakini
run: |
bash './build.sh' 'native'
- name: Generate tarball
run: |
declare tarball_filename='/tmp/x86_64-linux-gnu.tar.xz'
tar --directory='/tmp' --create --file=- 'dakini' | 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/dakini' '/tmp/dakini-toolchain'
- name: Build Dakini 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=- 'dakini' | 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=- 'dakini' | 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
120 changes: 69 additions & 51 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,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 @@ -42,12 +64,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 @@ -61,15 +83,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="${max_jobs}"
make install

[ -d "${mpfr_directory}/build" ] || mkdir "${mpfr_directory}/build"
Expand All @@ -78,16 +100,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="${max_jobs}"
make install

[ -d "${mpc_directory}/build" ] || mkdir "${mpc_directory}/build"
Expand All @@ -96,28 +118,28 @@ 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="${max_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=(
'hppa'
'amd64'
'i386'
'emips'
'alpha'
'hppa'
'sparc'
'sparc64'
'vax'
Expand All @@ -130,25 +152,25 @@ for target in "${targets[@]}"; do

case "${target}" in
amd64)
declare triple='x86_64-unknown-netbsd';;
declare triplet='x86_64-unknown-netbsd';;
i386)
declare triple='i386-unknown-netbsdelf';;
declare triplet='i386-unknown-netbsdelf';;
emips)
declare triple='mips-unknown-netbsd';;
declare triplet='mips-unknown-netbsd';;
alpha)
declare triple='alpha-unknown-netbsd';;
declare triplet='alpha-unknown-netbsd';;
hppa)
declare triple='hppa-unknown-netbsd';;
declare triplet='hppa-unknown-netbsd';;
sparc)
declare triple='sparc-unknown-netbsdelf';;
declare triplet='sparc-unknown-netbsdelf';;
sparc64)
declare triple='sparc64-unknown-netbsd';;
declare triplet='sparc64-unknown-netbsd';;
vax)
declare triple='vax-unknown-netbsdelf';;
declare triplet='vax-unknown-netbsdelf';;
hpcsh)
declare triple='shle-unknown-netbsdelf';;
declare triplet='shle-unknown-netbsdelf';;
evbppc)
declare triple='powerpc-unknown-netbsd';;
declare triplet='powerpc-unknown-netbsd';;
esac

declare base_url="${url}/base.tgz"
Expand All @@ -164,25 +186,25 @@ for target in "${targets[@]}"; do
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="${base_output}" './usr/lib' './usr/include'
tar --directory="${toolchain_directory}/${triple}" --extract --file="${base_output}" './lib'
tar --directory="${toolchain_directory}/${triple}" --strip=2 --extract --file="${comp_output}" './usr/lib' './usr/include'
tar --directory="${toolchain_directory}/${triplet}" --strip=2 --extract --file="${base_output}" './usr/lib' './usr/include'
tar --directory="${toolchain_directory}/${triplet}" --extract --file="${base_output}" './lib'
tar --directory="${toolchain_directory}/${triplet}" --strip=2 --extract --file="${comp_output}" './usr/lib' './usr/include'

cd "${gcc_directory}/build"

Expand All @@ -206,14 +228,17 @@ for target in "${targets[@]}"; do
fi

../configure \
--host="${CROSS_COMPILE_TRIPLET}" \
--target="${triple}" \
--target="${triplet}" \
--prefix="${toolchain_directory}" \
--with-linker-hash-style='sysv' \
--with-gmp="${toolchain_directory}" \
--with-mpc="${toolchain_directory}" \
--with-mpfr="${toolchain_directory}" \
--with-bugurl='https://github.com/AmanoTeam/Dakini/issues' \
--with-gcc-major-version-only \
--with-pkgversion="Dakini v0.4-${revision}" \
--with-sysroot="${toolchain_directory}/${triplet}" \
--with-native-system-header-dir='/include' \
--enable-__cxa_atexit \
--enable-cet='auto' \
--enable-checking='release' \
Expand All @@ -224,23 +249,20 @@ 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-languages='c,c++' \
--enable-libssp \
--enable-ld \
--enable-gold \
--disable-multilib \
--disable-libstdcxx-pch \
--disable-werror \
--enable-languages='c,c++' \
--disable-bootstrap \
--without-headers \
--enable-ld \
--enable-gold \
--with-gcc-major-version-only \
--with-pkgversion="Dakini v0.3-${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 @@ -249,24 +271,20 @@ for target in "${targets[@]}"; do
LD_LIBRARY_PATH="${toolchain_directory}/lib" PATH="${PATH}:${toolchain_directory}/bin" make \
CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET}" \
CXXFLAGS_FOR_TARGET="${CXXFLAGS_FOR_TARGET}" \
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 c8d6470

Please sign in to comment.