Skip to content

Commit

Permalink
Switch to C++20
Browse files Browse the repository at this point in the history
glibc compatibility remains the same.

We now use clang and static libc++ for the Aarch64 build
because clang-11 offers better C++20 support than GCC 10.
  • Loading branch information
glebm committed Aug 31, 2023
1 parent caa4c2c commit ac4a07b
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 67 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/Linux_aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,40 @@ jobs:
with:
fetch-depth: 0

- name: Create Build Environment
# Work around the somewhat broken packages in the GitHub Actions Ubuntu 20.04 image.
# https://github.com/actions/runner-images/issues/4620#issuecomment-981333260
- name: Work around broken packages
run: sudo apt-get -y install --allow-downgrades libpcre2-8-0=10.34-7

- name: Add clang repo
run: |
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
sudo tee /etc/apt/sources.list.d/clang.list <<LIST
deb [arch=amd64,arm64] http://apt.llvm.org/focal/ llvm-toolchain-focal main
deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal main
LIST
# Installs dependencies, including arm64 libraries (runs `sudo apt-get update` as part of it)
- name: Install dependencies
run: Packaging/nix/debian-cross-aarch64-prep.sh --no-gcc

- name: Install clang-18
run: |
# Work around the somewhat broken packages in the GitHub Actions Ubuntu 20.04 image.
# https://github.com/actions/runner-images/issues/4620#issuecomment-981333260
sudo apt-get -y install --allow-downgrades libpcre2-8-0=10.34-7
Packaging/nix/debian-cross-aarch64-prep.sh
sudo apt-get install -yq --no-install-recommends clang-18 lld-18 libc++-18-dev:arm64 && \
sudo update-alternatives --install \
/usr/bin/clang++ clang++ /usr/bin/clang++-18 100 && \
sudo update-alternatives --install \
/usr/bin/clang clang /usr/bin/clang-18 100 \
--slave /usr/bin/lld lld /usr/bin/lld-18 \
--slave /usr/bin/ld.lld ld.lld /usr/bin/ld.lld-18 && \
cat /var/lib/dpkg/alternatives/clang && cat /var/lib/dpkg/alternatives/clang++
- name: Cache CMake build folder
uses: actions/cache@v3
with:
path: build
key: ${{ github.workflow }}-v2-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v2-
key: ${{ github.workflow }}-v6-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v6-

