From 060b01260dac81e1854dce9499036948aba28281 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sun, 25 Jun 2023 19:40:09 +0200 Subject: [PATCH] CI: yet more updates --- .clang-format | 4 +- .github/workflows/test-cmake-default.yml | 102 ++++++++++++++++++ .github/workflows/weekly-ci-alpine-linux.yml | 46 ++++---- .../weekly-ci-cmake-windows-nmake.yml | 9 +- src/check/dt_check.cpp | 1 + src/headers.h | 23 ++++ 6 files changed, 160 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/test-cmake-default.yml diff --git a/.clang-format b/.clang-format index 9d4d8c2d..7b107654 100644 --- a/.clang-format +++ b/.clang-format @@ -16,12 +16,14 @@ AttributeMacros: - __acc_cdecl_sighandler - __acc_forceinline - __acc_noinline - - __acc_static_noinline - __acc_static_forceinline + - __acc_static_noinline - DELETED_FUNCTION - XSPAN_DELETED_FUNCTION - forceinline - noinline + - static_forceinline + - static_noinline EmptyLineBeforeAccessModifier: Leave SortIncludes: false SpaceAfterCStyleCast: true diff --git a/.github/workflows/test-cmake-default.yml b/.github/workflows/test-cmake-default.yml new file mode 100644 index 00000000..00425383 --- /dev/null +++ b/.github/workflows/test-cmake-default.yml @@ -0,0 +1,102 @@ +# Copyright (C) Markus Franz Xaver Johannes Oberhumer + +name: 'Test - CMake default build type' +on: [workflow_dispatch] +jobs: + + job-cmake-make: + runs-on: ubuntu-latest + steps: + - name: 'Check out code' + uses: actions/checkout@v3 + with: { submodules: true } + - name: 'Config, build, test and install' + run: | + cmake -S . -B build/default + cmake --build build/default --parallel --verbose + ctest --test-dir build/default + make -C build/default test + (cd build/default && DESTDIR=$PWD/Install-default cmake --install .) + + job-cmake-ninja: + runs-on: ubuntu-latest + steps: + - name: 'Check out code' + uses: actions/checkout@v3 + with: { submodules: true } + - name: 'Config, build, test and install' + run: | + sudo apt-get install ninja-build + cmake -S . -B build/default -G Ninja + cmake --build build/default --parallel --verbose + ctest --test-dir build/default + ninja -C build/default test + (cd build/default && DESTDIR=$PWD/Install-default cmake --install .) + + job-cmake-ninja-multi-config: + runs-on: ubuntu-latest + steps: + - name: 'Check out code' + uses: actions/checkout@v3 + with: { submodules: true } + - name: 'Config, build, test and install' + run: | + sudo apt-get install ninja-build + cmake -S . -B build/default -G "Ninja Multi-Config" + cmake --build build/default --parallel --verbose + # multi-config: ctest NEEDS a config + ctest --test-dir build/default -C Release + ninja -C build/default test + (cd build/default && DESTDIR=$PWD/Install-default cmake --install .) + + job-cmake-nmake: + runs-on: windows-2022 + steps: + - name: 'Check out code' + uses: actions/checkout@v3 + with: { submodules: true } + - name: 'Set up Developer Command Prompt' + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: amd64 + vsversion: 2022 + - name: 'Config, build, test and install' + run: | + cmake -S . -B build/default -G "NMake Makefiles" + cmake --build build/default --parallel --verbose + ctest --test-dir build/default + env -C build/default nmake test + env DESTDIR=./Install-default cmake --install build/default + + job-cmake-vsstudio-multi-config: + runs-on: windows-2022 + steps: + - name: 'Check out code' + uses: actions/checkout@v3 + with: { submodules: true } + - name: 'Set up Developer Command Prompt' + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: amd64 + vsversion: 2022 + - name: 'Config, build and test' + run: | + cmake -S . -B build/default + cmake --build build/default --parallel --verbose + # multi-config: ctest NEEDS a config + ctest --test-dir build/default -C Debug + + job-cmake-xcode-multi-config: + runs-on: macos-12 + steps: + - name: 'Check out code' + uses: actions/checkout@v3 + with: { submodules: true } + - name: 'Config, build, test and install' + run: | + cmake -S . -B build/default -G Xcode + cmake --build build/default --parallel --verbose + # multi-config: ctest NEEDS a config + ctest --test-dir build/default -C Debug + # BUG multi-config: cmake --install defaults to "Release" !! + (cd build/default && DESTDIR=$PWD/Install-default cmake --install . --config Debug) diff --git a/.github/workflows/weekly-ci-alpine-linux.yml b/.github/workflows/weekly-ci-alpine-linux.yml index e8965f1e..957bd80b 100644 --- a/.github/workflows/weekly-ci-alpine-linux.yml +++ b/.github/workflows/weekly-ci-alpine-linux.yml @@ -1,5 +1,6 @@ # Copyright (C) Markus Franz Xaver Johannes Oberhumer -# build under various Alpine Linux versions with clang and gcc +# build under various Alpine Linux versions with clang and gcc, and +# also test building with C++20 and C++23 # info: Alpine 3.9 has clang-5, cmake-3.13.0 and gcc-8, which nicely # matches our minimal build requirements @@ -14,7 +15,6 @@ jobs: job-alpine-cmake: strategy: fail-fast: false -# matrix: { container: ['alpine:3.12','alpine:3.18','alpine:edge','i386/alpine:edge'] } matrix: { container: ['alpine:3.9','alpine:3.10','alpine:3.11','alpine:3.12','alpine:3.13','alpine:3.14','alpine:3.15','alpine:3.16','alpine:3.17','alpine:3.18','alpine:edge','i386/alpine:edge'] } name: ${{ format('container {0}', matrix.container) }} runs-on: ubuntu-latest @@ -37,7 +37,7 @@ jobs: N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-weekly-ci-alpine-${{ matrix.container }}" | sed 's/[^0-9a-zA-Z_.-]/-/g') echo "artifact_name=$N" >> $GITHUB_ENV - # build with C++17 + # build with default C11 and C++17 - name: ${{ format('Build clang Release with {0}', env.clang_package) }} run: 'make -C upx UPX_XTARGET=clang-static CC="clang -static" CXX="clang++ -static"' - name: ${{ format('Build clang Debug with {0}', env.clang_package) }} @@ -47,49 +47,45 @@ jobs: - name: ${{ format('Build gcc Debug with {0}', env.gcc_package) }} run: 'make -C upx UPX_XTARGET=gcc-static CC="gcc -static" CXX="g++ -static" xtarget/debug' - # build with C++20 on alpine:edge + - name: 'Update environment' + run: | + echo "UPX_CMAKE_CONFIG_FLAGS=-DCMAKE_VERBOSE_MAKEFILE=ON -DUPX_CONFIG_DISABLE_C_STANDARD=ON -DUPX_CONFIG_DISABLE_CXX_STANDARD=ON" >> $GITHUB_ENV + + # build with C17 and C++20 on alpine:edge - name: ${{ format('Build clang C++20 Release with {0}', env.clang_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=clang-cxx20-static CC="clang -static" CXX="clang++ -std=gnu++20 -static" + make -C upx UPX_XTARGET=clang-cxx20-static CC="clang -std=gnu17 -static" CXX="clang++ -std=gnu++20 -static" - name: ${{ format('Build clang C++20 Debug with {0}', env.clang_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=clang-cxx20-static CC="clang -static" CXX="clang++ -std=gnu++20 -static" xtarget/debug + make -C upx UPX_XTARGET=clang-cxx20-static CC="clang -std=gnu17 -static" CXX="clang++ -std=gnu++20 -static" xtarget/debug - name: ${{ format('Build gcc C++20 Release with {0}', env.gcc_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=gcc-cxx20-static CC="gcc -static" CXX="g++ -std=gnu++20 -static" + make -C upx UPX_XTARGET=gcc-cxx20-static CC="gcc -std=gnu17 -static" CXX="g++ -std=gnu++20 -static" - name: ${{ format('Build gcc C++20 Debug with {0}', env.gcc_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=gcc-cxx20-static CC="gcc -static" CXX="g++ -std=gnu++20 -static" xtarget/debug + make -C upx UPX_XTARGET=gcc-cxx20-static CC="gcc -std=gnu17 -static" CXX="g++ -std=gnu++20 -static" xtarget/debug - # build with C++23 on alpine:edge + # build with C23 and C++23 on alpine:edge - name: ${{ format('Build clang C++23 Release with {0}', env.clang_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=clang-cxx23-static CC="clang -static" CXX="clang++ -std=gnu++23 -static" + make -C upx UPX_XTARGET=clang-cxx23-static CC="clang -std=gnu2x -static" CXX="clang++ -std=gnu++2b -static" - name: ${{ format('Build clang C++23 Debug with {0}', env.clang_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=clang-cxx23-static CC="clang -static" CXX="clang++ -std=gnu++23 -static" xtarget/debug + make -C upx UPX_XTARGET=clang-cxx23-static CC="clang -std=gnu2x -static" CXX="clang++ -std=gnu++2b -static" xtarget/debug - name: ${{ format('Build gcc C++23 Release with {0}', env.gcc_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=gcc-cxx23-static CC="gcc -static" CXX="g++ -std=gnu++23 -static" + make -C upx UPX_XTARGET=gcc-cxx23-static CC="gcc -std=gnu2x -static" CXX="g++ -std=gnu++23 -static" - name: ${{ format('Build gcc C++23 Debug with {0}', env.gcc_package) }} if: ${{ contains(matrix.container, ':edge') }} run: | - export UPX_CMAKE_CONFIG_FLAGS='-DUPX_CONFIG_DISABLE_CXX_STANDARD=ON -DCMAKE_VERBOSE_MAKEFILE=ON' - make -C upx UPX_XTARGET=gcc-cxx23-static CC="gcc -static" CXX="g++ -std=gnu++23 -static" xtarget/debug + make -C upx UPX_XTARGET=gcc-cxx23-static CC="gcc -std=gnu2x -static" CXX="g++ -std=gnu++23 -static" xtarget/debug - { name: 'Strip release binaries', run: 'strip -p --strip-unneeded upx/build/*/*/release/upx' } - name: ${{ format('Upload artifact {0}', env.artifact_name) }} @@ -98,7 +94,15 @@ jobs: with: name: ${{ env.artifact_name }} path: 'upx*/build/*/*/*/upx' + - { name: 'Run basic tests clang Release', run: 'make -C upx/build/xtarget/clang-static/release test' } - { name: 'Run basic tests clang Debug', run: 'make -C upx/build/xtarget/clang-static/debug test' } - { name: 'Run basic tests gcc Release', run: 'make -C upx/build/xtarget/gcc-static/release test' } - { name: 'Run basic tests gcc Debug', run: 'make -C upx/build/xtarget/gcc-static/debug test' } + - name: 'Run basic tests C++20 and C++23' + if: ${{ contains(matrix.container, ':edge') }} + run: | + for dir in upx/build/xtarget/*-cxx*/*; do + echo "===== $dir" + make -C $dir test + done diff --git a/.github/workflows/weekly-ci-cmake-windows-nmake.yml b/.github/workflows/weekly-ci-cmake-windows-nmake.yml index 36fef233..a7bc45ba 100644 --- a/.github/workflows/weekly-ci-cmake-windows-nmake.yml +++ b/.github/workflows/weekly-ci-cmake-windows-nmake.yml @@ -9,7 +9,7 @@ on: jobs: job-cmake-windows-nmake: - name: ${{ format('{0} {1}', matrix.os, matrix.arch) }} + name: ${{ format('vs{0} {1}', matrix.vsversion, matrix.arch) }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -47,7 +47,7 @@ jobs: - name: 'Make artifact' shell: bash run: | - N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-weekly-ci-nmake-${{ matrix.os }}-${{ matrix.arch }}" | sed 's/[^0-9a-zA-Z_.-]/-/g') + N=$(echo "upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-weekly-ci-nmake-vs${{ matrix.vsversion }}-${{ matrix.arch }}" | sed 's/[^0-9a-zA-Z_.-]/-/g') mkdir -p "tmp/artifact/$N" (cd build && cp -ai --parents */upx.exe "../tmp/artifact/$N") # GitHub Actions magic: set "artifact_name" environment value for use in next step @@ -59,7 +59,10 @@ jobs: path: tmp/artifact - name: 'Run basic tests' if: ${{ matrix.arch != 'amd64_arm64' }} - shell: cmd run: | ctest --test-dir build/debug ctest --test-dir build/release + - name: 'Run install tests' + run: | + env DESTDIR=./Install-debug cmake --install build/debug + env DESTDIR=./Install-release cmake --install build/release diff --git a/src/check/dt_check.cpp b/src/check/dt_check.cpp index a183bd1d..cd3337de 100644 --- a/src/check/dt_check.cpp +++ b/src/check/dt_check.cpp @@ -131,6 +131,7 @@ ACC_COMPILE_TIME_ASSERT_HEADER(usizeof(usizeof(0)) == sizeof(unsigned)) ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("") == 0) ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("a") == 1) ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("ab") == 2) +ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_len("abc") == 3) ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_eq("", "")) ACC_COMPILE_TIME_ASSERT_HEADER(!compile_time::string_eq("a", "")) diff --git a/src/headers.h b/src/headers.h index 90fff592..d9a1fc93 100644 --- a/src/headers.h +++ b/src/headers.h @@ -30,6 +30,29 @@ #error "C++17 is required" #endif +#if defined(__ILP32) || defined(__ILP32__) +static_assert(sizeof(int) == 4); +static_assert(sizeof(long) == 4); +static_assert(sizeof(void *) == 4); +#endif +#if defined(__LP64) || defined(__LP64__) +static_assert(sizeof(int) == 4); +static_assert(sizeof(long) == 8); +static_assert(sizeof(void *) == 8); +#endif +#if defined(_WIN32) +static_assert(sizeof(int) == 4); +static_assert(sizeof(long) == 4); +#if !defined(_WIN64) +static_assert(sizeof(void *) == 4); +#endif +#endif +#if defined(_WIN64) +static_assert(sizeof(int) == 4); +static_assert(sizeof(long) == 4); +static_assert(sizeof(void *) == 8); +#endif + #if !defined(_FILE_OFFSET_BITS) #define _FILE_OFFSET_BITS 64 #endif