Skip to content

Commit 962b6e8

Browse files
authored
GCC 15.1.0 (#1)
1 parent c2d8ec8 commit 962b6e8

File tree

9 files changed

+639
-0
lines changed

9 files changed

+639
-0
lines changed

.github/workflows/build.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build Toolchain
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- v**
8+
pull_request:
9+
jobs:
10+
build:
11+
name: Build Toolchain
12+
runs-on: ubuntu-22.04
13+
strategy:
14+
matrix:
15+
target_arch: [aarch64, arm, i686, x86_64]
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@main
19+
with:
20+
path: ${{ github.workspace }}
21+
- name: Build Toolchain
22+
env:
23+
TOOLCHAIN_ARCH: ${{ matrix.target_arch }}
24+
run: |
25+
bash ./build.sh
26+
- name: Waiting for debugger
27+
if: ${{ failure() }}
28+
uses: mxschmitt/action-tmate@v3
29+
- name: Upload Build Archive
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: newer-toolchain-${{ matrix.target_arch }}-${{ github.sha }}
33+
path: ${{ github.workspace }}/build/
34+
release:
35+
name: Create Github Release
36+
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
37+
needs: build
38+
runs-on: ubuntu-22.04
39+
steps:
40+
- name: Fetch archives
41+
uses: actions/download-artifact@v4
42+
with:
43+
path: ./
44+
- name: Copy archives
45+
run: |
46+
cp newer-toolchain-*-${{ github.sha }}/*.tar.bz2 ./
47+
- name: Get checksums
48+
id: checksums
49+
run: |
50+
checksums=$(printf 'SHA-256:\n```\n%s\n```\n' "$(sha256sum *.tar.bz2)")
51+
checksums="${checksums//'%'/'%25'}"
52+
checksums="${checksums//$'\n'/'%0A'}"
53+
checksums="${checksums//$'\r'/'%0D'}"
54+
echo "::set-output name=checksums::$checksums"
55+
- name: Get tag
56+
id: tag
57+
uses: dawidd6/action-get-tag@v1
58+
- name: Publish GitHub release
59+
uses: svenstaro/upload-release-action@v2
60+
with:
61+
repo_token: ${{ secrets.GITHUB_TOKEN }}
62+
file: "*.tar.bz2"
63+
file_glob: true
64+
release_name: "Android NDK toolchain version r17c with gcc"
65+
tag: ${{ steps.tag.outputs.tag }}
66+
body: ${{ steps.checksums.outputs.checksums }}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Cache files
2+
/cache/
3+
4+
# Temp files
5+
/tmp/
6+
7+
# Build files
8+
/build/
9+
10+
# VSCode
11+
/.vscode/

build.sh

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
#!/bin/bash
2+
# build.sh - script to build a custom NDK toolchain
3+
#
4+
# Copyright 2022 Chongyun Lee <[email protected]>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
set -e -u -o pipefail
20+
21+
_SCRIPTDIR=$(cd "$(realpath "$(dirname "$0")")"; pwd)
22+
source $_SCRIPTDIR/common-files/setup_toolchain_ndk_r17c.sh
23+
source $_SCRIPTDIR/common-files/termux_download.sh
24+
25+
: ${TOOLCHAIN_ARCH:=aarch64}
26+
: ${_CACHE_DIR:=$_SCRIPTDIR/cache}
27+
: ${_TMP_DIR:=$_SCRIPTDIR/tmp}
28+
: ${_API_LEVEL:=21}
29+
: ${_MAKE_PROCESSES:=$(nproc)}
30+
: ${GCC_VERSION:=15.1.0}
31+
: ${GCC_SHA256:=51b9919ea69c980d7a381db95d4be27edf73b21254eb13d752a08003b4d013b1}
32+
: ${BINUTILS_VERSION:=2.44}
33+
: ${BINUTILS_SHA256:=0cdd76777a0dfd3dd3a63f215f030208ddb91c2361d2bcc02acec0f1c16b6a2e}
34+
35+
export TOOLCHAIN_ARCH
36+
37+
TERMUX_PKG_TMPDIR=$_TMP_DIR
38+
mkdir -p $_CACHE_DIR
39+
rm -rf $_TMP_DIR
40+
mkdir -p $_TMP_DIR
41+
42+
_HOST_PLATFORM="${TOOLCHAIN_ARCH}-linux-android"
43+
44+
_GCC_EXTRA_HOST_BUILD=""
45+
_BINUTILS_EXTRA_HOST_BUILD="--enable-gold"
46+
if [ "$TOOLCHAIN_ARCH" = "arm" ]; then
47+
_HOST_PLATFORM="${_HOST_PLATFORM}eabi"
48+
_GCC_EXTRA_HOST_BUILD="--with-arch=armv7-a --with-float=soft --with-fpu=vfp"
49+
elif [ "$TOOLCHAIN_ARCH" = "aarch64" ]; then
50+
_GCC_EXTRA_HOST_BUILD="--enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419"
51+
_BINUTILS_EXTRA_HOST_BUILD+=" $_GCC_EXTRA_HOST_BUILD"
52+
elif [ "$TOOLCHAIN_ARCH" = "i686" ]; then
53+
_GCC_EXTRA_HOST_BUILD="--with-arch=i686 --with-fpmath=sse "
54+
elif [ "$TOOLCHAIN_ARCH" = "x86_64" ]; then
55+
_GCC_EXTRA_HOST_BUILD="--with-arch=x86-64 --with-fpmath=sse"
56+
fi
57+
58+
# Install dependencies
59+
sudo apt update
60+
sudo apt install -y build-essential curl
61+
sudo apt install -y libgmp-dev libmpfr-dev libmpc-dev zlib1g-dev libisl-dev
62+
63+
pushd $_TMP_DIR
64+
65+
# Download source
66+
GCC_SRC_URL=https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz
67+
GCC_SRC_FILE=$_CACHE_DIR/gcc-${GCC_VERSION}.tar.gz
68+
GCC_SRC_DIR=$_TMP_DIR/gcc-${GCC_VERSION}
69+
termux_download $GCC_SRC_URL $GCC_SRC_FILE $GCC_SHA256
70+
BINUTILS_SRC_URL=https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz
71+
BINUTILS_SRC_FILE=$_CACHE_DIR/binutils-${BINUTILS_VERSION}.tar.gz
72+
BINUTILS_SRC_DIR=$_TMP_DIR/binutils-${BINUTILS_VERSION}
73+
termux_download $BINUTILS_SRC_URL $BINUTILS_SRC_FILE $BINUTILS_SHA256
74+
75+
# Setup a standalone toolchain
76+
_setup_standalone_toolchain_ndk_r17c $_TMP_DIR/standalone-toolchain
77+
cp -R $_TMP_DIR/standalone-toolchain/sysroot/usr/include/$_HOST_PLATFORM/* $_TMP_DIR/standalone-toolchain/sysroot/usr/include/
78+
79+
# Extract source
80+
tar -xf $GCC_SRC_FILE -C $_TMP_DIR/
81+
pushd $_TMP_DIR
82+
PATCHES="$(find "$_SCRIPTDIR/patches/" -maxdepth 1 -type f -name *.patch | sort)"
83+
for f in $PATCHES; do
84+
echo "Applying patch: $(basename $f)"
85+
patch -d "$GCC_SRC_DIR/" -p1 < "$f";
86+
done
87+
tar -xf $BINUTILS_SRC_FILE -C $_TMP_DIR/
88+
popd
89+
90+
# Copy sysroot
91+
mkdir -p $_TMP_DIR/newer-toolchain
92+
cp -R $_TMP_DIR/standalone-toolchain/sysroot $_TMP_DIR/newer-toolchain/
93+
94+
# Set CPPFLAGS/CFLAGS/CXXFLAGS
95+
export CPPFLAGS="-O3 -g0"
96+
export CFLAGS="$CPPFLAGS"
97+
export CXXFLAGS="$CPPFLAGS"
98+
99+
# Build binutils
100+
mkdir -p binutils-build
101+
pushd binutils-build
102+
$BINUTILS_SRC_DIR/configure \
103+
--target=$_HOST_PLATFORM \
104+
--prefix=$_TMP_DIR/newer-toolchain \
105+
--with-sysroot=$_TMP_DIR/newer-toolchain/sysroot \
106+
--with-zstd \
107+
ZSTD_LIBS=-l:libzstd.a \
108+
$_BINUTILS_EXTRA_HOST_BUILD
109+
make -j $_MAKE_PROCESSES
110+
make -j $_MAKE_PROCESSES install-strip
111+
popd # binutils-build
112+
113+
export PATH="$_TMP_DIR/newer-toolchain/bin:$PATH"
114+
115+
# Build GCC toolchain
116+
mkdir -p newer-toolchain-build
117+
pushd newer-toolchain-build
118+
119+
export CPPFLAGS+=" -D__ANDROID_API__=$_API_LEVEL"
120+
export CFLAGS+=" -D__ANDROID_API__=$_API_LEVEL"
121+
export CXXFLAGS+=" -D__ANDROID_API__=$_API_LEVEL"
122+
123+
$GCC_SRC_DIR/configure \
124+
--host=x86_64-linux-gnu \
125+
--build=x86_64-linux-gnu \
126+
--target=$_HOST_PLATFORM \
127+
--disable-shared \
128+
--disable-nls \
129+
--enable-default-pie \
130+
--with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' \
131+
--with-gnu-as --with-gnu-ld \
132+
--disable-libstdc__-v3 \
133+
--disable-tls \
134+
--disable-ssp \
135+
--disable-bootstrap \
136+
--enable-initfini-array \
137+
--enable-libatomic-ifuncs=no \
138+
--prefix=$_TMP_DIR/newer-toolchain \
139+
--with-gmp --with-mpfr --with-mpc --with-system-zlib \
140+
--enable-languages=c,c++,fortran \
141+
--enable-plugins --enable-libgomp \
142+
--enable-gnu-indirect-function \
143+
--disable-libcilkrts --disable-libsanitizer \
144+
--enable-gold --enable-threads \
145+
--enable-eh-frame-hdr-for-static \
146+
--enable-graphite=yes --with-isl \
147+
--disable-multilib \
148+
$_GCC_EXTRA_HOST_BUILD \
149+
--with-sysroot=$_TMP_DIR/newer-toolchain/sysroot \
150+
--with-gxx-include-dir=$_TMP_DIR/newer-toolchain/include/c++/$GCC_VERSION
151+
152+
make -j $_MAKE_PROCESSES
153+
make -j $_MAKE_PROCESSES install-strip
154+
155+
popd # newer-toolchain-build
156+
157+
# Make the archive
158+
mv newer-toolchain gcc-$GCC_VERSION-$TOOLCHAIN_ARCH
159+
tar -cjvf gcc-$GCC_VERSION-$TOOLCHAIN_ARCH.tar.bz2 gcc-$GCC_VERSION-$TOOLCHAIN_ARCH
160+
161+
popd # $_TMP_DIR
162+
163+
# Copy the archive
164+
mkdir -p build
165+
cp $_TMP_DIR/gcc-$GCC_VERSION-$TOOLCHAIN_ARCH.tar.bz2 ./build
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
_download_ndk_r17c() {
2+
if [ ! -f $_CACHE_DIR/.placeholder-android-ndk-r17c ]; then
3+
echo "Start downloading Android NDK toolchain (version r17c)..."
4+
mkdir -p $_CACHE_DIR/
5+
local _NDKARCHIVE_FILE=$_CACHE_DIR/android-ndk-r17c-linux-x86_64.zip
6+
local _NDK_URL=https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip
7+
local _NDK_SHA256=3f541adbd0330a9205ba12697f6d04ec90752c53d6b622101a2a8a856e816589
8+
termux_download $_NDK_URL $_NDKARCHIVE_FILE $_NDK_SHA256
9+
unzip -d $_CACHE_DIR/ $_NDKARCHIVE_FILE > /dev/null 2>&1
10+
touch $_CACHE_DIR/.placeholder-android-ndk-r17c
11+
echo "Downloading completed."
12+
fi
13+
}
14+
15+
_setup_standalone_toolchain_ndk_r17c() {
16+
_download_ndk_r17c
17+
18+
local TOOLCHAIN_DIR="$1"
19+
rm -rf $TOOLCHAIN_DIR
20+
21+
local _NDKARCH
22+
if [ "$TOOLCHAIN_ARCH" == "aarch64" ]; then
23+
_NDKARCH="arm64"
24+
elif [ "$TOOLCHAIN_ARCH" == "arm" ]; then
25+
_NDKARCH="arm"
26+
elif [ "$TOOLCHAIN_ARCH" == "x86_64" ]; then
27+
_NDKARCH="x86_64"
28+
elif [ "$TOOLCHAIN_ARCH" == "i686" ]; then
29+
_NDKARCH="x86"
30+
fi
31+
32+
# Setup a standalone toolchain
33+
python $_CACHE_DIR/android-ndk-r17c/build/tools/make_standalone_toolchain.py \
34+
--arch $_NDKARCH --api $_API_LEVEL --install-dir $TOOLCHAIN_DIR
35+
36+
# Modify sysroot
37+
pushd $TOOLCHAIN_DIR
38+
39+
# See https://github.com/android/ndk/issues/215#issuecomment-524293090
40+
sed -i "s/include_next <stddef.h>/include <stddef.h>/" include/c++/4.9.x/cstddef
41+
42+
sed -i "s/define __ANDROID_API__ __ANDROID_API_FUTURE__/define __ANDROID_API__ $_API_LEVEL/" \
43+
sysroot/usr/include/android/api-level.h
44+
popd
45+
}

common-files/termux_download.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/bash
2+
##
3+
## Copyright 2020 Termux
4+
##
5+
## Licensed under the Apache License, Version 2.0 (the "License");
6+
## you may not use this file except in compliance with the License.
7+
## You may obtain a copy of the License at
8+
##
9+
## http://www.apache.org/licenses/LICENSE-2.0
10+
##
11+
## Unless required by applicable law or agreed to in writing, software
12+
## distributed under the License is distributed on an "AS IS" BASIS,
13+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
## See the License for the specific language governing permissions and
15+
## limitations under the License.
16+
##
17+
18+
termux_download() {
19+
if [ $# != 3 ]; then
20+
termux_error_exit "termux_download(): Invalid arguments - expected \$URL \$DESTINATION \$CHECKSUM"
21+
fi
22+
local URL="$1"
23+
local DESTINATION="$2"
24+
local CHECKSUM="$3"
25+
26+
if [ -f "$DESTINATION" ] && [ "$CHECKSUM" != "SKIP_CHECKSUM" ]; then
27+
# Keep existing file if checksum matches.
28+
local EXISTING_CHECKSUM
29+
EXISTING_CHECKSUM=$(sha256sum "$DESTINATION" | cut -f 1 -d ' ')
30+
if [ "$EXISTING_CHECKSUM" = "$CHECKSUM" ]; then return; fi
31+
fi
32+
33+
local TMPFILE
34+
TMPFILE=$(mktemp "$TERMUX_PKG_TMPDIR/download.${TERMUX_PKG_NAME-unnamed}.XXXXXXXXX")
35+
echo "Downloading ${URL}"
36+
if curl --fail --retry 20 --retry-connrefused --retry-delay 30 --location --output "$TMPFILE" "$URL"; then
37+
local ACTUAL_CHECKSUM
38+
ACTUAL_CHECKSUM=$(sha256sum "$TMPFILE" | cut -f 1 -d ' ')
39+
if [ "$CHECKSUM" != "SKIP_CHECKSUM" ]; then
40+
if [ "$CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
41+
>&2 printf "Wrong checksum for %s:\nExpected: %s\nActual: %s\n" \
42+
"$URL" "$CHECKSUM" "$ACTUAL_CHECKSUM"
43+
return 1
44+
fi
45+
elif [ -z "$CHECKSUM" ]; then
46+
printf "WARNING: No checksum check for %s:\nActual: %s\n" \
47+
"$URL" "$ACTUAL_CHECKSUM"
48+
fi
49+
mv "$TMPFILE" "$DESTINATION"
50+
return 0
51+
fi
52+
53+
echo "Failed to download $URL" >&2
54+
return 1
55+
}
56+
57+
# Make script standalone executable as well as sourceable
58+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
59+
termux_download "$@"
60+
fi

0 commit comments

Comments
 (0)