- name: Build
working-directory: ${{github.workspace}}
Expand All @@ -51,7 +72,7 @@ jobs:
# We set DEVILUTIONX_SYSTEM_LIBFMT=OFF because its soversion changes frequently.
# We set DEVILUTIONX_SYSTEM_SIMPLEINI=OFF because we require v4.19+, still missing from many distributions.
run: |
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/aarch64-linux-gnu.toolchain.cmake \
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE=../CMake/platforms/aarch64-linux-gnu-clang-static-libc++.toolchain.cmake \
-DCMAKE_BUILD_TYPE=${{env.CMAKE_BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=/usr -DCPACK=ON \
-DDEVILUTIONX_SYSTEM_LIBFMT=OFF -DDEVILUTIONX_SYSTEM_SIMPLEINI=OFF && \
cmake --build build -j $(getconf _NPROCESSORS_ONLN) --target package
Expand Down
26 changes: 19 additions & 7 deletions .github/workflows/Linux_x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,31 @@ jobs:
with:
fetch-depth: 0

- name: Create Build Environment
# Work around the somewhat broken packages in the GitHub Actions Ubuntu 20.04 image.
# https://github.com/actions/runner-images/issues/4620#issuecomment-981333260
- name: Work around broken packages
run: sudo apt-get -y install --allow-downgrades libpcre2-8-0=10.34-7

- name: Add gcc repo
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test

# Installs dependencies, including x86 libraries (runs `sudo apt-get update` as part of it)
- name: Install dependencies
run: Packaging/nix/debian-cross-i386-prep.sh --no-gcc

- name: Install gcc-13
run: |
# Work around the somewhat broken packages in the GitHub Actions Ubuntu 20.04 image.
# https://github.com/actions/runner-images/issues/4620#issuecomment-981333260
sudo apt-get -y install --allow-downgrades libpcre2-8-0=10.34-7
Packaging/nix/debian-cross-i386-prep.sh
sudo apt-get install -yq --no-install-recommends gcc-13 g++-13 g++-13-multilib && \
sudo update-alternatives --install \
/usr/bin/gcc gcc /usr/bin/gcc-13 13 \
--slave /usr/bin/g++ g++ /usr/bin/g++-13
- name: Cache CMake build folder
uses: actions/cache@v3
with:
path: build
key: ${{ github.workflow }}-v3-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v3-
key: ${{ github.workflow }}-v5-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v5-

- name: Build
working-directory: ${{github.workspace}}
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/Linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,29 @@ jobs:
with:
fetch-depth: 0

- name: Add gcc repo
run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test

# Installs dependencies and runs `sudo apt-get update` as part of it.
- name: Install dependencies
run: Packaging/nix/debian-host-prep.sh --no-gcc

- name: Install gcc-13
run: |
sudo apt-get install -yq --no-install-recommends gcc-13 g++-13 && \
sudo update-alternatives --install \
/usr/bin/gcc gcc /usr/bin/gcc-13 13 \
--slave /usr/bin/g++ g++ /usr/bin/g++-13
- name: Create Build Environment
run: Packaging/nix/debian-host-prep.sh
run: Packaging/nix/debian-host-prep.sh --no-gcc

- name: Cache CMake build folder
uses: actions/cache@v3
with:
path: build
key: ${{ github.workflow }}-v2-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v2-
key: ${{ github.workflow }}-v5-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v5-

- name: Build
working-directory: ${{github.workspace}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Linux_x86_64_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(triple aarch64-linux-gnu)

set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_C_COMPILER_TARGET "${triple}")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(CMAKE_CXX_FLAGS_INIT "-stdlib=libc++")
set(CMAKE_CXX_COMPILER_TARGET "${triple}")
set(CMAKE_ASM_COMPILER "/usr/bin/clang")
set(CMAKE_ASM_COMPILER_TARGET "${triple}")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=/usr/bin/ld.lld -static-libstdc++ -static-libgcc")

set(CMAKE_FIND_ROOT_PATH "/usr/aarch64-linux-gnu;/usr")
set(CMAKE_LIBRARY_ARCHITECTURE "${triple}")

set(PKG_CONFIG_EXECUTABLE "${CMAKE_CURRENT_LIST_DIR}/aarch64-linux-gnu-pkg-config" CACHE STRING "Path to pkg-config")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE arm64)
10 changes: 6 additions & 4 deletions CMake/platforms/debian-cross-pkg-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ if [ x"${PKG_CONFIG_LIBDIR+set}" = x ]; then
# Normalized multiarch path if any, e.g. i386-linux-gnu for i386
multiarch="`dpkg-architecture -t"${triplet}" -qDEB_HOST_MULTIARCH 2>/dev/null`"
# Native multiarch path
native_multiarch="$(cat /usr/lib/pkg-config.multiarch)"
if [ -f /usr/lib/pkg-config.multiarch ]; then
native_multiarch="$(cat /usr/lib/pkg-config.multiarch)"

# This can be used for native builds as well, in that case, just exec pkg-config "$@" directly.
if [ "$native_multiarch" = "$multiarch" ]; then
exec pkg-config "$@"
# This can be used for native builds as well, in that case, just exec pkg-config "$@" directly.
if [ "$native_multiarch" = "$multiarch" ]; then
exec pkg-config "$@"
fi
fi

PKG_CONFIG_LIBDIR="/usr/local/${triplet}/lib/pkgconfig"
Expand Down
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,9 @@ if(GPERF)
endif()
endif()

# Despite setting C++ standard to 20, features from this version are not being used.
# DevilutionX is compatible with C++ 17.
# Here we set it to 20 only to take advantage of the fmt::format build time errors.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for clang-tidy
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
16 changes: 13 additions & 3 deletions Packaging/nix/debian-cross-aarch64-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ LIST
cat /etc/apt/sources.list
fi


PACKAGES=(
cmake git smpq gettext dpkg-cross libc-dev-arm64-cross
libsdl2-dev:arm64 libsdl2-image-dev:arm64 libsodium-dev:arm64
libsimpleini-dev:arm64 libpng-dev:arm64 libbz2-dev:arm64 libfmt-dev:arm64
)

if (( $# < 1 )) || [[ "$1" != --no-gcc ]]; then
PACKAGES+=(crossbuild-essential-arm64)
fi


sudo dpkg --add-architecture arm64
sudo apt-get update
sudo apt-get install -y cmake git smpq gettext crossbuild-essential-arm64 \
libsdl2-dev:arm64 libsdl2-image-dev:arm64 libsodium-dev:arm64 \
libsimpleini-dev:arm64 libpng-dev:arm64 libbz2-dev:arm64 libfmt-dev:arm64
sudo apt-get install -y "${PACKAGES[@]}"
16 changes: 12 additions & 4 deletions Packaging/nix/debian-cross-i386-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
set -euo pipefail
set -x

PACKAGES=(
cmake git smpq gettext
libsdl2-dev:i386 libsdl2-image-dev:i386 libsodium-dev:i386
libpng-dev:i386 libbz2-dev:i386 libfmt-dev:i386
)

if (( $# < 1 )) || [[ "$1" != --no-gcc ]]; then
PACKAGES+=(g++-multilib)
fi

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install --ignore-hold -y \
cmake g++-multilib git smpq gettext \
libsdl2-dev:i386 libsdl2-image-dev:i386 libsodium-dev:i386 \
libpng-dev:i386 libbz2-dev:i386 libfmt-dev:i386
sudo apt-get install --ignore-hold -y "${PACKAGES[@]}"

14 changes: 11 additions & 3 deletions Packaging/nix/debian-host-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
set -euo pipefail
set -x

sudo apt-get update
sudo apt-get install -y \
rpm pkg-config cmake g++ git smpq gettext libsdl2-dev libsdl2-image-dev libsodium-dev \
PACKAGES=(
rpm pkg-config cmake git smpq gettext libsdl2-dev libsdl2-image-dev libsodium-dev
libpng-dev libbz2-dev libfmt-dev
)

if (( $# < 1 )) || [[ "$1" != --no-gcc ]]; then
PACKAGES+=(g++)
fi

sudo apt-get update
sudo apt-get install -y "${PACKAGES[@]}"

Loading

0 comments on commit ac4a07b

Please sign in to comment.